better handling of comment sort loading state

This commit is contained in:
keyan 2022-09-06 09:48:37 -05:00
parent 52de4a253e
commit b468c033ca
1 changed files with 11 additions and 2 deletions

View File

@ -69,7 +69,8 @@ export default function Comments ({ parentId, commentSats, comments, ...props })
} catch {} } catch {}
} }
}, []) }, [])
const [getComments, { loading }] = useLazyQuery(COMMENTS_QUERY, { const [loading, setLoading] = useState()
const [getComments] = useLazyQuery(COMMENTS_QUERY, {
fetchPolicy: 'network-only', fetchPolicy: 'network-only',
onCompleted: data => { onCompleted: data => {
client.writeFragment({ client.writeFragment({
@ -87,12 +88,20 @@ export default function Comments ({ parentId, commentSats, comments, ...props })
comments: data.comments comments: data.comments
} }
}) })
setLoading(false)
} }
}) })
return ( return (
<> <>
{comments.length ? <CommentsHeader commentSats={commentSats} handleSort={sort => getComments({ variables: { id: parentId, sort } })} /> : null} {comments.length
? <CommentsHeader
commentSats={commentSats} handleSort={sort => {
setLoading(true)
getComments({ variables: { id: parentId, sort } })
}}
/>
: null}
{loading {loading
? <CommentsSkeleton /> ? <CommentsSkeleton />
: comments.map(item => ( : comments.map(item => (