mirror of
https://github.com/zadam/trilium.git
synced 2025-10-28 08:46:43 +01:00
fix(react/collections/geomap): crash for notes without location
This commit is contained in:
@@ -46,6 +46,8 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
|
|||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
|
console.log("Got new notes IDs ", noteIds);
|
||||||
|
console.log("Got notes ", notes);
|
||||||
useEffect(() => { froca.getNotes(noteIds).then(setNotes) }, [ noteIds ]);
|
useEffect(() => { froca.getNotes(noteIds).then(setNotes) }, [ noteIds ]);
|
||||||
|
|
||||||
// Note creation.
|
// Note creation.
|
||||||
@@ -126,19 +128,30 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
|
|||||||
onContextMenu={onContextMenu}
|
onContextMenu={onContextMenu}
|
||||||
scale={hasScale}
|
scale={hasScale}
|
||||||
>
|
>
|
||||||
{notes.map(note => (
|
{notes.map(note => <NoteWrapper note={note} isReadOnly={isReadOnly} />)}
|
||||||
note.mime !== "application/gpx+xml"
|
|
||||||
? <NoteMarker note={note} editable={!isReadOnly} />
|
|
||||||
: <NoteGpxTrack note={note} />
|
|
||||||
))}
|
|
||||||
</Map>
|
</Map>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function NoteMarker({ note, editable }: { note: FNote, editable: boolean }) {
|
function NoteWrapper({ note, isReadOnly }: { note: FNote, isReadOnly: boolean }) {
|
||||||
|
const mime = useNoteProperty(note, "mime");
|
||||||
const [ location ] = useNoteLabel(note, LOCATION_ATTRIBUTE);
|
const [ location ] = useNoteLabel(note, LOCATION_ATTRIBUTE);
|
||||||
|
|
||||||
|
console.log("Got ", note, mime);
|
||||||
|
|
||||||
|
if (mime === "application/gpx+xml") {
|
||||||
|
return <NoteGpxTrack note={note} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location) {
|
||||||
|
const latLng = location?.split(",", 2).map((el) => parseFloat(el)) as [ number, number ] | undefined;
|
||||||
|
if (!latLng) return;
|
||||||
|
return <NoteMarker note={note} editable={!isReadOnly} latLng={latLng} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function NoteMarker({ note, editable, latLng }: { note: FNote, editable: boolean, latLng: [number, number] }) {
|
||||||
// React to changes
|
// React to changes
|
||||||
useNoteLabel(note, "color");
|
useNoteLabel(note, "color");
|
||||||
useNoteLabel(note, "iconClass");
|
useNoteLabel(note, "iconClass");
|
||||||
@@ -146,7 +159,6 @@ function NoteMarker({ note, editable }: { note: FNote, editable: boolean }) {
|
|||||||
const title = useNoteProperty(note, "title");
|
const title = useNoteProperty(note, "title");
|
||||||
const colorClass = note.getColorClass();
|
const colorClass = note.getColorClass();
|
||||||
const iconClass = note.getIcon();
|
const iconClass = note.getIcon();
|
||||||
const latLng = location?.split(",", 2).map((el) => parseFloat(el)) as [ number, number ] | undefined;
|
|
||||||
const icon = useMemo(() => buildIcon(iconClass, colorClass ?? undefined, title, note.noteId), [ iconClass, colorClass, title, note.noteId]);
|
const icon = useMemo(() => buildIcon(iconClass, colorClass ?? undefined, title, note.noteId), [ iconClass, colorClass, title, note.noteId]);
|
||||||
|
|
||||||
const onClick = useCallback(() => {
|
const onClick = useCallback(() => {
|
||||||
@@ -168,6 +180,7 @@ function NoteMarker({ note, editable }: { note: FNote, editable: boolean }) {
|
|||||||
|
|
||||||
const onContextMenu = useCallback((e: LeafletMouseEvent) => openContextMenu(note.noteId, e, editable), [ note.noteId, editable ]);
|
const onContextMenu = useCallback((e: LeafletMouseEvent) => openContextMenu(note.noteId, e, editable), [ note.noteId, editable ]);
|
||||||
|
|
||||||
|
console.log("Got ", latLng);
|
||||||
return latLng && <Marker
|
return latLng && <Marker
|
||||||
coordinates={latLng}
|
coordinates={latLng}
|
||||||
icon={icon}
|
icon={icon}
|
||||||
|
|||||||
Reference in New Issue
Block a user