diff --git a/surfsense_web/features/chat-artifacts/state/artifacts-panel.atom.ts b/surfsense_web/features/chat-artifacts/state/artifacts-panel.atom.ts index c29a24845..2ed0f7479 100644 --- a/surfsense_web/features/chat-artifacts/state/artifacts-panel.atom.ts +++ b/surfsense_web/features/chat-artifacts/state/artifacts-panel.atom.ts @@ -1,4 +1,5 @@ import { atom } from "jotai"; +import { rightPanelCollapsedAtom, rightPanelTabAtom } from "@/atoms/layout/right-panel.atom"; import type { ChatArtifact } from "../model/artifact"; /** Artifacts of the active thread, synced from the message stream by `useSyncChatArtifacts`. */ @@ -6,3 +7,25 @@ export const chatArtifactsAtom = atom([]); /** Whether the artifacts sidebar is open in the right panel. */ export const artifactsPanelOpenAtom = atom(false); + +/** Snapshot of `rightPanelCollapsedAtom` taken before the panel opens, restored on close. */ +const preArtifactsCollapsedAtom = atom(null); + +export const openArtifactsPanelAtom = atom(null, (get, set) => { + if (!get(artifactsPanelOpenAtom)) { + set(preArtifactsCollapsedAtom, get(rightPanelCollapsedAtom)); + } + set(artifactsPanelOpenAtom, true); + set(rightPanelTabAtom, "artifacts"); + set(rightPanelCollapsedAtom, false); +}); + +export const closeArtifactsPanelAtom = atom(null, (get, set) => { + set(artifactsPanelOpenAtom, false); + set(rightPanelTabAtom, "sources"); + const prev = get(preArtifactsCollapsedAtom); + if (prev !== null) { + set(rightPanelCollapsedAtom, prev); + set(preArtifactsCollapsedAtom, null); + } +});