mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 17:08:58 +01:00
chore(react/type_widget): react to note revisions
This commit is contained in:
parent
3a68395ca7
commit
77e7c414b6
@ -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">
|
||||
|
||||
@ -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;
|
||||
Loading…
x
Reference in New Issue
Block a user