feat: add artifacts open/close actions

This commit is contained in:
CREDO23 2026-06-22 22:36:06 +02:00
parent 71f16c93dd
commit d568905661

View file

@ -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<ChatArtifact[]>([]);
/** 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<boolean | null>(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);
}
});