mirror of
https://github.com/zadam/trilium.git
synced 2025-12-29 18:54:29 +01:00
refactor(client/pdf): split into own component
This commit is contained in:
parent
7c4a56f5f2
commit
f09a3e06f4
@ -1,13 +1,11 @@
|
||||
import "./File.css";
|
||||
|
||||
import { useEffect } from "preact/hooks";
|
||||
|
||||
import FNote from "../../entities/fnote";
|
||||
import { t } from "../../services/i18n";
|
||||
import { getUrlForDownload } from "../../services/open";
|
||||
import server from "../../services/server";
|
||||
import Alert from "../react/Alert";
|
||||
import { useNoteBlob } from "../react/hooks";
|
||||
import PdfPreview from "./file/Pdf";
|
||||
import { TypeWidgetProps } from "./type_widget";
|
||||
|
||||
const TEXT_MAX_NUM_CHARS = 5000;
|
||||
@ -44,28 +42,6 @@ function TextPreview({ content }: { content: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
function PdfPreview({ note }: { note: FNote }) {
|
||||
useEffect(() => {
|
||||
function handleMessage(event: MessageEvent) {
|
||||
if (event.data?.type === "pdfjs-viewer-document-modified" && event.data?.data) {
|
||||
const blob = new Blob([event.data.data], { type: note.mime });
|
||||
server.upload(`notes/${note.noteId}/file`, new File([blob], note.title, { type: note.mime }));
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("message", handleMessage);
|
||||
return () => {
|
||||
window.removeEventListener("message", handleMessage);
|
||||
};
|
||||
}, [ note ]);
|
||||
|
||||
return (
|
||||
<iframe
|
||||
class="pdf-preview"
|
||||
src={`pdfjs/web/viewer.html?file=../../api/notes/${note.noteId}/open`} />
|
||||
);
|
||||
}
|
||||
|
||||
function VideoPreview({ note }: { note: FNote }) {
|
||||
return (
|
||||
<video
|
||||
|
||||
26
apps/client/src/widgets/type_widgets/file/Pdf.tsx
Normal file
26
apps/client/src/widgets/type_widgets/file/Pdf.tsx
Normal file
@ -0,0 +1,26 @@
|
||||
import { useEffect } from "preact/hooks";
|
||||
|
||||
import FNote from "../../../entities/fnote";
|
||||
import server from "../../../services/server";
|
||||
|
||||
export default function PdfPreview({ note }: { note: FNote }) {
|
||||
useEffect(() => {
|
||||
function handleMessage(event: MessageEvent) {
|
||||
if (event.data?.type === "pdfjs-viewer-document-modified" && event.data?.data) {
|
||||
const blob = new Blob([event.data.data], { type: note.mime });
|
||||
server.upload(`notes/${note.noteId}/file`, new File([blob], note.title, { type: note.mime }));
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("message", handleMessage);
|
||||
return () => {
|
||||
window.removeEventListener("message", handleMessage);
|
||||
};
|
||||
}, [ note ]);
|
||||
|
||||
return (
|
||||
<iframe
|
||||
class="pdf-preview"
|
||||
src={`pdfjs/web/viewer.html?file=../../api/notes/${note.noteId}/open`} />
|
||||
);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user