Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2c5c0f

Browse files
committed
Add background color for notifications that are not viewed
1 parent b29e1e0 commit e2c5c0f

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/components/AppNavBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ export default function AppNavBar() {
101101
</Button>
102102

103103
<A href="/notifications">
104-
<button className="bg-white p-1 rounded-full text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
104+
<button className="bg-white p-1 rounded-full text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500">
105105
<span className="sr-only">View notifications</span>
106-
<span className="inline-block relative">
106+
<span className="flex items-center relative">
107107
<div className="border border-gray-300 rounded-full p-1">
108108
<svg
109109
className={classNames(

src/pages/notifications.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { A, Markdown } from '@/components'
2+
import classNames from 'classnames'
23
import { DateTime } from 'luxon'
34
import { useSession } from 'next-auth/client'
45
import { 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

Comments
 (0)