diff --git a/src/components/time-tracking/TimeTrackingFieldClient.tsx b/src/components/time-tracking/TimeTrackingFieldClient.tsx index 4cae2cc..8cab82f 100644 --- a/src/components/time-tracking/TimeTrackingFieldClient.tsx +++ b/src/components/time-tracking/TimeTrackingFieldClient.tsx @@ -392,8 +392,15 @@ const TRANS_ES: Translations = { function getLangCookie(): string { if (typeof document === "undefined") return "en"; - const match = document.cookie.match(/time_tracking_lang=(\w+)/); - return match ? match[1] : "en"; + // `time_tracking_lang` is the explicit override. Fall back to + // `wl_lang` so workers who switched to Spanish on the Water Log + // mobile app inherit the same language when they tap the Time tab + // — without this, the Time tab resets to English every time. + const tt = document.cookie.match(/time_tracking_lang=(\w+)/); + if (tt) return tt[1]; + const wl = document.cookie.match(/wl_lang=(\w+)/); + if (wl) return wl[1]; + return "en"; } function setLangCookie(lang: string) { @@ -410,8 +417,8 @@ function langToBcp(): "en-US" | "es-ES" { // Cheap global so `formatTime` doesn't have to thread `lang` around. // Resolved at call time from the lang cookie that's always set. if (typeof document === "undefined") return "en-US"; - const m = document.cookie.match(/time_tracking_lang=(\w+)/); - return m?.[1] === "es" ? "es-ES" : "en-US"; + const m = getLangCookie(); + return m === "es" ? "es-ES" : "en-US"; } function formatHours(minutes: number): string { @@ -538,7 +545,12 @@ function emptyManualDraft(): State["manualEntryDraft"] { const initialState: State = { lang: (getLangCookie() as "en" | "es") ?? "en", - screen: "pin", + // Start in `"loading"` so the init effect can resolve the session + // cookie + open clock-in before the UI renders. Previously this + // was `"pin"`, which caused a ~one-tick flash of the PIN screen on + // every tab switch — workers with a valid session saw the PIN UI + // for a moment before it was swapped out for Hub/Working. + screen: "loading", tasks: [], openEntry: null, payPeriod: null,