Skip to content

Commit 90a4fe6

Browse files
committed
feat(): ADding the comment box rendering feature
1 parent 47f23e9 commit 90a4fe6

2 files changed

Lines changed: 56 additions & 12 deletions

File tree

src/screens/articles/components/CommentBox.tsx

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@ import {
66
HStack,
77
Button,
88
VStack,
9+
Text,
910
} from '@chakra-ui/react';
11+
import { useState } from 'react';
1012

1113
const CommentBox = ({
1214
comments,
1315
}: {
1416
comments: { comment: string; user: string; email: string }[];
1517
}) => {
18+
const [state, setState] = useState<{
19+
email: string;
20+
name: string;
21+
comment: string;
22+
}>({ email: '', name: '', comment: '' });
23+
24+
const isDisabled =
25+
state.email === '' || state.name === '' || state.comment === '';
26+
1627
return (
1728
<Box
1829
w={'100%'}
@@ -25,19 +36,52 @@ const CommentBox = ({
2536
>
2637
<Heading size={'md'}>Comments</Heading>
2738
<Divider />
28-
{comments?.map((comment, index) => (
29-
<Box key={index} p={2}>
30-
<Heading size={'sm'}>{comment.user}</Heading>
31-
<Box>{comment.comment}</Box>
32-
</Box>
33-
))}
34-
<VStack p={4} borderRadius={'md'} mt={4} rowGap={5}>
39+
{comments ? (
40+
comments?.map((comment, index) => (
41+
<Box
42+
key={index}
43+
p={2}
44+
px={4}
45+
borderRadius={'md'}
46+
mt={4}
47+
bg={'gray.800'}
48+
>
49+
<Heading size={'md'}>
50+
🤖{comment.user} 📫{comment.email}
51+
</Heading>
52+
<Box paddingStart={2}>{comment.comment}</Box>
53+
</Box>
54+
))
55+
) : (
56+
<Text alignSelf={'start'} color={'gray.500'} p={4}>
57+
No Comments
58+
</Text>
59+
)}
60+
<VStack p={4} borderRadius={'md'} mt={4} rowGap={3}>
61+
<Divider />
62+
<Text alignSelf={'start'}>Add a Comment</Text>
3563
<HStack columnGap={4} w={'100%'}>
36-
<Input type="text" placeholder="Enter email" />
37-
<Input type="text" placeholder="Enter Name" />
64+
<Input
65+
type="text"
66+
placeholder="Enter email"
67+
value={state.email}
68+
onChange={(e) => setState({ ...state, email: e.target.value })}
69+
/>
70+
<Input
71+
type="text"
72+
placeholder="Enter Name"
73+
value={state.name}
74+
onChange={(e) => setState({ ...state, name: e.target.value })}
75+
/>
3876
</HStack>
39-
<Input placeholder="Add a comment" />
40-
<Button alignSelf={'start'}>Submit</Button>
77+
<Input
78+
placeholder="Add a comment"
79+
value={state.comment}
80+
onChange={(e) => setState({ ...state, comment: e.target.value })}
81+
/>
82+
<Button alignSelf={'start'} isDisabled={isDisabled}>
83+
Submit
84+
</Button>
4185
</VStack>
4286
</Box>
4387
);

src/screens/articles/components/MarkdownViewer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const MarkdownViewer = ({ articleKey }: { articleKey: string }) => {
3232
>
3333
<Box width={'80%'} id="md-preview-flex-box">
3434
<MdPreview mdString={mdString ?? ''} />
35-
<CommentBox comments={comments} />
35+
<CommentBox comments={JSON.parse(comments).comments} />
3636
</Box>
3737
<SideViewer mdString={mdString ?? ''} />
3838
</HStack>

0 commit comments

Comments
 (0)