Files
openchamber/packages/ui/src/stores/useSessionDisplayStore.ts
T

45 lines
1.6 KiB
TypeScript
Raw Normal View History

import { create } from 'zustand';
import { persist } from 'zustand/middleware';
export type SessionDisplayMode = 'default' | 'minimal';
type SessionDisplayStore = {
displayMode: SessionDisplayMode;
2026-05-03 16:32:14 +03:00
showRecentSection: boolean;
showArchivedSessions: boolean;
setDisplayMode: (mode: SessionDisplayMode) => void;
2026-05-03 16:32:14 +03:00
setShowRecentSection: (show: boolean) => void;
setShowArchivedSessions: (show: boolean) => void;
2026-05-03 16:32:14 +03:00
toggleRecentSection: () => void;
toggleArchivedSessions: () => void;
};
export const useSessionDisplayStore = create<SessionDisplayStore>()(
persist(
(set) => ({
2026-06-12 12:38:31 +03:00
displayMode: 'minimal',
2026-05-03 16:32:14 +03:00
showRecentSection: true,
showArchivedSessions: true,
setDisplayMode: (mode) => set({ displayMode: mode }),
2026-05-03 16:32:14 +03:00
setShowRecentSection: (show) => set({ showRecentSection: show }),
setShowArchivedSessions: (show) => set({ showArchivedSessions: show }),
2026-05-03 16:32:14 +03:00
toggleRecentSection: () => set((state) => ({ showRecentSection: !state.showRecentSection })),
toggleArchivedSessions: () => set((state) => ({ showArchivedSessions: !state.showArchivedSessions })),
}),
{
name: 'session-display-mode',
2026-06-12 12:38:31 +03:00
version: 1,
// v0 shipped 'default' as the only/initial mode, so most existing users
// have it persisted by accident rather than choice. Nudge everyone onto
// minimal once so the mode can be evaluated before removing it entirely.
migrate: (persisted, version) => {
const state = (persisted ?? {}) as Partial<SessionDisplayStore>;
if (version < 1) {
return { ...state, displayMode: 'minimal' };
}
return state;
},
},
),
);