mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-27 19:25:15 +02:00
feat: implement unsaved changes handling in editor and sidebar
- Introduced global state management for unsaved changes and pending navigation using Jotai atoms. - Updated the editor component to sync local unsaved changes with global state and handle navigation prompts. - Enhanced sidebar functionality to check for unsaved changes before navigating to a new note. - Added cleanup logic for global state on component unmount to prevent stale data.
This commit is contained in:
parent
ee46a43afc
commit
b53b19170e
4 changed files with 108 additions and 7 deletions
27
surfsense_web/atoms/editor/ui.atoms.ts
Normal file
27
surfsense_web/atoms/editor/ui.atoms.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { atom } from "jotai";
|
||||
|
||||
interface EditorUIState {
|
||||
hasUnsavedChanges: boolean;
|
||||
pendingNavigation: string | null; // URL to navigate to after user confirms
|
||||
}
|
||||
|
||||
export const editorUIAtom = atom<EditorUIState>({
|
||||
hasUnsavedChanges: false,
|
||||
pendingNavigation: null,
|
||||
});
|
||||
|
||||
// Derived atom for just the unsaved changes state
|
||||
export const hasUnsavedEditorChangesAtom = atom(
|
||||
(get) => get(editorUIAtom).hasUnsavedChanges,
|
||||
(get, set, value: boolean) => {
|
||||
set(editorUIAtom, { ...get(editorUIAtom), hasUnsavedChanges: value });
|
||||
}
|
||||
);
|
||||
|
||||
// Derived atom for pending navigation
|
||||
export const pendingEditorNavigationAtom = atom(
|
||||
(get) => get(editorUIAtom).pendingNavigation,
|
||||
(get, set, value: string | null) => {
|
||||
set(editorUIAtom, { ...get(editorUIAtom), pendingNavigation: value });
|
||||
}
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue