11import { A , Markdown } from '@/components'
2+ import classNames from 'classnames'
23import { DateTime } from 'luxon'
34import { useSession } from 'next-auth/client'
45import { useEffect } from 'react'
@@ -48,7 +49,13 @@ function message({ notification }: { notification: NotificationType }) {
4849 return ''
4950}
5051
51- function Notification ( { notification } : { notification : NotificationType } ) {
52+ function Notification ( {
53+ notification,
54+ isRead,
55+ } : {
56+ notification : NotificationType
57+ isRead : boolean
58+ } ) {
5259 const [ session ] = useSession ( )
5360 const currentUserId = ( session . user as User ) . id
5461 if ( currentUserId === notification . user . id ) {
@@ -68,7 +75,7 @@ function Notification({ notification }: { notification: NotificationType }) {
6875 notification . user . account ?. firstName ?? notification . user . username
6976
7077 return (
71- < li className = "py-4" >
78+ < li className = { classNames ( 'p-4' , ! isRead && 'bg-gray-200' ) } >
7279 < div className = "flex items-center space-x-4" >
7380 < div className = "flex-shrink-0" >
7481 < A href = { `/${ notification . user . username } ` } >
@@ -101,12 +108,18 @@ function NotificationsList({
101108} : {
102109 notifications : NotificationType [ ]
103110} ) {
111+ const queryClient = useQueryClient ( )
112+ const count = queryClient . getQueryData ( 'api/fauna/has-notifications' )
104113 return (
105114 < div >
106115 < div className = "flow-root mt-6" >
107116 < 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+ />
110123 ) ) }
111124 </ ul >
112125 </ div >
@@ -147,7 +160,11 @@ export default function Notifications() {
147160 }
148161 return (
149162 < >
150- < NotificationsList notifications = { data } />
163+ < NotificationsList
164+ notifications = { data . map (
165+ ( _ , index : number ) => data [ data . length - 1 - index ]
166+ ) }
167+ />
151168 </ >
152169 )
153170}
0 commit comments