mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 16:56:22 +02:00
- Added editor panel state management using Jotai atoms. - Integrated editor panel into the right panel and documents sidebar. - Updated DocumentsTableShell to open the editor panel on edit action. - Enhanced NewChatPage to close the editor panel when navigating away. - Improved context menu actions for document editing and deletion.
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { atom } from "jotai";
|
|
import { rightPanelCollapsedAtom, rightPanelTabAtom } from "@/atoms/layout/right-panel.atom";
|
|
|
|
interface EditorPanelState {
|
|
isOpen: boolean;
|
|
documentId: number | null;
|
|
searchSpaceId: number | null;
|
|
title: string | null;
|
|
}
|
|
|
|
const initialState: EditorPanelState = {
|
|
isOpen: false,
|
|
documentId: null,
|
|
searchSpaceId: null,
|
|
title: null,
|
|
};
|
|
|
|
export const editorPanelAtom = atom<EditorPanelState>(initialState);
|
|
|
|
export const editorPanelOpenAtom = atom((get) => get(editorPanelAtom).isOpen);
|
|
|
|
const preEditorCollapsedAtom = atom<boolean | null>(null);
|
|
|
|
export const openEditorPanelAtom = atom(
|
|
null,
|
|
(
|
|
get,
|
|
set,
|
|
{
|
|
documentId,
|
|
searchSpaceId,
|
|
title,
|
|
}: { documentId: number; searchSpaceId: number; title?: string }
|
|
) => {
|
|
if (!get(editorPanelAtom).isOpen) {
|
|
set(preEditorCollapsedAtom, get(rightPanelCollapsedAtom));
|
|
}
|
|
set(editorPanelAtom, {
|
|
isOpen: true,
|
|
documentId,
|
|
searchSpaceId,
|
|
title: title ?? null,
|
|
});
|
|
set(rightPanelTabAtom, "editor");
|
|
set(rightPanelCollapsedAtom, false);
|
|
}
|
|
);
|
|
|
|
export const closeEditorPanelAtom = atom(null, (get, set) => {
|
|
set(editorPanelAtom, initialState);
|
|
set(rightPanelTabAtom, "sources");
|
|
const prev = get(preEditorCollapsedAtom);
|
|
if (prev !== null) {
|
|
set(rightPanelCollapsedAtom, prev);
|
|
set(preEditorCollapsedAtom, null);
|
|
}
|
|
});
|