chore(react/type_widgets): finalize porting

This commit is contained in:
Elian Doran 2025-09-25 18:26:52 +03:00
parent 7af610a5b4
commit e2ef58ed50
No known key found for this signature in database
3 changed files with 6 additions and 67 deletions

View File

@ -241,12 +241,7 @@ function useTemplates() {
}, []);
useTriliumEvent("entitiesReloaded", async ({ loadResults }) => {
console.log("Reloaded ", loadResults);
const newTemplates = await updateTemplateCache(loadResults);
if (newTemplates) {
console.log("Got new templates!", newTemplates);
setTemplates(newTemplates);
}
await updateTemplateCache(loadResults, setTemplates);
});
return templates;

View File

@ -57,12 +57,7 @@ function buildIcon(snippet: FNote) {
</svg>`
}
function handleFullReload() {
console.warn("Full text editor reload needed");
appContext.triggerCommand("reloadTextEditor");
}
async function handleContentUpdate(affectedNoteIds: string[]) {
async function handleContentUpdate(affectedNoteIds: string[], setTemplates: (value: TemplateDefinition[]) => void) {
const updatedNoteIds = new Set(affectedNoteIds);
const templateNoteIds = new Set(templateCache.keys());
const affectedTemplateNoteIds = templateNoteIds.intersection(updatedNoteIds);
@ -92,11 +87,11 @@ async function handleContentUpdate(affectedNoteIds: string[]) {
}
if (fullReloadNeeded) {
handleFullReload();
setTemplates(await getTemplates());
}
}
export async function updateTemplateCache(loadResults: LoadResults): Promise<TemplateDefinition[] | null> {
export async function updateTemplateCache(loadResults: LoadResults, setTemplates: (value: TemplateDefinition[]) => void) {
const affectedNoteIds = loadResults.getNoteIds();
// React to creation or deletion of text snippets.
@ -107,11 +102,9 @@ export async function updateTemplateCache(loadResults: LoadResults): Promise<Tem
return (attr.value === "_template_text_snippet");
}
})) {
return await getTemplates();
setTemplates(await getTemplates());
} else if (affectedNoteIds.length > 0) {
// Update content and titles if one of the template notes were updated.
debouncedHandleContentUpdate(affectedNoteIds);
debouncedHandleContentUpdate(affectedNoteIds, setTemplates);
}
return null;
}

View File

@ -1,49 +0,0 @@
import utils, { hasTouchBar } from "../../services/utils.js";
import keyboardActionService from "../../services/keyboard_actions.js";
import froca from "../../services/froca.js";
import noteCreateService from "../../services/note_create.js";
import AbstractTextTypeWidget from "./abstract_text_type_widget.js";
import link from "../../services/link.js";
import appContext, { type CommandListenerData, type EventData } from "../../components/app_context.js";
import dialogService from "../../services/dialog.js";
import options from "../../services/options.js";
import toast from "../../services/toast.js";
import { buildSelectedBackgroundColor } from "../../components/touch_bar.js";
import { buildConfig, BuildEditorOptions, OPEN_SOURCE_LICENSE_KEY } from "./ckeditor/config.js";
import type FNote from "../../entities/fnote.js";
import { PopupEditor, ClassicEditor, EditorWatchdog, type CKTextEditor, type MentionFeed, type WatchdogConfig, EditorConfig } from "@triliumnext/ckeditor5";
export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
private contentLanguage?: string | null;
private watchdog!: EditorWatchdog<ClassicEditor | PopupEditor>;
private $editor!: JQuery<HTMLElement>;
doRender() {
this.$widget = $(TPL);
this.$editor = this.$widget.find(".note-detail-editable-text-editor");
this.initialized = this.initEditor();
this.setupImageOpening(false);
super.doRender();
}
getEditor() {
return this.watchdog?.editor;
}
async reinitialize() {
const data = this.watchdog.editor?.getData();
await this.reinitializeWithData(data ?? "");
}
async reloadTextEditorEvent() {
await this.reinitialize();
}
}