mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-12 23:02:35 +00:00
fix: wait for a pending note save before navigating away (#29745)
This commit is contained in:
parent
57acc2b68f
commit
3aabbfebfe
1 changed files with 34 additions and 15 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue