managarten/apps-archived/finance/apps/web/src/lib/stores/user-settings.svelte.ts
Till-JS ace7fa8f7f chore: archive finance, mail, moodlit apps and rename voxel-lava
- Move finance, mail, moodlit to apps-archived for later development
- Rename games/voxel-lava to games/voxelava

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 13:13:15 +01:00

66 lines
1.3 KiB
TypeScript

/**
* User Settings Store for Finance
* Manages user preferences and settings
*/
interface UserSettings {
currency: string;
locale: string;
dateFormat: string;
nav: {
desktopPosition: 'left' | 'center' | 'right';
};
}
const defaultSettings: UserSettings = {
currency: 'EUR',
locale: 'de',
dateFormat: 'dd.MM.yyyy',
nav: {
desktopPosition: 'center',
},
};
let settings = $state<UserSettings>({ ...defaultSettings });
let isLoaded = $state(false);
export const userSettings = {
get currency() {
return settings.currency;
},
get locale() {
return settings.locale;
},
get dateFormat() {
return settings.dateFormat;
},
get nav() {
return settings.nav;
},
get isLoaded() {
return isLoaded;
},
async load() {
if (typeof window === 'undefined') return;
// Load from localStorage
const saved = localStorage.getItem('finance-user-settings');
if (saved) {
try {
const parsed = JSON.parse(saved);
settings = { ...defaultSettings, ...parsed };
} catch {
// Ignore parse errors
}
}
isLoaded = true;
},
update(updates: Partial<UserSettings>) {
settings = { ...settings, ...updates };
if (typeof localStorage !== 'undefined') {
localStorage.setItem('finance-user-settings', JSON.stringify(settings));
}
},
};