diff --git a/frontend/src/components/TimeSyncNotice.tsx b/frontend/src/components/TimeSyncNotice.tsx index 67a75e3..9a8e8ff 100644 --- a/frontend/src/components/TimeSyncNotice.tsx +++ b/frontend/src/components/TimeSyncNotice.tsx @@ -8,17 +8,15 @@ function formatMs(ms: number) { export default function TimeSyncNotice({ thresholdMs = 500, - endpoint, intervalMs, lang = "ja", }: { thresholdMs?: number; - endpoint?: string; intervalMs?: number; lang?: "ja" | "en"; }) { // removed `error` - const { skewMs, rttMs, recheck } = useTimeSkew({ endpoint, intervalMs }); + const { skewMs, rttMs, recheck } = useTimeSkew({ intervalMs }); const [dismissed, setDismissed] = useState(() => { try { return sessionStorage.getItem("timesync.dismissed") === "1"; } catch { return false; } diff --git a/frontend/src/hooks/useTimeSkew.ts b/frontend/src/hooks/useTimeSkew.ts index 60ca0e9..03d816a 100644 --- a/frontend/src/hooks/useTimeSkew.ts +++ b/frontend/src/hooks/useTimeSkew.ts @@ -1,4 +1,5 @@ import { useEffect, useRef, useState } from "react"; +import { API_ENDPOINT } from "../api/endpoint"; /** * Measures client clock skew vs server time {now: }. @@ -9,6 +10,8 @@ import { useEffect, useRef, useState } from "react"; * offset ≈ ((t0 + t1)/2) - s * Positive offset => client is AHEAD by that many ms. */ +const TIME_URL_ENDPOINT = API_ENDPOINT.v1.TIME; + export function useTimeSkew(opts?: { endpoint?: string; // e.g., "/api/time" or `${import.meta.env.BASE_URL}api/time` intervalMs?: number; // how often to recheck; default 5 min @@ -16,7 +19,6 @@ export function useTimeSkew(opts?: { enabled?: boolean; // allow turning off; default true }) { const { - endpoint = "/api/time", intervalMs = 5 * 60_000, samples = 1, enabled = true, @@ -29,7 +31,7 @@ export function useTimeSkew(opts?: { const measureOnce = async () => { const t0 = Date.now(); - const res = await fetch(endpoint, { cache: "no-store" }); + const res = await fetch(TIME_URL_ENDPOINT, { cache: "no-store" }); const t1 = Date.now(); if (!res.ok) throw new Error(`HTTP ${res.status}`); const data = await res.json(); @@ -81,7 +83,7 @@ export function useTimeSkew(opts?: { if (timerRef.current) window.clearInterval(timerRef.current); }; // eslint-disable-next-line react-hooks/exhaustive-deps - }, [endpoint, intervalMs, samples, enabled]); + }, [intervalMs, samples, enabled]); return { skewMs, rttMs, error, recheck: measure }; } \ No newline at end of file