feat(frontend): i18n, theming and account/browser/admin UI updates
- add French-keyed i18n with an English dictionary, plus theme and locale helpers, applied across all pages and components - account page: theme and language selectors and a two-column layout - browser: per-folder media type filters and unread chat badges - admin: audit log filtered by user and action through dropdowns - global API and type updates to match the new backend endpoints
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { useEffect, type ReactNode } from "react";
|
||||
import type { Theme } from "./api.js";
|
||||
|
||||
const STORAGE_KEY = "cohaise-theme";
|
||||
|
||||
const prefersDark = (): boolean =>
|
||||
typeof window !== "undefined" &&
|
||||
window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
|
||||
const isDark = (theme: Theme): boolean =>
|
||||
theme === "dark" || (theme === "system" && prefersDark());
|
||||
|
||||
/**
|
||||
* Applique le theme choisi dans le compte sur la racine du document. Le meme
|
||||
* choix est recopie dans `localStorage` pour que `public/theme.js` reproduise
|
||||
* le rendu des le premier pixel, avant que React ne demarre.
|
||||
*/
|
||||
export const ThemeProvider = ({ theme, children }: { theme: Theme; children: ReactNode }) => {
|
||||
useEffect(() => {
|
||||
const apply = () => {
|
||||
document.documentElement.classList.toggle("dark", isDark(theme));
|
||||
};
|
||||
apply();
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, theme);
|
||||
} catch {
|
||||
/* stockage indisponible : le rendu reste correct */
|
||||
}
|
||||
|
||||
if (theme !== "system") return undefined;
|
||||
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
const onChange = () => apply();
|
||||
media.addEventListener("change", onChange);
|
||||
return () => media.removeEventListener("change", onChange);
|
||||
}, [theme]);
|
||||
|
||||
return <>{children}</>;
|
||||
};
|
||||
Reference in New Issue
Block a user