0.1.14 上线前更改
This commit is contained in:
@@ -5,11 +5,14 @@ import type { SidebarSectionId } from "@/components/sidebar/types";
|
||||
interface SidebarState {
|
||||
open: boolean;
|
||||
width: number;
|
||||
sectionsTrayOpen: boolean;
|
||||
collapsedSections: Record<SidebarSectionId, boolean>;
|
||||
trashConfirm: boolean;
|
||||
viewMode: "section" | "filesystem";
|
||||
setOpen: (open: boolean) => void;
|
||||
setWidth: (width: number) => void;
|
||||
setSectionsTrayOpen: (open: boolean) => void;
|
||||
toggleSectionsTray: () => void;
|
||||
toggleSection: (section: SidebarSectionId) => void;
|
||||
setSectionCollapsed: (section: SidebarSectionId, collapsed: boolean) => void;
|
||||
setTrashConfirm: (value: boolean) => void;
|
||||
@@ -30,11 +33,14 @@ export const useSidebarStore = create<SidebarState>()(
|
||||
(set) => ({
|
||||
open: false,
|
||||
width: 280,
|
||||
sectionsTrayOpen: false,
|
||||
collapsedSections: { ...sectionDefaults },
|
||||
trashConfirm: true,
|
||||
viewMode: "section",
|
||||
setOpen: (open) => set({ open }),
|
||||
setWidth: (width) => set({ width }),
|
||||
setSectionsTrayOpen: (open) => set({ sectionsTrayOpen: open }),
|
||||
toggleSectionsTray: () => set((state) => ({ sectionsTrayOpen: !state.sectionsTrayOpen })),
|
||||
toggleSection: (section) =>
|
||||
set((state) => ({
|
||||
collapsedSections: {
|
||||
@@ -55,8 +61,39 @@ export const useSidebarStore = create<SidebarState>()(
|
||||
}),
|
||||
{
|
||||
name: "sidebar-ui",
|
||||
version: 2,
|
||||
migrate: (persistedState, version) => {
|
||||
const state = persistedState as
|
||||
| Partial<
|
||||
Pick<
|
||||
SidebarState,
|
||||
"width" | "collapsedSections" | "trashConfirm" | "viewMode" | "sectionsTrayOpen"
|
||||
>
|
||||
>
|
||||
| undefined;
|
||||
if (!state) return state;
|
||||
if (version >= 2) return state;
|
||||
|
||||
const nextCollapsedSections = {
|
||||
...sectionDefaults,
|
||||
...(state.collapsedSections ?? {}),
|
||||
};
|
||||
|
||||
// 迁移到「分区入口可折叠」后,让分区默认展开,折叠由入口开关控制。
|
||||
nextCollapsedSections.starred = false;
|
||||
nextCollapsedSections.public = false;
|
||||
nextCollapsedSections.shared = false;
|
||||
nextCollapsedSections.templates = false;
|
||||
|
||||
return {
|
||||
...state,
|
||||
sectionsTrayOpen: false,
|
||||
collapsedSections: nextCollapsedSections,
|
||||
};
|
||||
},
|
||||
partialize: (state) => ({
|
||||
width: state.width,
|
||||
sectionsTrayOpen: state.sectionsTrayOpen,
|
||||
collapsedSections: state.collapsedSections,
|
||||
trashConfirm: state.trashConfirm,
|
||||
viewMode: state.viewMode,
|
||||
|
||||
Reference in New Issue
Block a user