diff options
author | Ivan Chen <ivan@tagg.id> | 2021-05-10 20:23:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-10 20:23:39 -0400 |
commit | 4569240e09ff134d49fa11180c0074329a3ac95b (patch) | |
tree | ea716453b6d9b360ba9fb9f8285f2c14414d7baa | |
parent | 6c9d06f8ec0f7fe023d882484c59317e8230de09 (diff) | |
parent | 8e295367d7c992894ca2ac5c2175926e0ed3ab40 (diff) |
Merge pull request #412 from brian-tagg/fixCommentCount
[TMA-840] Fixed comment counting situation for moments
-rw-r--r-- | src/components/comments/CommentsContainer.tsx | 11 | ||||
-rw-r--r-- | src/screens/profile/MomentCommentsScreen.tsx | 5 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/components/comments/CommentsContainer.tsx b/src/components/comments/CommentsContainer.tsx index cd9ecb02..0bfd5ad6 100644 --- a/src/components/comments/CommentsContainer.tsx +++ b/src/components/comments/CommentsContainer.tsx @@ -18,6 +18,7 @@ export type CommentsContainerProps = { shouldUpdate: boolean; setShouldUpdate: (update: boolean) => void; isThread: boolean; + setCommentsLengthParent: (length: number) => void; }; /** @@ -31,6 +32,7 @@ const CommentsContainer: React.FC<CommentsContainerProps> = ({ shouldUpdate, setShouldUpdate, commentId, + setCommentsLengthParent, }) => { const {setCommentsLength, commentTapped} = useContext(CommentContext); const {username: loggedInUsername} = useSelector( @@ -41,6 +43,14 @@ const CommentsContainer: React.FC<CommentsContainerProps> = ({ const ref = useRef<FlatList<CommentType>>(null); const ITEM_HEIGHT = SCREEN_HEIGHT / 7.0; + const countComments = (comments: CommentType[]) => { + let count = 0; + for (let i = 0; i < comments.length; i++) { + count += 1 + comments[i].replies_count; + } + return count; + } + useEffect(() => { const loadComments = async () => { await getComments(objectId, isThread).then((comments) => { @@ -51,6 +61,7 @@ const CommentsContainer: React.FC<CommentsContainerProps> = ({ } setShouldUpdate(false); } + setCommentsLengthParent(countComments(comments)); }); }; let subscribedToLoadComments = true; diff --git a/src/screens/profile/MomentCommentsScreen.tsx b/src/screens/profile/MomentCommentsScreen.tsx index 1a913e58..bf07ae30 100644 --- a/src/screens/profile/MomentCommentsScreen.tsx +++ b/src/screens/profile/MomentCommentsScreen.tsx @@ -32,8 +32,6 @@ type MomentCommentContextType = { ) => void; shouldUpdateAllComments: boolean; setShouldUpdateAllComments: (available: boolean) => void; - commentsLength: number; - setCommentsLength: (length: number) => void; }; export const CommentContext = React.createContext( @@ -68,8 +66,6 @@ const MomentCommentsScreen: React.FC<MomentCommentsScreenProps> = ({route}) => { setCommentTapped, shouldUpdateAllComments, setShouldUpdateAllComments, - commentsLength, - setCommentsLength, }}> <View style={styles.background}> <SafeAreaView> @@ -81,6 +77,7 @@ const MomentCommentsScreen: React.FC<MomentCommentsScreenProps> = ({route}) => { shouldUpdate={shouldUpdateAllComments} setShouldUpdate={setShouldUpdateAllComments} isThread={false} + setCommentsLengthParent={setCommentsLength} /> <AddComment placeholderText={ |