diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.ts index 3fff82afa..dcb768dd7 100644 --- a/apps/client/src/entities/fnote.ts +++ b/apps/client/src/entities/fnote.ts @@ -907,8 +907,8 @@ export default class FNote { return this.getBlob(); } - async getBlob() { - return await this.froca.getBlob("notes", this.noteId); + getBlob() { + return this.froca.getBlob("notes", this.noteId); } toString() { diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx index 23432084d..416aadbe3 100644 --- a/apps/client/src/widgets/collections/geomap/index.tsx +++ b/apps/client/src/widgets/collections/geomap/index.tsx @@ -212,6 +212,7 @@ function NoteGpxTrack({ note }: { note: FNote }) { const blob = useNoteBlob(note); useEffect(() => { + if (!blob) return; server.get(`notes/${note.noteId}/open`, undefined, true).then(xmlResponse => { if (xmlResponse instanceof Uint8Array) { setXmlString(new TextDecoder().decode(xmlResponse)); diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index 06ea554ec..1b218bb33 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -367,7 +367,7 @@ export function useNoteLabelInt(note: FNote | undefined | null, labelName: strin ] } -export function useNoteBlob(note: FNote | null | undefined): [ FBlob | null | undefined ] { +export function useNoteBlob(note: FNote | null | undefined): FBlob | null | undefined { const [ blob, setBlob ] = useState(); function refresh() { @@ -376,14 +376,23 @@ export function useNoteBlob(note: FNote | null | undefined): [ FBlob | null | un useEffect(refresh, [ note?.noteId ]); useTriliumEvent("entitiesReloaded", ({ loadResults }) => { - if (note && loadResults.hasRevisionForNote(note.noteId)) { + if (!note) return; + + // Check if the note was deleted. + if (loadResults.getEntityRow("notes", note.noteId)?.isDeleted) { + setBlob(null); + return; + } + + // Check if a revision occurred. + if (loadResults.hasRevisionForNote(note.noteId)) { refresh(); } }); useDebugValue(note?.noteId); - return [ blob ] as const; + return blob; } export function useLegacyWidget(widgetFactory: () => T, { noteContext, containerClassName, containerStyle }: { diff --git a/apps/client/src/widgets/ribbon/FilePropertiesTab.tsx b/apps/client/src/widgets/ribbon/FilePropertiesTab.tsx index c65b9ab3e..4b42699d3 100644 --- a/apps/client/src/widgets/ribbon/FilePropertiesTab.tsx +++ b/apps/client/src/widgets/ribbon/FilePropertiesTab.tsx @@ -12,7 +12,7 @@ import FNote from "../../entities/fnote"; export default function FilePropertiesTab({ note }: { note?: FNote | null }) { const [ originalFileName ] = useNoteLabel(note, "originalFileName"); const canAccessProtectedNote = !note?.isProtected || protected_session_holder.isProtectedSessionAvailable(); - const [ blob ] = useNoteBlob(note); + const blob = useNoteBlob(note); return (
@@ -52,7 +52,7 @@ export default function FilePropertiesTab({ note }: { note?: FNote | null }) { { if (!fileToUpload) { return; @@ -74,4 +74,4 @@ export default function FilePropertiesTab({ note }: { note?: FNote | null }) { )}
); -} \ No newline at end of file +} diff --git a/apps/client/src/widgets/ribbon/ImagePropertiesTab.tsx b/apps/client/src/widgets/ribbon/ImagePropertiesTab.tsx index 824040b8a..cb747d6b4 100644 --- a/apps/client/src/widgets/ribbon/ImagePropertiesTab.tsx +++ b/apps/client/src/widgets/ribbon/ImagePropertiesTab.tsx @@ -12,7 +12,7 @@ import toast from "../../services/toast"; export default function ImagePropertiesTab({ note, ntxId }: TabContext) { const [ originalFileName ] = useNoteLabel(note, "originalFileName"); - const [ blob ] = useNoteBlob(note); + const blob = useNoteBlob(note); const parentComponent = useContext(ParentComponent); @@ -25,12 +25,12 @@ export default function ImagePropertiesTab({ note, ntxId }: TabContext) { {t("image_properties.original_file_name")}:{" "} {originalFileName ?? "?"} - + {t("image_properties.file_type")}:{" "} {note.mime} - + {t("image_properties.file_size")}:{" "} {formatSize(blob?.contentLength)} @@ -48,7 +48,7 @@ export default function ImagePropertiesTab({ note, ntxId }: TabContext) {