/** * 60-second interval to refresh duty list when viewing the current month. * Replaces state.todayRefreshInterval from webapp/js/main.js. */ "use client"; import { useEffect, useRef } from "react"; const AUTO_REFRESH_INTERVAL_MS = 60000; /** * When isCurrentMonth is true, starts a 60-second interval to refresh. Does not call refresh() * immediately so the initial load is handled only by useMonthData (avoids duplicate first fetch). * When isCurrentMonth becomes false or on unmount, the interval is cleared. */ export function useAutoRefresh( refresh: () => void, isCurrentMonth: boolean ): void { const refreshRef = useRef(refresh); refreshRef.current = refresh; useEffect(() => { if (!isCurrentMonth) return; const id = setInterval(() => refreshRef.current(), AUTO_REFRESH_INTERVAL_MS); return () => clearInterval(id); }, [isCurrentMonth]); }