mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-20 22:06:42 +02:00
refactor(manacore): centralize localStorage keys in storage-keys config
Extract hardcoded localStorage key strings into a central STORAGE_KEYS constant to avoid key collisions and improve maintainability. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7077c0a397
commit
0519440705
2 changed files with 19 additions and 2 deletions
16
apps/manacore/apps/web/src/lib/config/storage-keys.ts
Normal file
16
apps/manacore/apps/web/src/lib/config/storage-keys.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* Centralized localStorage keys for the ManaCore web app.
|
||||
* All keys should be prefixed with 'manacore-' to avoid collisions.
|
||||
*/
|
||||
export const STORAGE_KEYS = {
|
||||
/** User's preferred locale (e.g., 'de', 'en') */
|
||||
LOCALE: 'locale',
|
||||
/** Whether the sidebar navigation is collapsed */
|
||||
NAV_COLLAPSED: 'manacore-nav-collapsed',
|
||||
/** Whether the welcome page has been seen */
|
||||
HAS_SEEN_WELCOME: 'hasSeenWelcome',
|
||||
/** Onboarding wizard state (JSON) */
|
||||
ONBOARDING: 'manacore-onboarding',
|
||||
/** Dashboard widget layout (JSON) — defined in default-dashboard.ts */
|
||||
// DASHBOARD: 'manacore-dashboard-config',
|
||||
} as const;
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import { browser } from '$app/environment';
|
||||
import { init, register, locale, waitLocale } from 'svelte-i18n';
|
||||
import { STORAGE_KEYS } from '$lib/config/storage-keys';
|
||||
|
||||
// Register all available locales
|
||||
register('de', () => import('./locales/de.json'));
|
||||
|
|
@ -19,7 +20,7 @@ const defaultLocale = 'de';
|
|||
function getInitialLocale(): SupportedLocale {
|
||||
if (browser) {
|
||||
// Check localStorage first
|
||||
const stored = localStorage.getItem('locale');
|
||||
const stored = localStorage.getItem(STORAGE_KEYS.LOCALE);
|
||||
if (stored && supportedLocales.includes(stored as SupportedLocale)) {
|
||||
return stored as SupportedLocale;
|
||||
}
|
||||
|
|
@ -52,7 +53,7 @@ export function initI18n() {
|
|||
export function setLocale(newLocale: SupportedLocale) {
|
||||
locale.set(newLocale);
|
||||
if (browser) {
|
||||
localStorage.setItem('locale', newLocale);
|
||||
localStorage.setItem(STORAGE_KEYS.LOCALE, newLocale);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue