diff --git a/apps/client/src/widgets/type_widgets/file/Pdf.tsx b/apps/client/src/widgets/type_widgets/file/Pdf.tsx index 1146ad60f..bb18d44f8 100644 --- a/apps/client/src/widgets/type_widgets/file/Pdf.tsx +++ b/apps/client/src/widgets/type_widgets/file/Pdf.tsx @@ -3,6 +3,7 @@ import { useCallback, useEffect, useRef } from "preact/hooks"; import FNote from "../../../entities/fnote"; import server from "../../../services/server"; +import { useViewModeConfig } from "../../collections/NoteList"; const VARIABLE_WHITELIST = new Set([ "root-background", @@ -14,6 +15,7 @@ const VARIABLE_WHITELIST = new Set([ export default function PdfPreview({ note }: { note: FNote }) { const iframeRef = useRef(null); const { onLoad } = useStyleInjection(iframeRef); + const historyConfig = useViewModeConfig(note, "pdfHistory"); useEffect(() => { function handleMessage(event: MessageEvent) { @@ -21,20 +23,29 @@ export default function PdfPreview({ note }: { note: FNote }) { const blob = new Blob([event.data.data], { type: note.mime }); server.upload(`notes/${note.noteId}/file`, new File([blob], note.title, { type: note.mime })); } + + if (event.data.type === "pdfjs-viewer-save-view-history" && event.data?.data) { + historyConfig?.storeFn(JSON.parse(event.data.data)); + } } window.addEventListener("message", handleMessage); return () => { window.removeEventListener("message", handleMessage); }; - }, [ note ]); + }, [ note, historyConfig ]); - return ( + return (historyConfig &&