diff --git a/apps/client/src/services/server.ts b/apps/client/src/services/server.ts index b13653cf3e..381c58a3cf 100644 --- a/apps/client/src/services/server.ts +++ b/apps/client/src/services/server.ts @@ -85,13 +85,15 @@ async function remove(url: string, componentId?: string) { return await call("DELETE", url, componentId); } -async function upload(url: string, fileToUpload: File) { +async function upload(url: string, fileToUpload: File, componentId?: string) { const formData = new FormData(); formData.append("upload", fileToUpload); return await $.ajax({ url: window.glob.baseApiUrl + url, - headers: await getHeaders(), + headers: await getHeaders(componentId ? { + "trilium-component-id": componentId + } : undefined), data: formData, type: "PUT", timeout: 60 * 60 * 1000, diff --git a/apps/client/src/types-pdfjs.d.ts b/apps/client/src/types-pdfjs.d.ts new file mode 100644 index 0000000000..54a440f162 --- /dev/null +++ b/apps/client/src/types-pdfjs.d.ts @@ -0,0 +1,3 @@ +interface Window { + TRILIUM_VIEW_HISTORY_STORE?: object; +} diff --git a/apps/client/src/widgets/collections/NoteList.tsx b/apps/client/src/widgets/collections/NoteList.tsx index 5626cc33cf..ec80e6b197 100644 --- a/apps/client/src/widgets/collections/NoteList.tsx +++ b/apps/client/src/widgets/collections/NoteList.tsx @@ -11,7 +11,8 @@ import froca from "../../services/froca"; import { subscribeToMessages, unsubscribeToMessage as unsubscribeFromMessage } from "../../services/ws"; import { useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumEvent } from "../react/hooks"; import { allViewTypes, ViewModeMedia, ViewModeProps, ViewTypeOptions } from "./interface"; -import ViewModeStorage from "./view_mode_storage"; +import ViewModeStorage, { type ViewModeStorageType } from "./view_mode_storage"; + interface NoteListProps { note: FNote | null | undefined; notePath: string | null | undefined; @@ -215,7 +216,7 @@ export function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOpt return noteIds; } -export function useViewModeConfig(note: FNote | null | undefined, viewType: ViewTypeOptions | undefined) { +export function useViewModeConfig(note: FNote | null | undefined, viewType: ViewModeStorageType | undefined) { const [ viewConfig, setViewConfig ] = useState<{ config: T | undefined; storeFn: (data: T) => void; diff --git a/apps/client/src/widgets/collections/view_mode_storage.ts b/apps/client/src/widgets/collections/view_mode_storage.ts index 95c3ff8004..b8c3b94f25 100644 --- a/apps/client/src/widgets/collections/view_mode_storage.ts +++ b/apps/client/src/widgets/collections/view_mode_storage.ts @@ -4,14 +4,16 @@ import { ViewTypeOptions } from "../collections/interface"; const ATTACHMENT_ROLE = "viewConfig"; +export type ViewModeStorageType = ViewTypeOptions | "pdfHistory"; + export default class ViewModeStorage { private note: FNote; private attachmentName: string; - constructor(note: FNote, viewType: ViewTypeOptions) { + constructor(note: FNote, viewType: ViewModeStorageType) { this.note = note; - this.attachmentName = viewType + ".json"; + this.attachmentName = `${viewType}.json`; } async store(data: T) { diff --git a/apps/client/src/widgets/type_widgets/File.tsx b/apps/client/src/widgets/type_widgets/File.tsx index 2665267549..b720d6a0dc 100644 --- a/apps/client/src/widgets/type_widgets/File.tsx +++ b/apps/client/src/widgets/type_widgets/File.tsx @@ -1,27 +1,29 @@ -import { useNoteBlob } from "../react/hooks"; import "./File.css"; -import { TypeWidgetProps } from "./type_widget"; + import FNote from "../../entities/fnote"; +import { t } from "../../services/i18n"; import { getUrlForDownload } from "../../services/open"; import Alert from "../react/Alert"; -import { t } from "../../services/i18n"; +import { useNoteBlob } from "../react/hooks"; +import PdfPreview from "./file/Pdf"; +import { TypeWidgetProps } from "./type_widget"; const TEXT_MAX_NUM_CHARS = 5000; -export default function File({ note }: TypeWidgetProps) { - const blob = useNoteBlob(note); +export default function FileTypeWidget({ note, parentComponent }: TypeWidgetProps) { + const blob = useNoteBlob(note, parentComponent?.componentId); if (blob?.content) { - return + return ; } else if (note.mime === "application/pdf") { - return + return ; } else if (note.mime.startsWith("video/")) { - return + return ; } else if (note.mime.startsWith("audio/")) { - return - } else { - return + return ; } + return ; + } function TextPreview({ content }: { content: string }) { @@ -37,14 +39,6 @@ function TextPreview({ content }: { content: string }) { )}
{trimmedContent}
- ) -} - -function PdfPreview({ note }: { note: FNote }) { - return ( -