Skip to content

Commit bbdb86d

Browse files
committed
CommentList updated for "Has Data" use case
1 parent 74de8cc commit bbdb86d

File tree

3 files changed

+379
-48
lines changed

3 files changed

+379
-48
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
},
1414
"dependencies": {
1515
"react": "^18.3.1",
16-
"react-dom": "^18.3.1"
16+
"react-dom": "^18.3.1",
17+
"styled-components": "^6.1.13"
1718
},
1819
"devDependencies": {
1920
"@eslint/js": "^9.9.0",

src/components/CommentList.tsx

Lines changed: 117 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,121 @@
1+
import styled, { createGlobalStyle } from 'styled-components';
12

23
interface Author {
3-
name: string;
4-
avatar: string;
5-
}
6-
7-
interface Comment {
8-
text: string;
9-
author: Author;
10-
}
11-
12-
export interface CommentListProps {
13-
/**
14-
* Is the component in the loading state
15-
*/
16-
loading?: boolean;
17-
18-
/**
19-
* Total number of comments
20-
*/
21-
totalCount?: number;
22-
23-
/**
24-
* List of comments
25-
*/
26-
comments?: Comment[];
27-
}
28-
4+
name: string;
5+
avatar: string;
6+
}
7+
8+
interface Comment {
9+
text: string;
10+
author: Author;
11+
}
12+
13+
export interface CommentListProps {
2914
/**
30-
* The Commentlist component should display the comments from the users.
31-
*/
32-
export default function CommentList({
33-
loading = false,
34-
comments = [],
35-
totalCount = 10,
36-
}: CommentListProps) {
37-
if (loading) {
38-
return <div>loading</div>;
39-
}
40-
if (comments.length === 0) {
41-
return <div>empty</div>;
42-
}
43-
return (
44-
<div>
45-
{comments.length} of {totalCount}
46-
</div>
47-
);
15+
* Is the component in the loading state
16+
*/
17+
loading?: boolean;
18+
19+
/**
20+
* Total number of comments
21+
*/
22+
totalCount?: number;
23+
24+
/**
25+
* List of comments
26+
*/
27+
comments?: Comment[];
28+
}
29+
30+
const CommentListWrapper = styled.div`
31+
font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
32+
color: #333;
33+
display: inline-block;
34+
vertical-align: top;
35+
width: 265px;
36+
`;
37+
38+
const CommentItem = styled.div`
39+
font-size: 12px;
40+
line-height: 14px;
41+
clear: both;
42+
height: 48px;
43+
margin-bottom: 10px;
44+
box-shadow: rgba(0, 0, 0, 0.2) 0 0 10px 0;
45+
background: linear-gradient(
46+
120deg,
47+
rgba(248, 248, 254, 0.95),
48+
rgba(250, 250, 250, 0.95)
49+
);
50+
border-radius: 48px;
51+
`;
52+
53+
const Avatar = styled.div`
54+
float: left;
55+
position: relative;
56+
overflow: hidden;
57+
height: 48px;
58+
width: 48px;
59+
margin-right: 14px;
60+
background: #dfecf2;
61+
border-radius: 48px;
62+
`;
63+
64+
const AvatarImg = styled.img`
65+
position: absolute;
66+
height: 100%;
67+
width: 100%;
68+
left: 0;
69+
top: 0;
70+
z-index: 1;
71+
background: #999;
72+
`;
73+
74+
const Message = styled.div`
75+
overflow: hidden;
76+
padding-top: 10px;
77+
padding-right: 20px;
78+
`;
79+
80+
const Author = styled.span`
81+
font-weight: bold;
82+
`;
83+
84+
const CommentText = styled.span``;
85+
86+
const GlobalStyle = createGlobalStyle`
87+
@import url('https://fonts.googleapis.com/css?family=Nunito+Sans:400,400i,800');
88+
`;
89+
90+
/**
91+
* The Commentlist component should display the comments from the user.
92+
*/
93+
export default function CommentList({
94+
loading = false,
95+
comments = [],
96+
totalCount = 10,
97+
}: CommentListProps) {
98+
if (loading) {
99+
return <div>loading</div>;
100+
}
101+
if (comments.length === 0) {
102+
return <div>empty</div>;
48103
}
49-
104+
return (
105+
<>
106+
<GlobalStyle />
107+
<CommentListWrapper>
108+
{comments.map(({ text, author: { name, avatar } }) => (
109+
<CommentItem key={`comment_${name}`}>
110+
<Avatar>
111+
<AvatarImg src={avatar} />
112+
</Avatar>
113+
<Message>
114+
<Author>{name}</Author> <CommentText>{text}</CommentText>
115+
</Message>
116+
</CommentItem>
117+
))}
118+
</CommentListWrapper>
119+
</>
120+
);
121+
}

0 commit comments

Comments
 (0)