mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-25 19:15:18 +02:00
Merge pull request #994 from MODSetter/dev_mod
feat: implement session storage for tabs state management and optimiz…
This commit is contained in:
commit
52487c4acd
2 changed files with 18 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import { atom } from "jotai";
|
import { atom } from "jotai";
|
||||||
|
import { atomWithStorage, createJSONStorage } from "jotai/utils";
|
||||||
|
|
||||||
export type TabType = "chat" | "document";
|
export type TabType = "chat" | "document";
|
||||||
|
|
||||||
|
|
@ -32,7 +33,16 @@ const initialState: TabsState = {
|
||||||
activeTabId: "chat-new",
|
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 tabsAtom = atom((get) => get(tabsStateAtom).tabs);
|
||||||
export const activeTabIdAtom = atom((get) => get(tabsStateAtom).activeTabId);
|
export const activeTabIdAtom = atom((get) => get(tabsStateAtom).activeTabId);
|
||||||
|
|
|
||||||
|
|
@ -268,9 +268,14 @@ export function LayoutDataProvider({ searchSpaceId, children }: LayoutDataProvid
|
||||||
}, [pendingNewChat, params?.chat_id, router, searchSpaceId, resetCurrentThread]);
|
}, [pendingNewChat, params?.chat_id, router, searchSpaceId, resetCurrentThread]);
|
||||||
|
|
||||||
// Reset transient slide-out panels and tabs when switching search spaces.
|
// Reset transient slide-out panels and tabs when switching search spaces.
|
||||||
|
// Use a ref to skip the initial mount — only reset when the space actually changes.
|
||||||
|
const prevSearchSpaceIdRef = useRef(searchSpaceId);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setActiveSlideoutPanel(null);
|
if (prevSearchSpaceIdRef.current !== searchSpaceId) {
|
||||||
resetTabs();
|
prevSearchSpaceIdRef.current = searchSpaceId;
|
||||||
|
setActiveSlideoutPanel(null);
|
||||||
|
resetTabs();
|
||||||
|
}
|
||||||
}, [searchSpaceId, resetTabs]);
|
}, [searchSpaceId, resetTabs]);
|
||||||
|
|
||||||
const searchSpaces: SearchSpace[] = useMemo(() => {
|
const searchSpaces: SearchSpace[] = useMemo(() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue