Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client/pdf): not refreshing when uploading new revision
Elian Doran4134e5054a13
diff --git a/apps/client/src/widgets/type_widgets/File.tsx b/apps/client/src/widgets/type_widgets/File.tsxindex def25cbab3..b720d6a0dc 100644--- a/apps/client/src/widgets/type_widgets/File.tsx+++ b/apps/client/src/widgets/type_widgets/File.tsx@@ -16,7 +16,7 @@ export default function FileTypeWidget({ note, parentComponent }: TypeWidgetPropif (blob?.content) {return <TextPreview content={blob.content} />;} else if (note.mime === "application/pdf") {- return <PdfPreview note={note} componentId={parentComponent?.componentId} />;+ return <PdfPreview blob={blob} note={note} componentId={parentComponent?.componentId} />;} else if (note.mime.startsWith("video/")) {return <VideoPreview note={note} />;} else if (note.mime.startsWith("audio/")) {diff --git a/apps/client/src/widgets/type_widgets/file/Pdf.tsx b/apps/client/src/widgets/type_widgets/file/Pdf.tsxindex 5ffb92d34a..5d2767bb95 100644--- a/apps/client/src/widgets/type_widgets/file/Pdf.tsx+++ b/apps/client/src/widgets/type_widgets/file/Pdf.tsx@@ -1,6 +1,7 @@import { RefObject } from "preact";import { useCallback, useEffect, useRef } from "preact/hooks";+import FBlob from "../../../entities/fblob";import FNote from "../../../entities/fnote";import server from "../../../services/server";import { useViewModeConfig } from "../../collections/NoteList";@@ -12,8 +13,9 @@ const VARIABLE_WHITELIST = new Set(["main-text-color"]);-export default function PdfPreview({ note, componentId }: {+export default function PdfPreview({ note, blob, componentId }: {note: FNote,+ blob: FBlob | null | undefined,componentId: string | undefined;}) {const iframeRef = useRef<HTMLIFrameElement>(null);@@ -36,7 +38,14 @@ export default function PdfPreview({ note, componentId }: {return () => {window.removeEventListener("message", handleMessage);};- }, [ note, historyConfig ]);+ }, [ note, historyConfig, componentId, blob ]);++ // Refresh when blob changes.+ useEffect(() => {+ if (iframeRef.current?.contentWindow) {+ iframeRef.current.contentWindow.location.reload();+ }+ }, [ blob ]);return (historyConfig &&<iframe