Consolidate frontend storage keys into constants module

- Move magic strings from AuthProvider, MainLayout, and ThemeProvider to
  frontend/src/utils/constants.ts
- Add STORAGE_KEY_AUTHENTICATED, STORAGE_KEY_SIDEBAR_COLLAPSED, and
  STORAGE_KEY_THEME constants with JSDoc descriptions
- Update all three files to import and use centralized keys
- Prevents key drift and typo regressions across the frontend

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-04-28 09:48:28 +02:00
parent 72c4a0ed04
commit 252204ed97
5 changed files with 29 additions and 31 deletions

View File

@@ -36,6 +36,7 @@ import { useAuth } from "../hooks/useAuth";
import { useServerStatus } from "../hooks/useServerStatus";
import { useBlocklistStatus } from "../hooks/useBlocklistStatus";
import { useThemeMode } from "../providers/ThemeProvider";
import { STORAGE_KEY_SIDEBAR_COLLAPSED } from "../utils/constants";
// ---------------------------------------------------------------------------
// Styles
@@ -43,7 +44,6 @@ import { useThemeMode } from "../providers/ThemeProvider";
const SIDEBAR_FULL = "240px";
const SIDEBAR_COLLAPSED = "48px";
const SIDEBAR_COLLAPSED_STORAGE_KEY = "bangui_sidebar_collapsed";
const useStyles = makeStyles({
root: {
@@ -237,7 +237,7 @@ export function MainLayout(): React.JSX.Element {
const readSavedCollapsed = (): boolean => {
try {
const savedValue = localStorage.getItem(SIDEBAR_COLLAPSED_STORAGE_KEY);
const savedValue = localStorage.getItem(STORAGE_KEY_SIDEBAR_COLLAPSED);
if (savedValue === "true") {
return true;
}
@@ -259,14 +259,14 @@ export function MainLayout(): React.JSX.Element {
useEffect(() => {
try {
localStorage.setItem(SIDEBAR_COLLAPSED_STORAGE_KEY, String(collapsed));
localStorage.setItem(STORAGE_KEY_SIDEBAR_COLLAPSED, String(collapsed));
} catch {
// Local storage may be unavailable in some environments.
}
}, [collapsed]);
useEffect(() => {
const savedValue = localStorage.getItem(SIDEBAR_COLLAPSED_STORAGE_KEY);
const savedValue = localStorage.getItem(STORAGE_KEY_SIDEBAR_COLLAPSED);
if (savedValue !== null) {
return undefined;
}