Skip to content

Commit 47f23e9

Browse files
committed
feat(): Adding comments feature
1 parent 2e901f9 commit 47f23e9

14 files changed

Lines changed: 105 additions & 7 deletions

File tree

src/screens/articles/ArticlesScreen.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
55
import { MarkdownViewer } from './components';
66
import { useMemo, useState } from 'react';
77
import { groupBy } from 'lodash';
8+
import { BASE_NAV_ROUTE } from '@router';
89

910
const ArticlesScreen = () => {
1011
const { data } = useGetArticlesData();
@@ -76,7 +77,7 @@ const ArticlesScreen = () => {
7677
_hover={{ bg: 'gray.600', cursor: 'pointer', color: 'violet' }}
7778
onClick={() => {
7879
if (secondPath) {
79-
navigate(-1);
80+
navigate(BASE_NAV_ROUTE + 'articles');
8081
}
8182
setCategory(group_name);
8283
}}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {
2+
Box,
3+
Heading,
4+
Divider,
5+
Input,
6+
HStack,
7+
Button,
8+
VStack,
9+
} from '@chakra-ui/react';
10+
11+
const CommentBox = ({
12+
comments,
13+
}: {
14+
comments: { comment: string; user: string; email: string }[];
15+
}) => {
16+
return (
17+
<Box
18+
w={'100%'}
19+
h={'100%'}
20+
bg={'gray.900'}
21+
borderRadius={'md'}
22+
p={4}
23+
color={'white'}
24+
id="comments"
25+
>
26+
<Heading size={'md'}>Comments</Heading>
27+
<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}>
35+
<HStack columnGap={4} w={'100%'}>
36+
<Input type="text" placeholder="Enter email" />
37+
<Input type="text" placeholder="Enter Name" />
38+
</HStack>
39+
<Input placeholder="Add a comment" />
40+
<Button alignSelf={'start'}>Submit</Button>
41+
</VStack>
42+
</Box>
43+
);
44+
};
45+
46+
export default CommentBox;

src/screens/articles/components/MarkdownViewer.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { Box, HStack } from '@chakra-ui/react';
22
import { LoadingSpinner, MdPreview } from '@components';
33
import { useGetArticleData } from '@services';
44
import { useMemo } from 'react';
5-
import SideViewer from './Header';
5+
import SideViewer from './SideViewer';
6+
import CommentBox from './CommentBox';
67

78
const MarkdownViewer = ({ articleKey }: { articleKey: string }) => {
89
const { data } = useGetArticleData(articleKey);
@@ -12,6 +13,11 @@ const MarkdownViewer = ({ articleKey }: { articleKey: string }) => {
1213
[data],
1314
);
1415

16+
const comments = useMemo(
17+
() => (data as any)?.data?.rows?.[0].comments,
18+
[data],
19+
);
20+
1521
if (!data) {
1622
return <LoadingSpinner />;
1723
}
@@ -26,6 +32,7 @@ const MarkdownViewer = ({ articleKey }: { articleKey: string }) => {
2632
>
2733
<Box width={'80%'} id="md-preview-flex-box">
2834
<MdPreview mdString={mdString ?? ''} />
35+
<CommentBox comments={comments} />
2936
</Box>
3037
<SideViewer mdString={mdString ?? ''} />
3138
</HStack>

src/screens/articles/components/Header.tsx renamed to src/screens/articles/components/SideViewer.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { Box, Text } from '@chakra-ui/react';
1+
import { Box, Button, Text } from '@chakra-ui/react';
22
import { useMemo } from 'react';
33
import { HEADING_TYPE_REGEX } from './constants';
4+
import { useLikeArticleData } from '@services';
45

56
const SideViewer = ({ mdString }: { mdString: string }) => {
7+
const { mutate } = useLikeArticleData();
68
// Extract headings from the markdown string and remove dots.
79
const headings = useMemo(
810
() =>
@@ -37,7 +39,27 @@ const SideViewer = ({ mdString }: { mdString: string }) => {
3739
width={'20%'}
3840
overflowY={'scroll'}
3941
scrollSnapType={'y mandatory'}
42+
display={'flex'}
43+
px={2}
44+
rowGap={1}
45+
flexDir={'column'}
4046
>
47+
<Button size={'sm'} onClick={mutate}>
48+
Like 👍
49+
</Button>
50+
<Button
51+
size={'sm'}
52+
as={'a'}
53+
href={'#comments'}
54+
onClick={() =>
55+
document.getElementById('comments')?.scrollIntoView({
56+
behavior: 'smooth',
57+
block: 'center',
58+
})
59+
}
60+
>
61+
Comments 💬
62+
</Button>
4163
{headings.map(({ marginStart, itemName, link }, index) => (
4264
<>
4365
<Text
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { default as getArticlesData } from './getAllArticlesData';
22
export { default as getArticleData } from './getArticleData';
3+
export { default as likePageArticleData } from './likePageArticleData';
File renamed without changes.

0 commit comments

Comments
 (0)