better handling of comment sort loading state
This commit is contained in:
parent
52de4a253e
commit
b468c033ca
|
@ -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 => (
|
||||||
|
|
Loading…
Reference in New Issue