Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/type_widget): react to note revisions

Elian Doran77e7c414b62b
diff --git a/apps/client/src/widgets/type_widgets/Image.tsx b/apps/client/src/widgets/type_widgets/Image.tsx
index 956a461bdc..8381127fb7 100644
--- a/apps/client/src/widgets/type_widgets/Image.tsx
+++ b/apps/client/src/widgets/type_widgets/Image.tsx
@@ -1,6 +1,6 @@
import { useEffect, useRef, useState } from "preact/hooks";
import { createImageSrcUrl } from "../../services/utils";
-import { useTriliumEvent, useUniqueName } from "../react/hooks";
+import { useNoteBlob, useTriliumEvent, useUniqueName } from "../react/hooks";
import "./Image.css";
import { TypeWidgetProps } from "./type_widget";
import WheelZoom from 'vanilla-js-wheel-zoom';
@@ -11,6 +11,7 @@ import { copyImageReferenceToClipboard } from "../../services/image";
export default function Image({ note, ntxId }: TypeWidgetProps) {
const uniqueId = useUniqueName("image");
const containerRef = useRef<HTMLDivElement>(null);
+ const [ refreshCounter, setRefreshCounter ] = useState(0);
// Set up pan & zoom
useEffect(() => {
@@ -32,6 +33,13 @@ export default function Image({ note, ntxId }: TypeWidgetProps) {
copyImageReferenceToClipboard(refToJQuerySelector(containerRef));
});
+ // React to new revisions.
+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
+ if (loadResults.isNoteReloaded(note.noteId)) {
+ setRefreshCounter(refreshCounter + 1);
+ }
+ });
+
return (
<div className="note-detail-image note-detail-printable">
<div ref={containerRef} className="note-detail-image-wrapper">
diff --git a/apps/client/src/widgets/type_widgets_old/image.ts b/apps/client/src/widgets/type_widgets_old/image.ts
deleted file mode 100644
index f5e337b7b5..0000000000
--- a/apps/client/src/widgets/type_widgets_old/image.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import utils from "../../services/utils.js";
-import TypeWidget from "./type_widget.js";
-import imageContextMenuService from "../../menus/image_context_menu.js";
-import imageService from "../../services/image.js";
-import type FNote from "../../entities/fnote.js";
-import type { EventData } from "../../components/app_context.js";
-
-class ImageTypeWidget extends TypeWidget {
-
- private $imageWrapper!: JQuery<HTMLElement>;
- private $imageView!: JQuery<HTMLElement>;
-
- static getType() {
- return "image";
- }
-
- copyImageReferenceToClipboardEvent({ ntxId }: EventData<"copyImageReferenceToClipboard">) {
- }
-
- async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
- if (loadResults.isNoteReloaded(this.noteId)) {
- this.refresh();
- }
- }
-}
-
-export default ImageTypeWidget;