diff --git a/components/HomePageClient.tsx b/components/HomePageClient.tsx index 35d6b4d..5eb88ae 100644 --- a/components/HomePageClient.tsx +++ b/components/HomePageClient.tsx @@ -1,6 +1,7 @@ "use client"; import { useState, useEffect } from "react"; +import { useRouter } from "next/navigation"; import { WeekCalendar } from "./WeekCalendar"; import { MobileCardList } from "./MobileCardList"; import { WeekNav } from "./WeekNav"; @@ -9,6 +10,8 @@ import { EmptyState } from "./EmptyState"; import { PARKS, groupByRegion } from "@/lib/parks"; import type { DayData } from "@/lib/db"; +const REFRESH_INTERVAL_MS = 2 * 60 * 1000; // 2 minutes + const COASTER_MODE_KEY = "coasterMode"; interface HomePageClientProps { @@ -36,6 +39,7 @@ export function HomePageClient({ hasCoasterData, scrapedCount, }: HomePageClientProps) { + const router = useRouter(); const [coastersOnly, setCoastersOnly] = useState(false); // Hydrate from localStorage after mount to avoid SSR mismatch. @@ -43,6 +47,13 @@ export function HomePageClient({ setCoastersOnly(localStorage.getItem(COASTER_MODE_KEY) === "true"); }, []); + // Periodically re-fetch server data (ride counts, open status) without a full page reload. + useEffect(() => { + if (!isCurrentWeek) return; + const id = setInterval(() => router.refresh(), REFRESH_INTERVAL_MS); + return () => clearInterval(id); + }, [isCurrentWeek, router]); + // Remember the current week so the park page back button returns here. useEffect(() => { localStorage.setItem("lastWeek", weekStart);