fix(client/pdf): not refreshing when uploading new revision

This commit is contained in:
Elian Doran 2025-12-29 17:02:22 +02:00
parent bb374a5ce2
commit 4134e5054a
No known key found for this signature in database
2 changed files with 12 additions and 3 deletions

View File

@ -16,7 +16,7 @@ export default function FileTypeWidget({ note, parentComponent }: TypeWidgetProp
if (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/")) {

View File

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