forked from CSGOWTF/csgowtf
- Add dynamic MR12/MR15 halftime calculation to RoundTimeline component - Fix TrackPlayerModal API signature (remove shareCode, change isOpen to open binding) - Update Player types for string IDs and add ban fields (vac_count, vac_date, game_ban_count, game_ban_date) - Add target/rel props to Button component for external links - Enhance homepage with processing matches indicator - Update preferences store for string player IDs - Document Phase 5 progress and TypeScript fixes in TODO.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
101 lines
2.4 KiB
TypeScript
101 lines
2.4 KiB
TypeScript
import { writable } from 'svelte/store';
|
|
import { browser } from '$app/environment';
|
|
|
|
/**
|
|
* User preferences store
|
|
* Persisted to localStorage
|
|
*/
|
|
|
|
export interface UserPreferences {
|
|
theme: 'cs2dark' | 'cs2light' | 'auto';
|
|
language: string;
|
|
favoriteMap?: string;
|
|
favoritePlayers: string[]; // Steam IDs as strings to preserve uint64 precision
|
|
showAdvancedStats: boolean;
|
|
dateFormat: 'relative' | 'absolute';
|
|
timezone: string;
|
|
}
|
|
|
|
const defaultPreferences: UserPreferences = {
|
|
theme: 'cs2dark',
|
|
language: 'en',
|
|
favoritePlayers: [],
|
|
showAdvancedStats: false,
|
|
dateFormat: 'relative',
|
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
};
|
|
|
|
// Load preferences from localStorage
|
|
const loadPreferences = (): UserPreferences => {
|
|
if (!browser) return defaultPreferences;
|
|
|
|
try {
|
|
const stored = localStorage.getItem('cs2wtf-preferences');
|
|
if (stored) {
|
|
return { ...defaultPreferences, ...JSON.parse(stored) };
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to load preferences:', error);
|
|
}
|
|
|
|
return defaultPreferences;
|
|
};
|
|
|
|
// Create the store
|
|
const createPreferencesStore = () => {
|
|
const { subscribe, set, update } = writable<UserPreferences>(loadPreferences());
|
|
|
|
return {
|
|
subscribe,
|
|
set: (value: UserPreferences) => {
|
|
if (browser) {
|
|
localStorage.setItem('cs2wtf-preferences', JSON.stringify(value));
|
|
}
|
|
set(value);
|
|
},
|
|
update: (fn: (value: UserPreferences) => UserPreferences) => {
|
|
update((current) => {
|
|
const newValue = fn(current);
|
|
if (browser) {
|
|
localStorage.setItem('cs2wtf-preferences', JSON.stringify(newValue));
|
|
}
|
|
return newValue;
|
|
});
|
|
},
|
|
reset: () => {
|
|
if (browser) {
|
|
localStorage.removeItem('cs2wtf-preferences');
|
|
}
|
|
set(defaultPreferences);
|
|
},
|
|
|
|
// Convenience methods
|
|
setTheme: (theme: UserPreferences['theme']) => {
|
|
update((prefs) => ({ ...prefs, theme }));
|
|
},
|
|
setLanguage: (language: string) => {
|
|
update((prefs) => ({ ...prefs, language }));
|
|
},
|
|
addFavoritePlayer: (playerId: string) => {
|
|
update((prefs) => ({
|
|
...prefs,
|
|
favoritePlayers: [...new Set([...prefs.favoritePlayers, playerId])]
|
|
}));
|
|
},
|
|
removeFavoritePlayer: (playerId: string) => {
|
|
update((prefs) => ({
|
|
...prefs,
|
|
favoritePlayers: prefs.favoritePlayers.filter((id) => id !== playerId)
|
|
}));
|
|
},
|
|
toggleAdvancedStats: () => {
|
|
update((prefs) => ({
|
|
...prefs,
|
|
showAdvancedStats: !prefs.showAdvancedStats
|
|
}));
|
|
}
|
|
};
|
|
};
|
|
|
|
export const preferences = createPreferencesStore();
|