mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-24 02:16:41 +02:00
♻️ refactor: create createSimpleNavigationStores and migrate 10 apps
- Add factory for writable navigation stores with optional persistence - Support toolbar collapsed state with withToolbar option - Migrate all 10 navigation stores to use shared factory - Clock saves 32 LOC with built-in localStorage persistence Savings: ~50 LOC (68 LOC removed, factory adds reusable 94 LOC)
This commit is contained in:
parent
c14cd6cac5
commit
bf719f188f
13 changed files with 150 additions and 82 deletions
|
|
@ -1,35 +1,5 @@
|
|||
/**
|
||||
* Navigation Store - Manages navigation state
|
||||
*/
|
||||
import { createSimpleNavigationStores } from '@manacore/shared-stores';
|
||||
|
||||
import { writable } from 'svelte/store';
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
const SIDEBAR_MODE_KEY = 'clock_sidebar_mode';
|
||||
const NAV_COLLAPSED_KEY = 'clock_nav_collapsed';
|
||||
|
||||
// Check localStorage for initial values
|
||||
function getInitialSidebarMode(): boolean {
|
||||
if (!browser) return false;
|
||||
return localStorage.getItem(SIDEBAR_MODE_KEY) === 'true';
|
||||
}
|
||||
|
||||
function getInitialCollapsed(): boolean {
|
||||
if (!browser) return false;
|
||||
return localStorage.getItem(NAV_COLLAPSED_KEY) === 'true';
|
||||
}
|
||||
|
||||
// Create stores
|
||||
export const isSidebarMode = writable(getInitialSidebarMode());
|
||||
export const isNavCollapsed = writable(getInitialCollapsed());
|
||||
|
||||
// Subscribe to persist changes
|
||||
if (browser) {
|
||||
isSidebarMode.subscribe((value) => {
|
||||
localStorage.setItem(SIDEBAR_MODE_KEY, String(value));
|
||||
});
|
||||
|
||||
isNavCollapsed.subscribe((value) => {
|
||||
localStorage.setItem(NAV_COLLAPSED_KEY, String(value));
|
||||
});
|
||||
}
|
||||
export const { isSidebarMode, isNavCollapsed } = createSimpleNavigationStores({
|
||||
storageKey: 'clock',
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue