diff options
Diffstat (limited to 'src/stores/useLayoutStore.ts')
| -rw-r--r-- | src/stores/useLayoutStore.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/stores/useLayoutStore.ts b/src/stores/useLayoutStore.ts new file mode 100644 index 0000000..adcdae7 --- /dev/null +++ b/src/stores/useLayoutStore.ts @@ -0,0 +1,51 @@ +import { create } from 'zustand' + +export type ActivityView = 'explorer' | 'search' | 'extensions' | 'settings' + +interface LayoutState { + activeView: ActivityView | null + sidePanelVisible: boolean + sidePanelWidth: number + setActiveView: (view: ActivityView | null) => void + toggleSidePanel: () => void + showSidePanel: () => void + hideSidePanel: () => void + setSidePanelWidth: (width: number) => void +} + +const SIDEPANEL_MIN = 180 +const SIDEPANEL_MAX = 500 +const SIDEPANEL_DEFAULT = 240 + +export const useLayoutStore = create<LayoutState>((set, get) => ({ + activeView: 'explorer', + sidePanelVisible: true, + sidePanelWidth: SIDEPANEL_DEFAULT, + + setActiveView: (view: ActivityView | null) => { + const { activeView, hideSidePanel, showSidePanel } = get() + if (activeView === view) { + hideSidePanel() + set({ activeView: null }) + } else { + set({ activeView: view }) + showSidePanel() + } + }, + + toggleSidePanel: () => { + set((s) => ({ sidePanelVisible: !s.sidePanelVisible })) + }, + + showSidePanel: () => { + set({ sidePanelVisible: true }) + }, + + hideSidePanel: () => { + set({ sidePanelVisible: false }) + }, + + setSidePanelWidth: (width: number) => { + set({ sidePanelWidth: Math.max(SIDEPANEL_MIN, Math.min(SIDEPANEL_MAX, width)) }) + }, +})) |