fix(ui,i18n): E30 review round 3 — the stored language follows the screen, a fresh text starts collapsed, Retry waits again

This commit is contained in:
2026-10-01 10:43:59 +02:00
parent 08e62bbb16
commit 3563858fd1
14 changed files with 147 additions and 32 deletions
+7 -3
View File
@@ -2,18 +2,22 @@ import type { QueryClient } from "@tanstack/react-query";
import { isSupported } from "../i18n";
import { api } from "./api";
import { LANGUAGE_ORDERED } from "./queryKeys";
import { updateMeCache } from "./useMe";
/** Store the reader's language choice on the server, then ask again for the lists the server orders
* by it (`LANGUAGE_ORDERED`): only once the save has landed does the server sort in the new alphabet.
* Rejects with the save's error; the lists are left alone then. */
* The cached `me` takes it too, so what reads the stored language (`serverOrderLang`) agrees with the
* server at once, not at the next `me` poll. Rejects with the save's error; nothing is touched then. */
export async function saveLanguage(qc: QueryClient, code: string): Promise<void> {
await api.savePrefs({ language: code });
updateMeCache(qc, (me) => ({ ...me, preferences: { ...me.preferences, language: code } }));
for (const queryKey of LANGUAGE_ORDERED) void qc.invalidateQueries({ queryKey });
}
/** The language the server orders this account's lists in (backend `mailtext.lang_for_user`): the
* stored preference, else English. Not always the UI's — a browser-detected language, or one picked
* while signed out, is never stored — so a list re-slotted here to match the server's order uses it. */
* stored preference, else English. Not always the UI's: an account with none stored stores the one
* it is shown in at boot (BootGate), but until that save lands, or if it fails, the two differ — so a
* list re-slotted here to match the server's order uses this, not the UI's. */
export function serverOrderLang(preferences: Record<string, unknown> | null | undefined): string {
const lang = preferences?.language;
return typeof lang === "string" && isSupported(lang) ? lang : "en";