Skip to content

Build your personal knowledge base with Trilium Notes

feat(share): open a shared map's notes on their shared pages

Elian Dorane1a8deea9055
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx
index 0e35615a17..b1fe935b7e 100644
--- a/apps/client/src/widgets/collections/geomap/index.tsx
+++ b/apps/client/src/widgets/collections/geomap/index.tsx
@@ -92,7 +92,7 @@ type Placement =
| { mode: "move"; noteId: string }
| { mode: "draw"; tool: DrawTool };
-export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewModeProps<MapData>) {
+export default function GeoView({ note, noteIds, viewConfig, saveConfig, onOpenNote }: ViewModeProps<MapData>) {
const { noteContext } = useNoteContext();
const [ placement, setPlacement ] = useState<Placement>();
// Which marker the detail pane stands for. Held here rather than in the pane so that creating a
@@ -179,11 +179,16 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
/** Opens the pane on a note, which sends away the searched place the panel would otherwise share
* a corner with. */
const selectNote = useCallback((next: PaneSelection | null) => {
+ if (next && onOpenNote) {
+ onOpenNote(next.noteId);
+ return;
+ }
+
setSelection(next);
if (next) {
forgetPlace();
}
- }, [ forgetPlace ]);
+ }, [ forgetPlace, onOpenNote ]);
/** Stands the map on a place found by searching, and fetches the ground it covers where it covers
* any (see PlaceMarker). */
diff --git a/apps/client/src/widgets/collections/interface.ts b/apps/client/src/widgets/collections/interface.ts
index f665948098..b92a7d3a79 100644
--- a/apps/client/src/widgets/collections/interface.ts
+++ b/apps/client/src/widgets/collections/interface.ts
@@ -24,4 +24,6 @@ export interface ViewModeProps<T extends object> {
onReady(data: PrintReport): void;
onProgressChanged?: ProgressChangedFn;
showTextRepresentation?: boolean;
+ /** Opens a note the view selects, in place of the view's own way, such as the map's detail pane. */
+ onOpenNote?: (noteId: string) => void;
}
diff --git a/packages/share-theme/src/content/geomap_view.tsx b/packages/share-theme/src/content/geomap_view.tsx
index 30f4a25434..e2bdc7b22c 100644
--- a/packages/share-theme/src/content/geomap_view.tsx
+++ b/packages/share-theme/src/content/geomap_view.tsx
@@ -21,7 +21,7 @@ interface GeoMapPayload extends FrocaPayload {
* control the view has.
*/
export default function mountGeoMap(container: HTMLElement, payload: GeoMapPayload) {
- const { options: optionValues, links: _links, ...rows } = payload;
+ const { options: optionValues, links, ...rows } = payload;
options.load(Object.fromEntries(Object.entries(optionValues)
.flatMap(([ name, value ]) => (value === null ? [] : [ [ name, value ] ]))));
@@ -55,12 +55,20 @@ export default function mountGeoMap(container: HTMLElement, payload: GeoMapPaylo
saveConfig={() => {}}
media="screen"
onReady={() => {}}
+ onOpenNote={(openedNoteId) => openLink(links[openedNoteId])}
/>
</ParentComponent.Provider>,
container
);
}
+/** Opens a note's shared page, which the map does in place of its detail pane. */
+function openLink(link: string | undefined) {
+ if (link) {
+ window.location.href = link;
+ }
+}
+
/**
* Gives `appContext` the part of `start()` that the view relies on, a `TabManager` for the note
* contexts its panes register, and returns a component under it for the view to mount below.