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
+12 -5
View File
@@ -19,11 +19,13 @@ import Link from "next/link";
import { Bell } from "lucide-react";
import { useAuth } from "@/components/auth/auth-provider";
import { useAuthGate } from "@/components/auth/auth-gate";
import { useNotifications } from "@/components/notifications/notifications-provider";
import { notifications, type AppNotification } from "@/lib/social";
export default function NotificationsPage() {
const { user, loading } = useAuth();
const { requireAuth } = useAuthGate();
const { lastEventAt, clearUnread } = useNotifications();
const router = useRouter();
const [items, setItems] = useState<AppNotification[]>([]);
@@ -42,7 +44,9 @@ export default function NotificationsPage() {
};
}, [loading, user, requireAuth, router]);
// Load the feed + mark everything read once we have a user.
// Load the feed + mark everything read once we have a user, and again
// whenever a realtime notification arrives while the page is open
// (lastEventAt bumps). Marking read here also clears the header badge.
useEffect(() => {
if (!user) return;
let cancelled = false;
@@ -57,13 +61,16 @@ export default function NotificationsPage() {
.catch(() => {
if (!cancelled) setState("error");
});
notifications.markAllRead().catch(() => {
/* non-critical */
});
notifications
.markAllRead()
.then(() => clearUnread())
.catch(() => {
/* non-critical */
});
return () => {
cancelled = true;
};
}, [user]);
}, [user, lastEventAt, clearUnread]);
if (loading || !user) {
return (