fix(pdfjs): preferences don't account for ntxId or noteId

This commit is contained in:
Elian Doran 2026-01-02 18:08:25 +02:00
parent 120bb09171
commit 44d1d01105
No known key found for this signature in database
3 changed files with 13 additions and 6 deletions

View File

@ -38,14 +38,17 @@ interface PdfOutlineItem {
items: PdfOutlineItem[];
}
interface PdfDocumentModifiedMessage {
type: "pdfjs-viewer-document-modified";
data: Uint8Array<ArrayBufferLike>;
interface WithContext {
ntxId: string;
noteId: string | null | undefined;
}
interface PdfSaveViewHistoryMessage {
interface PdfDocumentModifiedMessage extends WithContext {
type: "pdfjs-viewer-document-modified";
data: Uint8Array<ArrayBufferLike>;
}
interface PdfSaveViewHistoryMessage extends WithContext {
type: "pdfjs-viewer-save-view-history";
data: string;
}

View File

@ -38,7 +38,9 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
}
if (event.data.type === "pdfjs-viewer-save-view-history" && event.data?.data) {
historyConfig?.storeFn(JSON.parse(event.data.data));
if (event.data.noteId === note.noteId && event.data.ntxId === noteContext.ntxId) {
historyConfig?.storeFn(JSON.parse(event.data.data));
}
}
if (event.data.type === "pdfjs-viewer-toc") {

View File

@ -41,7 +41,9 @@ function saveHistory(value: string) {
window.parent.postMessage({
type: "pdfjs-viewer-save-view-history",
data: JSON.stringify(history)
data: JSON.stringify(history),
ntxId: window.TRILIUM_NTX_ID,
noteId: window.TRILIUM_NOTE_ID
} satisfies PdfSaveViewHistoryMessage, window.location.origin);
saveTimeout = null;
}, 2_000);