feat: add websocket and analytics

This commit is contained in:
gosangam
2026-06-07 00:23:54 +05:30
parent 0db339254d
commit bcffe9684f
8 changed files with 219 additions and 29 deletions
+7 -21
View File
@@ -2,33 +2,19 @@
/**
* NotificationBell — header affordance for signed-in users. Links to the
* /notifications page and shows a dot when there are unread items. The
* unread count is fetched once on mount (good enough until websocket/push
* delivery lands); visiting the page marks everything read.
* /notifications page and shows a dot when there are unread items.
*
* The unread count is read from NotificationsProvider, which seeds it from
* the REST endpoint and keeps it live over the Soketi WebSocket. Visiting
* the page marks everything read and clears the badge.
*/
import { useEffect, useState } from "react";
import Link from "next/link";
import { Bell } from "lucide-react";
import { notifications } from "@/lib/social";
import { useNotifications } from "@/components/notifications/notifications-provider";
export function NotificationBell() {
const [unread, setUnread] = useState(0);
useEffect(() => {
let cancelled = false;
notifications
.unreadCount()
.then((r) => {
if (!cancelled) setUnread(r?.count ?? 0);
})
.catch(() => {
/* badge is non-critical — ignore */
});
return () => {
cancelled = true;
};
}, []);
const { unread } = useNotifications();
return (
<Link