diff --git a/showcase.json b/showcase.json index 54ee371c..af95835e 100644 --- a/showcase.json +++ b/showcase.json @@ -60,5 +60,6 @@ "atlas", "meow-7218", "erection", - "vup" + "vup", + "jowno" ] diff --git a/src/components/dashboard/DashboardLayout.tsx b/src/components/dashboard/DashboardLayout.tsx index c2c1044a..b78eec2a 100644 --- a/src/components/dashboard/DashboardLayout.tsx +++ b/src/components/dashboard/DashboardLayout.tsx @@ -12,7 +12,8 @@ import { SiteSwitcher } from "./SiteSwitcher" import { useGetUserSites } from "~/queries/site" import { useAccount } from "wagmi" import { ConnectButton } from "~/components/common/ConnectButton" -import { useGetSite } from "~/queries/site" +import { useGetNotifications, useGetSite } from "~/queries/site" +import { getStorage } from "~/lib/storage" export function DashboardLayout({ children, @@ -29,6 +30,25 @@ export function DashboardLayout({ const userSite = useGetUserSites(address) + const notifications = useGetNotifications({ + siteCId: site.data?.metadata?.proof, + }) + + const notificationCreatedAt = + getStorage(`notification-${subdomain}`)?.createdAt || 0 + + const [notificationCount, setNotificationCount] = useState(0) + + useEffect(() => { + if (notifications.data && subdomain) { + const count = notifications.data.filter( + (notification: any) => + +new Date(notification.createdAt) > +new Date(notificationCreatedAt), + ).length + setNotificationCount(count) + } + }, [notifications.data, subdomain, notificationCreatedAt]) + useEffect(() => { if (!address) { router.push("/") @@ -67,8 +87,10 @@ export function DashboardLayout({ { href: `/dashboard/${subdomain}/notifications`, isActive: ({ href, pathname }) => href === pathname, - icon: "i-bi:bell", - text: "Notifications", + icon: notificationCount > 0 ? "i-bi:bell-fill" : "i-bi:bell", + text: + "Notifications" + + (notificationCount > 0 ? ` (${notificationCount})` : ""), }, { href: `/dashboard/${subdomain}/settings/general`, diff --git a/src/pages/dashboard/[subdomain]/notifications.tsx b/src/pages/dashboard/[subdomain]/notifications.tsx index 30c9efa3..a11389c2 100644 --- a/src/pages/dashboard/[subdomain]/notifications.tsx +++ b/src/pages/dashboard/[subdomain]/notifications.tsx @@ -12,6 +12,8 @@ import relativeTime from "dayjs/plugin/relativeTime" import { BlockchainIcon } from "~/components/icons/BlockchainIcon" import { CSB_SCAN } from "~/lib/env" import { PageContent } from "~/components/common/PageContent" +import { useEffect, useMemo, useState } from "react" +import { setStorage, getStorage } from "~/lib/storage" dayjs.extend(duration) dayjs.extend(relativeTime) @@ -26,6 +28,24 @@ export default function SubdomainIndex() { siteCId: site.data?.metadata?.proof, }) + const [lastNotificationCreated, setLastNotificationCreated] = useState(0) + + useMemo(() => { + if (subdomain && !lastNotificationCreated) { + setLastNotificationCreated( + +new Date(getStorage(`notification-${subdomain}`)?.createdAt || 1), + ) + } + }, [subdomain]) + + useEffect(() => { + if (notifications.data?.[0].createdAt && subdomain) { + setStorage(`notification-${subdomain}`, { + createdAt: notifications.data[0].createdAt, + }) + } + }, [notifications.data, subdomain]) + return ( @@ -59,7 +79,13 @@ export default function SubdomainIndex() { return (
-
+
+ {+new Date(notification.createdAt) > + +new Date(lastNotificationCreated) && ( +
+ New +
+ )}
@@ -70,7 +96,7 @@ export default function SubdomainIndex() { subdomain: character.handle, }) } - className="block align-middle mr-3" + className="block align-middle mr-3 text-[0px]" >