Debounce loadNote() calls

This commit is contained in:
Abdo 2025-07-27 18:43:32 +03:00
parent 986ca6e252
commit 958599ed09

View file

@ -89,7 +89,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import RichTextInput, { editingInputIsRichText } from "./rich-text-input"; import RichTextInput, { editingInputIsRichText } from "./rich-text-input";
import RichTextBadge from "./RichTextBadge.svelte"; import RichTextBadge from "./RichTextBadge.svelte";
import type { HistoryEntry, NotetypeIdAndModTime, SessionOptions } from "./types"; import type { HistoryEntry, NotetypeIdAndModTime, SessionOptions } from "./types";
import { CooldownTimer } from "$lib/editable/cooldown-timer";
const loadDebouncer = new CooldownTimer(200);
let contextMenu: ContextMenu; let contextMenu: ContextMenu;
const [onContextMenu, contextMenuItems] = setupContextMenu(); const [onContextMenu, contextMenuItems] = setupContextMenu();
let contextMenuInput: EditingInputAPI | null = null; let contextMenuInput: EditingInputAPI | null = null;
@ -897,12 +899,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}); });
} }
async function loadNote( async function loadNoteInner(
nid: bigint | null, nid: bigint | null,
notetypeId: bigint, notetypeId: bigint,
focusTo: number, focusTo: number,
originalNoteId: bigint | null, originalNoteId: bigint | null,
): Promise<bigint> { ) {
const notetype = await getNotetype({ const notetype = await getNotetype({
ntid: notetypeId, ntid: notetypeId,
}); });
@ -1003,8 +1005,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
await updateDuplicateDisplay(); await updateDuplicateDisplay();
triggerChanges(); triggerChanges();
}
return note!.id; async function loadNote(
nid: bigint | null,
notetypeId: bigint,
focusTo: number,
originalNoteId: bigint | null,
) {
loadDebouncer.schedule(async () => {
await loadNoteInner(nid, notetypeId, focusTo, originalNoteId);
});
} }
async function reloadNote() { async function reloadNote() {