feat: update daily character management and local storage handling

This commit is contained in:
2026-03-01 16:43:54 +01:00
parent 0b81e9e350
commit 00bd718699
5 changed files with 39 additions and 42 deletions

View File

@@ -22,20 +22,36 @@
// Load from localStorage on mount
onMount(() => {
const stored = localStorage.getItem('dailyCharacterHistory');
if (stored) {
try {
const storedIds = JSON.parse(stored);
// Reconstruct character objects from IDs
if (Array.isArray(storedIds)) {
selectedCharacters = storedIds
.map((id: string) => data.characters.find((c: any) => c.id === id))
.filter((c: any) => c !== undefined);
const storedDailyCharacterId = localStorage.getItem('currentDailyCharacterId');
const currentDailyCharacterId = dailyCharacter?.id;
// If the daily character has changed, clear the history
if (storedDailyCharacterId && storedDailyCharacterId !== currentDailyCharacterId) {
localStorage.removeItem('dailyCharacterHistory');
selectedCharacters = [];
} else {
// Load existing history if the character hasn't changed
const stored = localStorage.getItem('dailyCharacterHistory');
if (stored) {
try {
const storedIds = JSON.parse(stored);
// Reconstruct character objects from IDs
if (Array.isArray(storedIds)) {
selectedCharacters = storedIds
.map((id: string) => data.characters.find((c: any) => c.id === id))
.filter((c: any) => c !== undefined);
}
} catch (e) {
console.error('Failed to parse stored history', e);
}
} catch (e) {
console.error('Failed to parse stored history', e);
}
}
// Store the current daily character ID
if (currentDailyCharacterId) {
localStorage.setItem('currentDailyCharacterId', currentDailyCharacterId);
}
isLoaded = true;
});