Skip to content

Commit

Permalink
Update StoryCommentsSection.tsx to reflect Relay tutorial
Browse files Browse the repository at this point in the history
Following the steps in the [Connections & Pagination](https://relay.dev/docs/next/tutorial/connections-pagination/#implementing-load-more-comments) part of the Relay Tutorial is clearly states that: 

> At this point, you should see up to three comments on each story. Some stories have more than three comments, and these will show a "Load more" button, although it isn't hooked up yet.

But the example only loads 1 comments, and there is no "Load more" button present. The tutorial assumes that this code is already present and that is confusing to the reader.

In this PR I've updated `StoryCommentsSection.tsx` to reflect the code examples & instructions in the tutorial.

Thanks!
  • Loading branch information
danielstocks authored Nov 7, 2024
1 parent b6f9b19 commit bafcd35
Showing 1 changed file with 14 additions and 12 deletions.
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} />
)}
</>
);
}

0 comments on commit bafcd35

Please sign in to comment.