diff --git a/artifacts/teaboy-os/src/components/clock.tsx b/artifacts/teaboy-os/src/components/clock.tsx index 80691144..02f0729e 100644 --- a/artifacts/teaboy-os/src/components/clock.tsx +++ b/artifacts/teaboy-os/src/components/clock.tsx @@ -384,6 +384,50 @@ export function useHomeClockVisibility(): [boolean, (next: boolean) => void] { return [visible, setVisible]; } +const TOPBAR_CLOCK_STORAGE_KEY = "teaboy:topbar-clock-visible"; +const TOPBAR_CLOCK_EVENT = "teaboy:topbar-clock-changed"; + +function readTopbarClockVisible(): boolean { + if (typeof window === "undefined") return true; + try { + const v = window.localStorage.getItem(TOPBAR_CLOCK_STORAGE_KEY); + return v === null ? true : v === "1"; + } catch { + return true; + } +} + +/** + * Visibility for the small clock displayed in the home page top bar. + * Independent of useHomeClockVisibility, which controls the large + * grid widget on the home screen. + */ +export function useTopbarClockVisibility(): [boolean, (next: boolean) => void] { + const [visible, setVisibleState] = useState(readTopbarClockVisible); + + useEffect(() => { + const onChange = () => setVisibleState(readTopbarClockVisible()); + window.addEventListener(TOPBAR_CLOCK_EVENT, onChange); + window.addEventListener("storage", onChange); + return () => { + window.removeEventListener(TOPBAR_CLOCK_EVENT, onChange); + window.removeEventListener("storage", onChange); + }; + }, []); + + const setVisible = (next: boolean) => { + try { + window.localStorage.setItem(TOPBAR_CLOCK_STORAGE_KEY, next ? "1" : "0"); + } catch { + /* ignore */ + } + setVisibleState(next); + window.dispatchEvent(new Event(TOPBAR_CLOCK_EVENT)); + }; + + return [visible, setVisible]; +} + const HOME_CLOCK_SIZE_EVENT = "teaboy:home-clock-size-changed"; export type HomeClockSize = "compact" | "large"; diff --git a/artifacts/teaboy-os/src/pages/home.tsx b/artifacts/teaboy-os/src/pages/home.tsx index ea25d6d4..36fd1d91 100644 --- a/artifacts/teaboy-os/src/pages/home.tsx +++ b/artifacts/teaboy-os/src/pages/home.tsx @@ -58,6 +58,7 @@ import { useNow, AnalogClockWidget, useHomeClockVisibility, + useTopbarClockVisibility, useHomeClockSize, useHomeClockPosition, type HomeClockSize, @@ -318,6 +319,7 @@ export default function HomePage() { const gridCols = useGridCols(); const [homeClockVisible, setHomeClockVisible] = useHomeClockVisibility(); + const [topbarClockVisible, setTopbarClockVisible] = useTopbarClockVisibility(); const [clockSize, setClockSize] = useHomeClockSize(user?.id); const [clockPos, setClockPos] = useHomeClockPosition(user?.id); const toggleClockSize = () => setClockSize(clockSize === "large" ? "compact" : "large"); @@ -449,7 +451,7 @@ export default function HomePage() { {/* Clock + dates */} - {homeClockVisible && ( + {topbarClockVisible && (