2026-06-22 22:35:50 +02:00
|
|
|
import { atom } from "jotai";
|
2026-06-22 22:36:06 +02:00
|
|
|
import { rightPanelCollapsedAtom, rightPanelTabAtom } from "@/atoms/layout/right-panel.atom";
|
2026-06-22 22:35:50 +02:00
|
|
|
import type { ChatArtifact } from "../model/artifact";
|
|
|
|
|
|
|
|
|
|
/** Artifacts of the active thread, synced from the message stream by `useSyncChatArtifacts`. */
|
|
|
|
|
export const chatArtifactsAtom = atom<ChatArtifact[]>([]);
|
|
|
|
|
|
|
|
|
|
/** Whether the artifacts sidebar is open in the right panel. */
|
|
|
|
|
export const artifactsPanelOpenAtom = atom(false);
|
2026-06-22 22:36:06 +02:00
|
|
|
|
|
|
|
|
/** 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);
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-06-22 22:36:20 +02:00
|
|
|
|
|
|
|
|
export const toggleArtifactsPanelAtom = atom(null, (get, set) => {
|
|
|
|
|
if (get(artifactsPanelOpenAtom)) set(closeArtifactsPanelAtom);
|
|
|
|
|
else set(openArtifactsPanelAtom);
|
|
|
|
|
});
|