-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: UseCommentReducer 개선 및 Comment UI 추가(#80)
- Loading branch information
1 parent
2679d2e
commit 5e80153
Showing
8 changed files
with
2,445 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ListItem, ListItemText, Typography } from '@mui/material'; | ||
import { Comment } from '../../../types/comment'; | ||
|
||
type Props = { | ||
data: Comment; | ||
}; | ||
|
||
const CommentChild = ({ data }: Props) => { | ||
return ( | ||
<ListItem> | ||
<ListItemText | ||
// primary="Brunch this weekend?" | ||
secondary={ | ||
<> | ||
<Typography | ||
sx={{ display: 'inline' }} | ||
component="span" | ||
variant="body2" | ||
color="text.primary" | ||
> | ||
{data.writer} - | ||
</Typography> | ||
{data.content} | ||
</> | ||
} | ||
/> | ||
</ListItem> | ||
); | ||
}; | ||
|
||
export default CommentChild; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { ExpandLess, ExpandMore } from '@mui/icons-material'; | ||
import { | ||
Avatar, | ||
Button, | ||
Collapse, | ||
List, | ||
ListItem, | ||
ListItemAvatar, | ||
ListItemText, | ||
Stack, | ||
Typography, | ||
} from '@mui/material'; | ||
import React from 'react'; | ||
import { UIComment } from '../../../types/comment'; | ||
import CommentChild from '../CommentChild'; | ||
|
||
type Props = { | ||
data: UIComment; | ||
expand: (id: number) => void; | ||
unexpand: (id: number) => void; | ||
}; | ||
|
||
const CommentItem = ({ data, expand, unexpand }: Props) => { | ||
const handleExpand = () => expand(data.id); | ||
const handleUnExpand = () => unexpand(data.id); | ||
|
||
return ( | ||
<> | ||
<ListItem> | ||
<ListItemAvatar> | ||
<Avatar alt="Remy Sharp" src={data.pictureUrl} /> | ||
</ListItemAvatar> | ||
<Stack direction="column"> | ||
<ListItemText | ||
primary={data.writer} | ||
secondary={ | ||
<> | ||
{/* <Typography | ||
sx={{ display: 'inline' }} | ||
component="span" | ||
variant="body2" | ||
color="text.primary" | ||
> | ||
Ali Connors | ||
</Typography> */} | ||
{data.content} | ||
</> | ||
} | ||
/> | ||
{data.hasChild ? ( | ||
data.isExpand ? ( | ||
<Button onClick={handleUnExpand}>감추기...</Button> | ||
) : ( | ||
//<ExpandMore /> | ||
// <ExpandLess /> | ||
<Button onClick={handleExpand}>더보기...</Button> | ||
) | ||
) : undefined} | ||
</Stack> | ||
</ListItem> | ||
<Collapse in={data.isExpand} timeout="auto" unmountOnExit> | ||
<List component="div" disablePadding> | ||
{data.children?.map((child) => ( | ||
<CommentChild key={child.id} data={child} /> | ||
))} | ||
</List> | ||
</Collapse> | ||
</> | ||
); | ||
}; | ||
|
||
export default React.memo(CommentItem); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Comment from '../../components/Comment'; | ||
|
||
const CommentPage = () => { | ||
return ( | ||
<div> | ||
<Comment articleId={0} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CommentPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
export interface Comment { | ||
id: number; | ||
pictureUrl: string; | ||
writer: string; | ||
content: string; | ||
postAt: string | Date; | ||
hasChild: boolean; | ||
parentId: number; // -1 = no parent | ||
} | ||
|
||
export interface UIComment extends Comment { | ||
isExpand: boolean; | ||
alreadyFetch: boolean; | ||
children: Comment[] | undefined; | ||
} |
Oops, something went wrong.