From b468c033ca1531de2a398a3edd603da33fba0522 Mon Sep 17 00:00:00 2001 From: keyan Date: Tue, 6 Sep 2022 09:48:37 -0500 Subject: [PATCH] better handling of comment sort loading state --- components/comments.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/components/comments.js b/components/comments.js index 9f5b6860..db5dfe2b 100644 --- a/components/comments.js +++ b/components/comments.js @@ -69,7 +69,8 @@ export default function Comments ({ parentId, commentSats, comments, ...props }) } catch {} } }, []) - const [getComments, { loading }] = useLazyQuery(COMMENTS_QUERY, { + const [loading, setLoading] = useState() + const [getComments] = useLazyQuery(COMMENTS_QUERY, { fetchPolicy: 'network-only', onCompleted: data => { client.writeFragment({ @@ -87,12 +88,20 @@ export default function Comments ({ parentId, commentSats, comments, ...props }) comments: data.comments } }) + setLoading(false) } }) return ( <> - {comments.length ? getComments({ variables: { id: parentId, sort } })} /> : null} + {comments.length + ? { + setLoading(true) + getComments({ variables: { id: parentId, sort } }) + }} + /> + : null} {loading ? : comments.map(item => (