fix notification padding and evict notification item from cache on visit

This commit is contained in:
keyan 2021-08-18 14:15:52 -05:00
parent 6dff4c6815
commit 534e772849
1 changed files with 6 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import { useQuery } from '@apollo/client' import { useApolloClient, useQuery } from '@apollo/client'
import Button from 'react-bootstrap/Button' import Button from 'react-bootstrap/Button'
import { useState } from 'react' import { useState } from 'react'
import Comment, { CommentSkeleton } from './comment' import Comment, { CommentSkeleton } from './comment'
@ -9,6 +9,7 @@ import { useRouter } from 'next/router'
export default function Notifications ({ variables, ...props }) { export default function Notifications ({ variables, ...props }) {
const router = useRouter() const router = useRouter()
const client = useApolloClient()
const { loading, error, data, fetchMore } = useQuery(NOTIFICATIONS, { const { loading, error, data, fetchMore } = useQuery(NOTIFICATIONS, {
variables variables
}) })
@ -27,11 +28,15 @@ export default function Notifications ({ variables, ...props }) {
className={styles.clickToContext} className={styles.clickToContext}
onClick={() => { onClick={() => {
if (n.__typename === 'Reply' || !n.item.title) { if (n.__typename === 'Reply' || !n.item.title) {
// evict item from cache so that it has current state
// e.g. if they previously visited before a recent comment
client.cache.evict({ id: `Item:${n.item.parentId}` })
router.push({ router.push({
pathname: '/items/[id]', pathname: '/items/[id]',
query: { id: n.item.parentId, commentId: n.item.id } query: { id: n.item.parentId, commentId: n.item.id }
}, `/items/${n.item.parentId}`) }, `/items/${n.item.parentId}`)
} else { } else {
client.cache.evict({ id: `Item:${n.item.id}` })
router.push(`items/${n.item.id}`) router.push(`items/${n.item.id}`)
} }
}} }}