Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Update StoryCommentsSection.tsx to accurately reflect Relay tutorial #327

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions newsfeed/src/components/StoryCommentsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,38 @@ import { graphql } from "relay-runtime";
import { useFragment } from "react-relay";
import type { StoryCommentsSectionFragment$key } from "./__generated__/StoryCommentsSectionFragment.graphql";
import Comment from "./Comment";

const { useState, useTransition } = React;
import LoadMoreCommentsButton from "./LoadMoreCommentsButton";

export type Props = {
story: StoryCommentsSectionFragment$key;
};

const StoryCommentsSectionFragment = graphql`
fragment StoryCommentsSectionFragment on Story {
comments(first: 1) {
pageInfo {
startCursor
}
comments(first: 3) {
edges {
node {
id
...CommentFragment
}
}
pageInfo {
hasNextPage
}
}
}
`;

export default function StoryCommentsSection({ story }: Props) {
const data = useFragment(StoryCommentsSectionFragment, story);
const onLoadMore = () => {/* TODO */};
return (
<div>
{data.comments.edges.map((edge) => (
<Comment key={edge.node.id} comment={edge.node} />
))}
</div>
<>
{data.comments.edges.map(commentEdge =>
<Comment comment={commentEdge.node} />
)}
{data.comments.pageInfo.hasNextPage && (
<LoadMoreCommentsButton onClick={onLoadMore} />
)}
</>
);
}