({
feedQueryKey,
query,
logOrigin,
variables,
emptyScreen,
commentClassName,
isMainFeed,
}: CommentFeedProps<T>)
| 28 | } |
| 29 | |
| 30 | export default function CommentFeed<T>({ |
| 31 | feedQueryKey, |
| 32 | query, |
| 33 | logOrigin, |
| 34 | variables, |
| 35 | emptyScreen, |
| 36 | commentClassName, |
| 37 | isMainFeed, |
| 38 | }: CommentFeedProps<T>): ReactElement { |
| 39 | const { openShareComment } = useShareComment(logOrigin); |
| 40 | const { onShowUpvoted } = useUpvoteQuery(); |
| 41 | const { deleteComment } = useDeleteComment(); |
| 42 | const isLaptop = useViewSize(ViewSize.Laptop); |
| 43 | |
| 44 | const queryResult = useInfiniteQuery<CommentFeedData>({ |
| 45 | queryKey: feedQueryKey, |
| 46 | queryFn: ({ pageParam }) => |
| 47 | gqlClient.request(query, { |
| 48 | ...variables, |
| 49 | first: 20, |
| 50 | after: pageParam, |
| 51 | }), |
| 52 | initialPageParam: '', |
| 53 | getNextPageParam: ({ page }) => getNextPageParam(page?.pageInfo), |
| 54 | }); |
| 55 | const length = queryResult?.data?.pages?.length; |
| 56 | const showEmptyScreen = |
| 57 | length > 0 && queryResult.data.pages[0].page.edges.length === 0; |
| 58 | |
| 59 | if (queryResult.isPending) { |
| 60 | return ( |
| 61 | <PlaceholderCommentList |
| 62 | placeholderAmount={5} |
| 63 | className={classNames( |
| 64 | '!mt-0 border-border-subtlest-tertiary p-4', |
| 65 | commentClassName?.container, |
| 66 | )} |
| 67 | showContextHeader |
| 68 | /> |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | if (showEmptyScreen && emptyScreen) { |
| 73 | return <>{emptyScreen}</>; |
| 74 | } |
| 75 | |
| 76 | return ( |
| 77 | <> |
| 78 | <InfiniteScrolling |
| 79 | isFetchingNextPage={queryResult.isFetchingNextPage} |
| 80 | canFetchMore={checkFetchMore(queryResult)} |
| 81 | fetchNextPage={queryResult.fetchNextPage} |
| 82 | className="w-full" |
| 83 | > |
| 84 | {queryResult.data.pages.flatMap((page) => |
| 85 | page.page.edges.map(({ node }, index) => ( |
| 86 | <MainComment |
| 87 | key={node.id} |
nothing calls this directly
no test coverage detected