chore(react/type_widget): react to note revisions

This commit is contained in:
Elian Doran 2025-09-19 22:45:03 +03:00
parent 3a68395ca7
commit 77e7c414b6
No known key found for this signature in database
2 changed files with 9 additions and 28 deletions

View File

@ -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">

View File

@ -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;