1
- import { Fragment , useMemo } from 'react'
1
+ import { Fragment , useMemo , useState } from 'react'
2
2
import Comment , { CommentSkeleton } from './comment'
3
3
import styles from './header.module.css'
4
4
import Nav from 'react-bootstrap/Nav'
@@ -10,6 +10,8 @@ import MoreFooter from './more-footer'
10
10
import { FULL_COMMENTS_THRESHOLD } from '@/lib/constants'
11
11
import useLiveComments from './use-live-comments'
12
12
import { ShowNewComments } from './show-new-comments'
13
+ import Head from 'next/head'
14
+ import { useHasNewNotes } from './use-has-new-notes'
13
15
14
16
export function CommentsHeader ( { handleSort, pinned, bio, parentCreatedAt, commentSats } ) {
15
17
const router = useRouter ( )
@@ -68,14 +70,20 @@ export default function Comments ({
68
70
parentId, pinned, bio, parentCreatedAt,
69
71
commentSats, comments, commentsCursor, fetchMoreComments, ncomments, newComments, lastCommentAt, ...props
70
72
} ) {
73
+ const [ hasNewComments , setHasNewComments ] = useState ( false )
71
74
const router = useRouter ( )
72
75
// fetch new comments that arrived after the lastCommentAt, and update the item.newComments field in cache
73
- useLiveComments ( parentId , lastCommentAt || parentCreatedAt , router . query . sort )
76
+ useLiveComments ( parentId , lastCommentAt || parentCreatedAt , router . query . sort , setHasNewComments )
77
+ console . log ( 'hasNewComments' , hasNewComments )
78
+ const hasNewNotes = useHasNewNotes ( )
74
79
75
80
const pins = useMemo ( ( ) => comments ?. filter ( ( { position } ) => ! ! position ) . sort ( ( a , b ) => a . position - b . position ) , [ comments ] )
76
81
77
82
return (
78
83
< >
84
+ < Head >
85
+ < link rel = 'shortcut icon' href = { hasNewComments ? '/favicon.png' : hasNewNotes ? '/favicon-notify.png' : '/favicon.png' } />
86
+ </ Head >
79
87
{ comments ?. length > 0
80
88
? < CommentsHeader
81
89
commentSats = { commentSats } parentCreatedAt = { parentCreatedAt }
@@ -93,15 +101,15 @@ export default function Comments ({
93
101
/>
94
102
: null }
95
103
{ newComments ?. length > 0 && (
96
- < ShowNewComments topLevel comments = { comments } newComments = { newComments } itemId = { parentId } sort = { router . query . sort } />
104
+ < ShowNewComments topLevel comments = { comments } newComments = { newComments } itemId = { parentId } sort = { router . query . sort } setHasNewComments = { setHasNewComments } />
97
105
) }
98
106
{ pins . map ( item => (
99
107
< Fragment key = { item . id } >
100
- < Comment depth = { 1 } item = { item } { ...props } pin />
108
+ < Comment depth = { 1 } item = { item } { ...props } pin setHasNewComments = { setHasNewComments } />
101
109
</ Fragment >
102
110
) ) }
103
111
{ comments . filter ( ( { position } ) => ! position ) . map ( item => (
104
- < Comment depth = { 1 } key = { item . id } item = { item } { ...props } />
112
+ < Comment depth = { 1 } key = { item . id } item = { item } { ...props } setHasNewComments = { setHasNewComments } />
105
113
) ) }
106
114
{ ncomments > FULL_COMMENTS_THRESHOLD &&
107
115
< MoreFooter
0 commit comments