Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/type_widgets): finalize porting

Elian Dorane2ef58ed50a1
diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
index 39b3249926..adb3536bc5 100644
--- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx
+++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
@@ -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;
diff --git a/apps/client/src/widgets/type_widgets/text/snippets.ts b/apps/client/src/widgets/type_widgets/text/snippets.ts
index 22766eba2e..4a1479c3d3 100644
--- a/apps/client/src/widgets/type_widgets/text/snippets.ts
+++ b/apps/client/src/widgets/type_widgets/text/snippets.ts
@@ -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;
}
diff --git a/apps/client/src/widgets/type_widgets_old/editable_text.ts b/apps/client/src/widgets/type_widgets_old/editable_text.ts
deleted file mode 100644
index 9e8890d08e..0000000000
--- a/apps/client/src/widgets/type_widgets_old/editable_text.ts
+++ /dev/null
@@ -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();
- }
-
-
-}