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:
Till JS 2026-03-25 10:36:40 +01:00
parent 7077c0a397
commit 0519440705
2 changed files with 19 additions and 2 deletions

View 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;

View file

@ -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);
}
}