Prevent note switching when there are unsaved changes
- Added hasUnsavedChanges state tracking in App.tsx - NoteEditor now notifies parent via onUnsavedChanges callback - NotesList receives hasUnsavedChanges prop - Clicking on other notes is prevented when current note has unsaved changes - Visual feedback: other notes become semi-transparent with cursor-not-allowed - Tooltip shows 'Save current note before switching' on disabled notes - Much simpler and more reliable than trying to auto-save on switch
This commit is contained in:
@@ -11,6 +11,7 @@ interface NoteEditorProps {
|
||||
note: Note | null;
|
||||
onUpdateNote: (note: Note) => void;
|
||||
fontSize: number;
|
||||
onUnsavedChanges?: (hasChanges: boolean) => void;
|
||||
}
|
||||
|
||||
const turndownService = new TurndownService({
|
||||
@@ -18,7 +19,7 @@ const turndownService = new TurndownService({
|
||||
codeBlockStyle: 'fenced',
|
||||
});
|
||||
|
||||
export function NoteEditor({ note, onUpdateNote, fontSize }: NoteEditorProps) {
|
||||
export function NoteEditor({ note, onUpdateNote, fontSize, onUnsavedChanges }: NoteEditorProps) {
|
||||
const [localTitle, setLocalTitle] = useState('');
|
||||
const [localFavorite, setLocalFavorite] = useState(false);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
@@ -26,6 +27,11 @@ export function NoteEditor({ note, onUpdateNote, fontSize }: NoteEditorProps) {
|
||||
const [titleManuallyEdited, setTitleManuallyEdited] = useState(false);
|
||||
const previousNoteIdRef = useRef<number | null>(null);
|
||||
|
||||
// Notify parent component when unsaved changes state changes
|
||||
useEffect(() => {
|
||||
onUnsavedChanges?.(hasUnsavedChanges);
|
||||
}, [hasUnsavedChanges, onUnsavedChanges]);
|
||||
|
||||
const editor = useEditor({
|
||||
extensions: [
|
||||
StarterKit,
|
||||
|
||||
Reference in New Issue
Block a user