refactor(state): fix code quality findings for nav panel store and prefs
This commit is contained in:
+14
-1
@@ -21,7 +21,20 @@ export function getPrefs(): GamePrefs {
|
||||
if (typeof localStorage === 'undefined') return { ...DEFAULTS };
|
||||
try {
|
||||
const raw = localStorage.getItem(PREFS_KEY);
|
||||
if (!raw) return { ...DEFAULTS };
|
||||
if (!raw) {
|
||||
const rawV1 = localStorage.getItem('idlegame:prefs:v1');
|
||||
if (rawV1) {
|
||||
try {
|
||||
const parsedV1 = JSON.parse(rawV1);
|
||||
const migrated = { ...DEFAULTS, ...parsedV1 };
|
||||
localStorage.setItem(PREFS_KEY, JSON.stringify(migrated));
|
||||
return migrated;
|
||||
} catch {
|
||||
return { ...DEFAULTS };
|
||||
}
|
||||
}
|
||||
return { ...DEFAULTS };
|
||||
}
|
||||
return { ...DEFAULTS, ...JSON.parse(raw) };
|
||||
} catch {
|
||||
return { ...DEFAULTS };
|
||||
|
||||
Reference in New Issue
Block a user