diff --git a/packages/web/src/components/comments/CommentSectionContext.tsx b/packages/web/src/components/comments/CommentSectionContext.tsx index 9edbe9fe3a3..5cfbd69fbb2 100644 --- a/packages/web/src/components/comments/CommentSectionContext.tsx +++ b/packages/web/src/components/comments/CommentSectionContext.tsx @@ -36,6 +36,8 @@ type CommentSectionContextType = CommentSectionContextProps & { handleEditComment: (commentId: ID, newMessage: string) => void handleDeleteComment: (commentId: ID) => void handleReportComment: (commentId: ID) => void + handleLoadMoreRootComments: () => void + handleLoadMoreReplies: (commentId: ID) => void fetchComments: () => void } @@ -52,6 +54,8 @@ const initialContextValues: CommentSectionContextType = { handleEditComment: emptyFn, handleDeleteComment: emptyFn, handleReportComment: emptyFn, + handleLoadMoreRootComments: emptyFn, + handleLoadMoreReplies: emptyFn, fetchComments: emptyFn } @@ -136,6 +140,12 @@ export const CommentSectionProvider = ({ const handleReportComment = (commentId: ID) => { console.log('Clicked report for ', commentId) } + const handleLoadMoreRootComments = () => { + console.log('Loading more root comments') + } + const handleLoadMoreReplies = (commentId: ID) => { + console.log('Loading more replies for', commentId) + } // TODO: move this to audius-query // load comments logic @@ -178,7 +188,9 @@ export const CommentSectionProvider = ({ handleEditComment, handleDeleteComment, handleReportComment, - fetchComments + handleLoadMoreReplies, + handleLoadMoreRootComments, + fetchComments // todo: temporary - remove later }} > {children} diff --git a/packages/web/src/components/comments/CommentSectionDesktop.tsx b/packages/web/src/components/comments/CommentSectionDesktop.tsx index 57b6929cd8e..05384c19aec 100644 --- a/packages/web/src/components/comments/CommentSectionDesktop.tsx +++ b/packages/web/src/components/comments/CommentSectionDesktop.tsx @@ -1,4 +1,4 @@ -import { Divider, Flex, Paper, Skeleton } from '@audius/harmony' +import { Button, Divider, Flex, Paper, Skeleton } from '@audius/harmony' import { CommentForm } from './CommentForm' import { CommentHeader } from './CommentHeader' @@ -6,8 +6,13 @@ import { useCurrentCommentSection } from './CommentSectionContext' import { CommentThread } from './CommentThread' export const CommentSectionDesktop = () => { - const { userId, isLoading, comments, handlePostComment } = - useCurrentCommentSection() + const { + userId, + isLoading, + comments, + handlePostComment, + handleLoadMoreRootComments + } = useCurrentCommentSection() const commentPostAllowed = userId !== null // Loading state @@ -50,6 +55,16 @@ export const CommentSectionDesktop = () => { ) : null} + {/* TODO: this button is temporary; will be replaced with endless scroll */} + diff --git a/packages/web/src/components/comments/CommentThread.tsx b/packages/web/src/components/comments/CommentThread.tsx index 0d7ba488a32..5b31f2d7014 100644 --- a/packages/web/src/components/comments/CommentThread.tsx +++ b/packages/web/src/components/comments/CommentThread.tsx @@ -15,11 +15,13 @@ import { useCurrentCommentSection } from './CommentSectionContext' const messages = { noCommentsTitle: 'Nothing here yet', - noCommentsSubtitle: 'Be the first to comment on this track' // TODO: make this derive from entity type + noCommentsSubtitle: 'Be the first to comment on this track', // TODO: make this derive from entity type + showMoreReplies: 'Show More Replies' } export const CommentThread = () => { - const { comments, fetchComments } = useCurrentCommentSection() + const { comments, fetchComments, handleLoadMoreReplies } = + useCurrentCommentSection() // TODO: this feels sub-optimal? Maybe fine const [hiddenReplies, setHiddenReplies] = useState<{ [parentCommentId: number]: boolean @@ -61,20 +63,25 @@ export const CommentThread = () => { {hiddenReplies[rootComment.id] ? 'Show' : 'Hide'} Replies ) : null} + {hiddenReplies[rootComment.id] || + (rootComment?.replies?.length ?? 0) === 0 ? null : ( + + {rootComment?.replies?.map((reply) => ( + + + + ))} + + )} + {/* TODO: need a way to hide this when no more to load */} + handleLoadMoreReplies(rootComment.id)}> + {messages.showMoreReplies} + - {hiddenReplies[rootComment.id] ? null : ( - - {rootComment?.replies?.map((reply) => ( - - - - ))} - - )} ))}