mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
feat(text-snippets): better reaction to removing templates
This commit is contained in:
parent
3e40a35c19
commit
4f9bd970af
@ -46,28 +46,31 @@ async function handleContentUpdate(affectedNoteIds: string[]) {
|
|||||||
const templateNoteIds = new Set(templateCache.keys());
|
const templateNoteIds = new Set(templateCache.keys());
|
||||||
const affectedTemplateNoteIds = templateNoteIds.intersection(updatedNoteIds);
|
const affectedTemplateNoteIds = templateNoteIds.intersection(updatedNoteIds);
|
||||||
|
|
||||||
console.log("Got ", affectedTemplateNoteIds);
|
|
||||||
|
|
||||||
await froca.getNotes(affectedNoteIds);
|
await froca.getNotes(affectedNoteIds);
|
||||||
|
|
||||||
let fullReloadNeeded = false;
|
let fullReloadNeeded = false;
|
||||||
for (const affectedTemplateNoteId of affectedTemplateNoteIds) {
|
for (const affectedTemplateNoteId of affectedTemplateNoteIds) {
|
||||||
const template = await froca.getNote(affectedTemplateNoteId);
|
try {
|
||||||
if (!template) {
|
const template = await froca.getNote(affectedTemplateNoteId);
|
||||||
console.warn("Unable to obtain template with ID ", affectedTemplateNoteId);
|
if (!template) {
|
||||||
continue;
|
console.warn("Unable to obtain template with ID ", affectedTemplateNoteId);
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const newTitle = template.title;
|
const newTitle = template.title;
|
||||||
if (templateCache.get(affectedTemplateNoteId)?.title !== newTitle) {
|
if (templateCache.get(affectedTemplateNoteId)?.title !== newTitle) {
|
||||||
|
fullReloadNeeded = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
templateCache.set(affectedTemplateNoteId, {
|
||||||
|
title: template.title,
|
||||||
|
content: await template.getContent()
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// If a note was not found while updating the cache, it means we need to do a full reload.
|
||||||
fullReloadNeeded = true;
|
fullReloadNeeded = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
templateCache.set(affectedTemplateNoteId, {
|
|
||||||
title: template.title,
|
|
||||||
content: await template.getContent()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fullReloadNeeded) {
|
if (fullReloadNeeded) {
|
||||||
@ -77,14 +80,15 @@ async function handleContentUpdate(affectedNoteIds: string[]) {
|
|||||||
|
|
||||||
export function updateTemplateCache(loadResults: LoadResults): boolean {
|
export function updateTemplateCache(loadResults: LoadResults): boolean {
|
||||||
const affectedNoteIds = loadResults.getNoteIds();
|
const affectedNoteIds = loadResults.getNoteIds();
|
||||||
if (affectedNoteIds.length > 0) {
|
|
||||||
debouncedHandleContentUpdate(affectedNoteIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// React to creation or deletion of text snippets.
|
||||||
if (loadResults.getAttributeRows().find((attr) =>
|
if (loadResults.getAttributeRows().find((attr) =>
|
||||||
attr.type === "label" &&
|
attr.type === "label" &&
|
||||||
attr.name === "textSnippet")) {
|
attr.name === "textSnippet")) {
|
||||||
handleFullReload();
|
handleFullReload();
|
||||||
|
} else if (affectedNoteIds.length > 0) {
|
||||||
|
// Update content and titles if one of the template notes were updated.
|
||||||
|
debouncedHandleContentUpdate(affectedNoteIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user