From 4c20ac0b1cb30869869fea55eb5e022896f9348a Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 6 Sep 2025 14:31:41 +0300 Subject: [PATCH] chore(react/collections): reintroduce geomap touch bar buttons --- .../src/widgets/collections/geomap/index.tsx | 15 +++++-- apps/client/src/widgets/react/TouchBar.tsx | 41 +++++++++++++++---- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx index fa0e7a54d..b04403328 100644 --- a/apps/client/src/widgets/collections/geomap/index.tsx +++ b/apps/client/src/widgets/collections/geomap/index.tsx @@ -4,7 +4,7 @@ import { ViewModeProps } from "../interface"; import { useNoteBlob, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useNoteTreeDrag, useSpacedUpdate, useTouchBar, useTriliumEvent } from "../../react/hooks"; import { DEFAULT_MAP_LAYER_NAME } from "./map_layer"; import { divIcon, GPXOptions, LatLng, LeafletMouseEvent } from "leaflet"; -import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks"; +import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks"; import Marker, { GpxTrack } from "./marker"; import froca from "../../../services/froca"; import FNote from "../../../entities/fnote"; @@ -17,7 +17,8 @@ import toast from "../../../services/toast"; import { t } from "../../../services/i18n"; import server from "../../../services/server"; import branches from "../../../services/branches"; -import TouchBar, { TouchBarLabel, TouchBarSlider } from "../../react/TouchBar"; +import TouchBar, { TouchBarButton, TouchBarLabel, TouchBarSlider } from "../../react/TouchBar"; +import { ParentComponent } from "../../react/react_utils"; const DEFAULT_COORDINATES: [number, number] = [3.878638227135724, 446.6630455551659]; const DEFAULT_ZOOM = 2; @@ -130,7 +131,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM > {notes.map(note => )} - + ); } @@ -244,8 +245,9 @@ function buildIcon(bxIconClass: string, colorClass?: string, title?: string, not }); } -function GeoMapTouchBar({ map }: { map: L.Map | null | undefined }) { +function GeoMapTouchBar({ state, map }: { state: State, map: L.Map | null | undefined }) { const [ currentZoom, setCurrentZoom ] = useState(); + const parentComponent = useContext(ParentComponent); useEffect(() => { if (!map) return; @@ -270,6 +272,11 @@ function GeoMapTouchBar({ map }: { map: L.Map | null | undefined }) { map.setZoom(newValue); }} /> + parentComponent?.triggerCommand("geoMapCreateChildNote")} + enabled={state === State.Normal} + /> ) } diff --git a/apps/client/src/widgets/react/TouchBar.tsx b/apps/client/src/widgets/react/TouchBar.tsx index d0a7b9d65..ba2e664b0 100644 --- a/apps/client/src/widgets/react/TouchBar.tsx +++ b/apps/client/src/widgets/react/TouchBar.tsx @@ -8,6 +8,24 @@ interface TouchBarProps { children: ComponentChildren; } +interface LabelProps { + label: string; +} + +interface SliderProps { + label: string; + value: number; + minValue: number; + maxValue: number; + onChange: (newValue: number) => void; +} + +interface ButtonProps { + label: string; + click: () => void; + enabled?: boolean; +} + interface TouchBarContextApi { addItem(item: TouchBarItem): void; TouchBar: typeof Electron.TouchBar; @@ -61,7 +79,7 @@ export default function TouchBar({ children }: TouchBarProps) { ); } -export function TouchBarLabel({ label }: { label: string }) { +export function TouchBarLabel({ label }: LabelProps) { const api = useContext(TouchBarContext); if (api) { @@ -74,14 +92,6 @@ export function TouchBarLabel({ label }: { label: string }) { return <>; } -interface SliderProps { - label: string; - value: number; - minValue: number; - maxValue: number; - onChange: (newValue: number) => void; -} - export function TouchBarSlider({ label, value, minValue, maxValue, onChange }: SliderProps) { const api = useContext(TouchBarContext); @@ -96,3 +106,16 @@ export function TouchBarSlider({ label, value, minValue, maxValue, onChange }: S return <>; } + +export function TouchBarButton({ label, click, enabled }: ButtonProps) { + const api = useContext(TouchBarContext); + + if (api) { + const item = new api.TouchBar.TouchBarButton({ + label, click, enabled + }); + api.addItem(item); + } + + return <>; +}