Skip to content

Commit 1b45ef8

Browse files
authored
Merge pull request #26 from firstcontributions/improve-comment-styles
2 parents a629469 + 0e717ad commit 1b45ef8

File tree

9 files changed

+298
-52
lines changed

9 files changed

+298
-52
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@editorjs/table": "^2.0.2",
2323
"@firstcontributions/editorjs-codeflask": "https://github.com/firstcontributions/editorjs-codeflask",
2424
"@react-icons/all-files": "^4.1.0",
25+
"dayjs": "^1.11.5",
2526
"form-data": "^4.0.0",
2627
"formidable": "^2.0.1",
2728
"install": "^0.13.0",

src/components/comment/Comment.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import dayjs from 'dayjs'
2+
import relativeTime from 'dayjs/plugin/relativeTime'
3+
import { graphql, useFragment } from 'react-relay'
4+
5+
type CommentProps = {
6+
comment: any
7+
}
8+
9+
const Comment = ({ comment }: CommentProps) => {
10+
const data = useFragment(
11+
graphql`
12+
fragment Comment_node on Comment {
13+
abstractContent
14+
contentJson
15+
createdBy {
16+
avatar
17+
name
18+
handle
19+
}
20+
id
21+
timeCreated
22+
}
23+
`,
24+
comment
25+
)
26+
27+
dayjs.extend(relativeTime)
28+
29+
return (
30+
<div className="flex flex-col p-j ">
31+
<div className="flex flex-row">
32+
<img
33+
className="w-8 h-8 rounded-full"
34+
src={data.createdBy.avatar}
35+
alt={data.createdBy.name}
36+
/>
37+
<div className="ml-2 flex flex-col">
38+
<div className="flex flex-row text-sm">
39+
<span className="mr-4">{data.createdBy.handle}</span>
40+
<span>{`${dayjs(data.timeCreated).toNow(true)} ago`}</span>
41+
</div>
42+
<span className="text-l dark:text-gray-300">{data.contentJson}</span>
43+
</div>
44+
</div>
45+
</div>
46+
)
47+
}
48+
49+
export default Comment

src/components/comment/Comments.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { graphql, usePaginationFragment } from 'react-relay'
2+
import { Comments_story$key } from '../../queries/__generated__/Comments_story.graphql'
23
import NewComment from './NewComment'
4+
import Comment from './Comment'
35

4-
const Comments = ({ story }: any) => {
6+
type CommentsProps = {
7+
story: Comments_story$key
8+
}
9+
10+
const Comments = ({ story }: CommentsProps) => {
511
const { data, loadNext, hasNext, refetch } = usePaginationFragment(
612
graphql`
713
fragment Comments_story on Story
@@ -15,7 +21,7 @@ const Comments = ({ story }: any) => {
1521
edges {
1622
node {
1723
id
18-
contentJson
24+
...Comment_node
1925
}
2026
}
2127
}
@@ -29,10 +35,12 @@ const Comments = ({ story }: any) => {
2935
}
3036

3137
return (
32-
<div className="space-y-4">
33-
{data.comments.edges.map((comment: any) => (
34-
<div key={comment.id}>{comment.node.contentJson}</div>
35-
))}
38+
<div className="space-y-4 mt-4">
39+
<NewComment storyId={story.id} refetch={refetch} />
40+
{data.comments.edges.map(
41+
(comment: any) =>
42+
comment && <Comment comment={comment.node} key={comment.node.id} />
43+
)}
3644
{hasNext ? (
3745
<button
3846
className="text-gray-600 dark:text-gray-300"
@@ -43,7 +51,6 @@ const Comments = ({ story }: any) => {
4351
Load more
4452
</button>
4553
) : null}
46-
<NewComment storyId={story.id} refetch={refetch} />
4754
</div>
4855
)
4956
}

src/pages/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ const Home = ({
4040
sidebarContentLeft={leftSidebar}
4141
sidebarContentRight={<div>Promoted</div>}
4242
>
43-
{query.viewer && (
44-
<>
45-
<Feed root={query} />
46-
</>
47-
)}
43+
<>
44+
<Feed root={query} />
45+
</>
4846
</Layout>
4947
)
5048
}

src/queries/__generated__/Comment_node.graphql.ts

Lines changed: 104 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/queries/__generated__/Comments_story.graphql.ts

Lines changed: 5 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/queries/__generated__/Comments_storyQuery.graphql.ts

Lines changed: 51 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)