feat: add feed

This commit is contained in:
gosangam
2026-06-14 00:18:31 +05:30
parent eb0c981d3c
commit 61581b67a7
9 changed files with 395 additions and 47 deletions
@@ -26,7 +26,7 @@ import {
} from "react";
import { toast } from "sonner";
import { useAuth } from "@/components/auth/auth-provider";
import { notifications } from "@/lib/social";
import { feed, notifications } from "@/lib/social";
import { sadhna } from "@/lib/sadhna";
type NotificationsContextValue = {
@@ -113,8 +113,24 @@ export function NotificationsProvider({
}
}, [user?.id]);
// Open the realtime connection while signed in.
const userId = user?.id;
// When the session ends — the page unloads / the realtime socket drops as
// the user navigates away or closes the tab — clear the home-feed seen-set
// so it doesn't linger in Redis. `keepalive` lets the request outlive the
// page. (Genuine network drops with no unload are caught by the set's TTL;
// we deliberately don't clear on transient socket blips, which would re-show
// posts mid-scroll.)
useEffect(() => {
if (!userId) return;
const onLeave = () => {
void feed.reset().catch(() => {});
};
window.addEventListener("pagehide", onLeave);
return () => window.removeEventListener("pagehide", onLeave);
}, [userId]);
// Open the realtime connection while signed in.
useEffect(() => {
if (!userId) return;
const key = process.env.NEXT_PUBLIC_SOKETI_KEY;