fix(react/collections/geomap): "note not found" when deleting GPX

This commit is contained in:
Elian Doran
2025-09-13 15:34:32 +03:00
parent dc854cbd10
commit 5bb1432450
5 changed files with 23 additions and 13 deletions

View File

@@ -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() {

View File

@@ -212,6 +212,7 @@ function NoteGpxTrack({ note }: { note: FNote }) {
const blob = useNoteBlob(note);
useEffect(() => {
if (!blob) return;
server.get<string | Uint8Array>(`notes/${note.noteId}/open`, undefined, true).then(xmlResponse => {
if (xmlResponse instanceof Uint8Array) {
setXmlString(new TextDecoder().decode(xmlResponse));

View File

@@ -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<FBlob | null>();
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<T extends BasicWidget>(widgetFactory: () => T, { noteContext, containerClassName, containerStyle }: {

View File

@@ -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 (
<div className="file-properties-widget">
@@ -52,7 +52,7 @@ export default function FilePropertiesTab({ note }: { note?: FNote | null }) {
<FormFileUploadButton
icon="bx bx-folder-open"
text={t("file_properties.upload_new_revision")}
disabled={!canAccessProtectedNote}
disabled={!canAccessProtectedNote}
onChange={(fileToUpload) => {
if (!fileToUpload) {
return;
@@ -74,4 +74,4 @@ export default function FilePropertiesTab({ note }: { note?: FNote | null }) {
)}
</div>
);
}
}

View File

@@ -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) {
<strong>{t("image_properties.original_file_name")}:</strong>{" "}
<span>{originalFileName ?? "?"}</span>
</span>
<span>
<strong>{t("image_properties.file_type")}:</strong>{" "}
<span>{note.mime}</span>
</span>
<span>
<strong>{t("image_properties.file_size")}:</strong>{" "}
<span>{formatSize(blob?.contentLength)}</span>
@@ -48,7 +48,7 @@ export default function ImagePropertiesTab({ note, ntxId }: TabContext) {
<Button
text={t("image_properties.open")}
icon="bx bx-link-external"
onClick={() => openNoteExternally(note.noteId, note.mime)}
onClick={() => openNoteExternally(note.noteId, note.mime)}
/>
<Button
@@ -79,4 +79,4 @@ export default function ImagePropertiesTab({ note, ntxId }: TabContext) {
)}
</div>
)
}
}