From 52ea335714f2b495b92f87636c269b73b4067066 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Mon, 16 Feb 2026 11:28:01 -0800 Subject: v3: persist sidebar state via cookie, default closed on tablet/mobile Sidebar open/close state is now saved to a cookie (neko_sidebar) so it persists across page reloads. On first visit without a cookie, the sidebar defaults to closed on tablet and mobile (<=1024px viewport) and open on desktop. Removes the auto-open-on-resize behavior that was overriding user preference. Co-Authored-By: Claude Opus 4.6 --- frontend-vanilla/src/store.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'frontend-vanilla/src/store.ts') diff --git a/frontend-vanilla/src/store.ts b/frontend-vanilla/src/store.ts index a23934a..c92059a 100644 --- a/frontend-vanilla/src/store.ts +++ b/frontend-vanilla/src/store.ts @@ -4,6 +4,23 @@ export type StoreEvent = 'feeds-updated' | 'tags-updated' | 'items-updated' | 'a export type FilterType = 'unread' | 'all' | 'starred'; +function getSidebarCookie(): boolean | null { + const match = document.cookie.split('; ').find(row => row.startsWith('neko_sidebar=')); + if (!match) return null; + return match.split('=')[1] === '1'; +} + +function setSidebarCookie(visible: boolean) { + document.cookie = `neko_sidebar=${visible ? '1' : '0'}; path=/; max-age=31536000; SameSite=Lax`; +} + +function getInitialSidebarVisible(): boolean { + const saved = getSidebarCookie(); + if (saved !== null) return saved; + // Default: closed on tablet+mobile (<=1024px), open on desktop + return window.innerWidth > 1024; +} + export class Store extends EventTarget { feeds: Feed[] = []; tags: Category[] = []; @@ -16,7 +33,7 @@ export class Store extends EventTarget { hasMore: boolean = true; theme: string = localStorage.getItem('neko-theme') || 'light'; fontTheme: string = localStorage.getItem('neko-font-theme') || 'default'; - sidebarVisible: boolean = window.innerWidth > 768; + sidebarVisible: boolean = getInitialSidebarVisible(); setFeeds(feeds: Feed[]) { this.feeds = feeds; @@ -86,6 +103,7 @@ export class Store extends EventTarget { setSidebarVisible(visible: boolean) { this.sidebarVisible = visible; + setSidebarCookie(visible); this.emit('sidebar-toggle'); } -- cgit v1.2.3