feat: implement session storage for tabs state management and optimize tab reset logic on search space change

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-03-27 02:08:36 -07:00
parent f263cf91a7
commit e47c786e40
2 changed files with 18 additions and 3 deletions

View file

@ -1,4 +1,5 @@
import { atom } from "jotai";
import { atomWithStorage, createJSONStorage } from "jotai/utils";
export type TabType = "chat" | "document";
@ -32,7 +33,16 @@ const initialState: TabsState = {
activeTabId: "chat-new",
};
export const tabsStateAtom = atom<TabsState>(initialState);
const sessionStorageAdapter = createJSONStorage<TabsState>(
() => (typeof window !== "undefined" ? sessionStorage : undefined) as Storage
);
export const tabsStateAtom = atomWithStorage<TabsState>(
"surfsense:tabs",
initialState,
sessionStorageAdapter,
{ getOnInit: true },
);
export const tabsAtom = atom((get) => get(tabsStateAtom).tabs);
export const activeTabIdAtom = atom((get) => get(tabsStateAtom).activeTabId);