A signed-in user with a snapshot goes straight to home; the same boot requests run in the background and replace it. Snapshot is cleared whenever tokens are cleared and on a new login, ignored from another build or when older than 7 days, and dropped when the fresh profile is a different user (reboot remounts MainApp via a generation key; AnimatePresence otherwise kept the exiting one). Notifications/characters wait for the profile answer so an expired access token costs the same requests as before. refreshHome applies only the latest answer. Home shows a "saved data" strip when the map could not be refreshed. Measured locally (old vs new build, same backend, Chrome throttling, median of 3, time to map): Fast 3G 2.46s -> 1.80s (expired token 3.63s -> 1.80s); Slow 3G 8.52s -> 6.14s (expired 12.6s -> 6.13s); API requests per open unchanged (6 valid, 11 expired). 12/12 behaviour checks passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
/** localStorage با try/catch؛ در حالتِ خصوصیِ مرورگر یا دسترسیِ مسدود throw نمیکند. */
|
|
export const store = {
|
|
get(key: string): string | null {
|
|
try {
|
|
return localStorage.getItem(key);
|
|
} catch {
|
|
return null;
|
|
}
|
|
},
|
|
set(key: string, value: string) {
|
|
try {
|
|
localStorage.setItem(key, value);
|
|
} catch {
|
|
/* نادیده */
|
|
}
|
|
},
|
|
remove(key: string) {
|
|
try {
|
|
localStorage.removeItem(key);
|
|
} catch {
|
|
/* نادیده */
|
|
}
|
|
},
|
|
};
|
|
|
|
export const KEYS = {
|
|
onboarded: 'tadrisino.onboarded',
|
|
conversationId: 'tadrisino.conversationId',
|
|
sound: 'tadrisino.sound',
|
|
referralCode: 'tadrisino.referralCode',
|
|
companion: 'tadrisino.companion',
|
|
/** {gradeId: subjectKey}؛ کتابی که کاربر در هر پایه آخر انتخاب کرده. */
|
|
subjects: 'tadrisino.subjects',
|
|
/** عکسِ صفحهی خانه برای بازشدنِ فوری (state/homeSnapshot.ts). */
|
|
homeSnapshot: 'tadrisino.homeSnapshot',
|
|
} as const;
|