mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-09-28 22:09:05 +02:00
fix: handle localStorage not enabled gracefully (#1786)
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
<link rel="apple-touch-icon" href="/img/static-logo-512.png" />
|
||||
<script>
|
||||
try {
|
||||
const mode = localStorage.getItem('mode-watcher-mode') || 'system';
|
||||
const mode = localStorage?.getItem('mode-watcher-mode') || 'system';
|
||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
const isDark = mode === 'dark' || (mode === 'system' && prefersDark);
|
||||
|
||||
|
||||
@@ -30,14 +30,14 @@
|
||||
let expanded = $state(defaultExpanded);
|
||||
|
||||
function loadExpandedState() {
|
||||
const state = JSON.parse(localStorage.getItem('collapsible-cards-expanded') || '{}');
|
||||
const state = JSON.parse(localStorage?.getItem('collapsible-cards-expanded') || '{}');
|
||||
expanded = state[id] || false;
|
||||
}
|
||||
|
||||
function saveExpandedState() {
|
||||
const state = JSON.parse(localStorage.getItem('collapsible-cards-expanded') || '{}');
|
||||
const state = JSON.parse(localStorage?.getItem('collapsible-cards-expanded') || '{}');
|
||||
state[id] = expanded;
|
||||
localStorage.setItem('collapsible-cards-expanded', JSON.stringify(state));
|
||||
localStorage?.setItem('collapsible-cards-expanded', JSON.stringify(state));
|
||||
}
|
||||
|
||||
function toggleExpanded() {
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
onMount(() => {
|
||||
if (dismissibleId) {
|
||||
const dismissedAlerts = JSON.parse(localStorage.getItem('dismissed-alerts') || '[]');
|
||||
const dismissedAlerts = JSON.parse(localStorage?.getItem('dismissed-alerts') || '[]');
|
||||
isVisible = !dismissedAlerts.includes(dismissibleId);
|
||||
}
|
||||
});
|
||||
@@ -54,8 +54,8 @@
|
||||
function dismiss() {
|
||||
onDismiss?.();
|
||||
if (dismissibleId) {
|
||||
const dismissedAlerts = JSON.parse(localStorage.getItem('dismissed-alerts') || '[]');
|
||||
localStorage.setItem('dismissed-alerts', JSON.stringify([...dismissedAlerts, dismissibleId]));
|
||||
const dismissedAlerts = JSON.parse(localStorage?.getItem('dismissed-alerts') || '[]');
|
||||
localStorage?.setItem('dismissed-alerts', JSON.stringify([...dismissedAlerts, dismissibleId]));
|
||||
isVisible = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,13 +103,13 @@ function bustImageCache(url: URL) {
|
||||
const key = normalizeUrlForKey(url);
|
||||
const expiresAt = Date.now() + 1000 * 60 * 15;
|
||||
|
||||
const store: SkipCacheUntil = JSON.parse(localStorage.getItem('skip-cache-until') ?? '{}');
|
||||
const store: SkipCacheUntil = JSON.parse(localStorage?.getItem('skip-cache-until') ?? '{}');
|
||||
store[key] = expiresAt;
|
||||
localStorage.setItem('skip-cache-until', JSON.stringify(store));
|
||||
localStorage?.setItem('skip-cache-until', JSON.stringify(store));
|
||||
}
|
||||
|
||||
function getSkipCacheUntil(key: string): number {
|
||||
const store: SkipCacheUntil = JSON.parse(localStorage.getItem('skip-cache-until') ?? '{}');
|
||||
const store: SkipCacheUntil = JSON.parse(localStorage?.getItem('skip-cache-until') ?? '{}');
|
||||
return store[key] ?? 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user