From 7ee28c7ca395f4e787b4158f9193946809775e2d Mon Sep 17 00:00:00 2001 From: Josh Wright Date: Sun, 5 Apr 2026 11:00:14 -0400 Subject: [PATCH] feat: auto-refresh homepage data every 2 minutes on current week MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Uses router.refresh() to re-run server data fetching (ride counts, open status) without a full page reload. Only runs when viewing the current week — no need to poll for past/future weeks. Co-Authored-By: Claude Sonnet 4.6 --- components/HomePageClient.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) 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);