1
1
import { A , Markdown } from '@/components'
2
+ import classNames from 'classnames'
2
3
import { DateTime } from 'luxon'
3
4
import { useSession } from 'next-auth/client'
4
5
import { useEffect } from 'react'
@@ -48,7 +49,13 @@ function message({ notification }: { notification: NotificationType }) {
48
49
return ''
49
50
}
50
51
51
- function Notification ( { notification } : { notification : NotificationType } ) {
52
+ function Notification ( {
53
+ notification,
54
+ isRead,
55
+ } : {
56
+ notification : NotificationType
57
+ isRead : boolean
58
+ } ) {
52
59
const [ session ] = useSession ( )
53
60
const currentUserId = ( session . user as User ) . id
54
61
if ( currentUserId === notification . user . id ) {
@@ -68,7 +75,7 @@ function Notification({ notification }: { notification: NotificationType }) {
68
75
notification . user . account ?. firstName ?? notification . user . username
69
76
70
77
return (
71
- < li className = "py-4" >
78
+ < li className = { classNames ( 'p-4' , ! isRead && 'bg-gray-200' ) } >
72
79
< div className = "flex items-center space-x-4" >
73
80
< div className = "flex-shrink-0" >
74
81
< A href = { `/${ notification . user . username } ` } >
@@ -101,12 +108,18 @@ function NotificationsList({
101
108
} : {
102
109
notifications : NotificationType [ ]
103
110
} ) {
111
+ const queryClient = useQueryClient ( )
112
+ const count = queryClient . getQueryData ( 'api/fauna/has-notifications' )
104
113
return (
105
114
< div >
106
115
< div className = "flow-root mt-6" >
107
116
< ul className = "-my-5 divide-y divide-gray-200" >
108
- { notifications . map ( ( notification ) => (
109
- < Notification notification = { notification } key = { notification . id } />
117
+ { notifications . map ( ( notification , index ) => (
118
+ < Notification
119
+ notification = { notification }
120
+ key = { notification . id }
121
+ isRead = { index >= count }
122
+ />
110
123
) ) }
111
124
</ ul >
112
125
</ div >
@@ -147,7 +160,11 @@ export default function Notifications() {
147
160
}
148
161
return (
149
162
< >
150
- < NotificationsList notifications = { data } />
163
+ < NotificationsList
164
+ notifications = { data . map (
165
+ ( _ , index : number ) => data [ data . length - 1 - index ]
166
+ ) }
167
+ />
151
168
</ >
152
169
)
153
170
}
0 commit comments