Fix clear new comments on route change (#2319)

This commit is contained in:
soxa 2025-07-24 06:47:53 +02:00 committed by GitHub
parent 7c10ded8a6
commit ecac519efb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -309,6 +309,7 @@ export function ViewAllReplies ({ id, nshown, nhas }) {
function ReplyOnAnotherPage ({ item }) { function ReplyOnAnotherPage ({ item }) {
const root = useRoot() const root = useRoot()
const rootId = commentSubTreeRootId(item, root) const rootId = commentSubTreeRootId(item, root)
const { cache } = useApolloClient()
let text = 'reply on another page' let text = 'reply on another page'
if (item.ncomments > 0) { if (item.ncomments > 0) {
@ -316,7 +317,24 @@ function ReplyOnAnotherPage ({ item }) {
} }
return ( return (
<Link href={`/items/${rootId}?commentId=${item.id}`} as={`/items/${rootId}`} className='pb-2 fw-bold d-flex align-items-center gap-2 text-muted'> <Link
onClick={() => {
// clear new comments going to another page
cache.writeFragment({
id: `Item:${item.id}`,
fragment: gql`
fragment NewComments on Item {
newComments
}`,
data: {
newComments: []
}
})
}}
href={`/items/${rootId}?commentId=${item.id}`}
as={`/items/${rootId}`}
className='pb-2 fw-bold d-flex align-items-center gap-2 text-muted'
>
{text} {text}
{item.newComments?.length > 0 && <div className={styles.newCommentDot} />} {item.newComments?.length > 0 && <div className={styles.newCommentDot} />}
</Link> </Link>