fix: wait for a pending note save before navigating away (#29745)

This commit is contained in:
G30 2026-09-07 11:26:45 -04:00 committed by GitHub
parent 57acc2b68f
commit 3aabbfebfe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,7 +10,7 @@
import { toast } from 'svelte-sonner';
import equal from 'fast-deep-equal';
import { goto } from '$app/navigation';
import { goto, onNavigate } from '$app/navigation';
import dayjs from '$lib/dayjs';
import calendar from 'dayjs/plugin/calendar';
@ -205,28 +205,47 @@
let debounceTimeout: NodeJS.Timeout | null = null;
const saveHandler = async () => {
const res = await updateNoteById(localStorage.token, id, {
title: note?.title === '' ? $i18n.t('Untitled') : note.title,
data: {
files: files
},
access_grants: note?.access_grants ?? []
}).catch((e) => {
toast.error(`${e}`);
});
if (res) {
pinnedNotes.set(await getPinnedNoteList(localStorage.token).catch(() => []));
}
};
const changeDebounceHandler = () => {
if (debounceTimeout) {
clearTimeout(debounceTimeout);
}
debounceTimeout = setTimeout(async () => {
const res = await updateNoteById(localStorage.token, id, {
title: note?.title === '' ? $i18n.t('Untitled') : note.title,
data: {
files: files
},
access_grants: note?.access_grants ?? []
}).catch((e) => {
toast.error(`${e}`);
});
if (res) {
pinnedNotes.set(await getPinnedNoteList(localStorage.token).catch(() => []));
}
debounceTimeout = setTimeout(() => {
debounceTimeout = null;
saveHandler();
}, 200);
};
onNavigate(() => {
if (titleInputFocused) {
changeDebounceHandler();
}
if (!debounceTimeout) {
return;
}
clearTimeout(debounceTimeout);
debounceTimeout = null;
return saveHandler();
});
const applyExternalNoteContent = async (_note) => {
const incomingContent = _note.data?.content;
const contentLength = incomingContent?.md?.length ?? incomingContent?.html?.length ?? 0;