From 424c2836536ef2ca60b687e68e4a2e858579b48e Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 16 Jan 2026 10:40:23 +0100 Subject: [PATCH] Notifications corrections --- components/calendar.tsx | 29 ++++++++++++++++++++++++----- components/email.tsx | 4 ++-- components/flow.tsx | 4 ++-- lib/constants/refresh-intervals.ts | 16 +++++++--------- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/components/calendar.tsx b/components/calendar.tsx index 851e455..1d47c83 100644 --- a/components/calendar.tsx +++ b/components/calendar.tsx @@ -5,6 +5,9 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { RefreshCw, Calendar as CalendarIcon } from "lucide-react"; import { useRouter } from "next/navigation"; +import { useSession } from "next-auth/react"; +import { useUnifiedRefresh } from "@/hooks/use-unified-refresh"; +import { REFRESH_INTERVALS } from "@/lib/constants/refresh-intervals"; interface Event { id: string; @@ -21,11 +24,13 @@ export function Calendar() { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const router = useRouter(); + const { data: session, status } = useSession(); - const fetchEvents = async () => { + const fetchEvents = async (forceRefresh: boolean = false) => { setLoading(true); try { - const response = await fetch('/api/calendars?refresh=true'); + const url = forceRefresh ? '/api/calendars?refresh=true' : '/api/calendars'; + const response = await fetch(url); if (!response.ok) { throw new Error('Failed to fetch events'); } @@ -151,9 +156,23 @@ export function Calendar() { } }; + // Initial fetch on mount useEffect(() => { - fetchEvents(); - }, []); + if (status === 'authenticated') { + fetchEvents(true); // Force refresh on initial load + } + }, [status]); + + // Integrate unified refresh for automatic polling + const { refresh } = useUnifiedRefresh({ + resource: 'calendar', + interval: REFRESH_INTERVALS.CALENDAR, // 30 seconds (harmonized) + enabled: status === 'authenticated', + onRefresh: async () => { + await fetchEvents(false); // Use cache for auto-refresh + }, + priority: 'high', + }); const formatDate = (dateString: string) => { const date = new Date(dateString); @@ -181,7 +200,7 @@ export function Calendar() {