import { useEffect, useState } from "react"; import { getGreetingPeriod, type GreetingPeriod } from "./greeting"; // Checked frequently enough that a period rollover (e.g. 11:59 -> 12:00) is picked up // within the Dashboard while the app stays open, without a page reload -- see section 9 // of the Fleet Ops final localization brief. const CHECK_INTERVAL_MS = 30_000; export function useGreetingPeriod(): GreetingPeriod { const [period, setPeriod] = useState(() => getGreetingPeriod()); useEffect(() => { const id = setInterval(() => { setPeriod((current) => { const next = getGreetingPeriod(); return next === current ? current : next; }); }, CHECK_INTERVAL_MS); return () => clearInterval(id); }, []); return period; }