- )
-}
+ useEffect(() => {
+ if (router.query.commentsViewedAt) {
+ const lastViewedNumComments = parseInt(window.localStorage.getItem(`commentsViewNumThread:${item.id}`), 10)
+ // get the updated number of comments in the thread from cache
+ const comment = cache.readFragment({
+ id: `Item:${item.id}`,
+ fragment: gql`
+ fragment NComments on Item {
+ ncomments
+ }`
+ })
+ // if the last viewed number of comments in the thread
+ // is less than the updated number of comments in it, highlight it
+ if (lastViewedNumComments && lastViewedNumComments < comment?.ncomments) {
+ ref.current.classList.add('outline-new-comment')
+ }
+ }
+ }, [item.id])
-function ReplyOnAnotherPage ({ item }) {
- const root = useRoot()
- const rootId = commentSubTreeRootId(item, root)
+ // distinguish between reply on another page and view all replies
+ const className = onAnotherPage
+ ? classNames(styles.comment, 'mt-3')
+ : `d-block fw-bold ${styles.comment} pb-2 ps-3`
- let text = 'reply on another page'
- if (item.ncomments > 0) {
- text = `view all ${item.ncomments} replies`
- }
+ // if item has replies, show view all n replies, otherwise show reply on another page
+ const text = item.ncomments > 0
+ ? `view all ${item.ncomments} replies`
+ : 'reply on another page'
return (
-
- {text}
-
+