Skip to content

Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.

TypeScript

feat(maps): add notes input to map pin placement popup (#926)

chriscrosstalked1fed8d2a90
diff --git a/admin/inertia/components/maps/MapComponent.tsx b/admin/inertia/components/maps/MapComponent.tsx
index aa9d9c0e..cd40cbce 100644
--- a/admin/inertia/components/maps/MapComponent.tsx
+++ b/admin/inertia/components/maps/MapComponent.tsx
@@ -72,6 +72,7 @@ export default function MapComponent({
const [isDraggingMap, setIsDraggingMap] = useState(false)
const [placingMarker, setPlacingMarker] = useState<{ lng: number; lat: number } | null>(null)
const [markerName, setMarkerName] = useState('')
+ const [markerNotes, setMarkerNotes] = useState('')
const [markerColor, setMarkerColor] = useState<PinColorId>('orange')
const [selectedMarkerId, setSelectedMarkerId] = useState<number | null>(null)
@@ -153,18 +154,27 @@ export default function MapComponent({
const handleMapClick = useCallback((e: MapLayerMouseEvent) => {
setPlacingMarker({ lng: e.lngLat.lng, lat: e.lngLat.lat })
setMarkerName('')
+ setMarkerNotes('')
setMarkerColor('orange')
setSelectedMarkerId(null)
}, [])
const handleSaveMarker = useCallback(() => {
if (placingMarker && markerName.trim()) {
- addMarker(markerName.trim(), placingMarker.lng, placingMarker.lat, markerColor)
+ const trimmedNotes = markerNotes.trim()
+ addMarker(
+ markerName.trim(),
+ placingMarker.lng,
+ placingMarker.lat,
+ markerColor,
+ trimmedNotes ? trimmedNotes : null
+ )
setPlacingMarker(null)
setMarkerName('')
+ setMarkerNotes('')
setMarkerColor('orange')
}
- }, [placingMarker, markerName, markerColor, addMarker])
+ }, [placingMarker, markerName, markerNotes, markerColor, addMarker])
const handleFlyTo = useCallback((longitude: number, latitude: number) => {
mapRef.current?.flyTo({ center: [longitude, latitude], zoom: 12, duration: 1500 })
@@ -317,6 +327,17 @@ export default function MapComponent({
className="block w-full rounded border border-gray-300 px-2 py-1 text-sm placeholder:text-gray-400 focus:outline-none focus:border-gray-500"
/>
+ <textarea
+ placeholder="Notes (optional)"
+ value={markerNotes}
+ onChange={(e) => setMarkerNotes(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === 'Escape') setPlacingMarker(null)
+ }}
+ rows={2}
+ className="mt-1.5 block w-full resize-y rounded border border-gray-300 px-2 py-1 text-sm placeholder:text-gray-400 focus:outline-none focus:border-gray-500"
+ />
+
<div className="mt-1.5 flex gap-1 items-center">
{PIN_COLORS.map((c) => (
<button
diff --git a/admin/inertia/hooks/useMapMarkers.ts b/admin/inertia/hooks/useMapMarkers.ts
index a0e818e5..5a278d2e 100644
--- a/admin/inertia/hooks/useMapMarkers.ts
+++ b/admin/inertia/hooks/useMapMarkers.ts
@@ -47,8 +47,14 @@ export function useMapMarkers() {
}, [])
const addMarker = useCallback(
- async (name: string, longitude: number, latitude: number, color: PinColorId = 'orange') => {
- const result = await api.createMapMarker({ name, longitude, latitude, color })
+ async (
+ name: string,
+ longitude: number,
+ latitude: number,
+ color: PinColorId = 'orange',
+ notes: string | null = null
+ ) => {
+ const result = await api.createMapMarker({ name, longitude, latitude, color, notes })
if (result) {
const marker: MapMarker = {
id: result.id,
diff --git a/admin/inertia/lib/api.ts b/admin/inertia/lib/api.ts
index 9782e9ea..75f8d49c 100644
--- a/admin/inertia/lib/api.ts
+++ b/admin/inertia/lib/api.ts
@@ -720,7 +720,7 @@ class API {
})()
}
- async createMapMarker(data: { name: string; longitude: number; latitude: number; color?: string }) {
+ async createMapMarker(data: { name: string; longitude: number; latitude: number; color?: string; notes?: string | null }) {
return catchInternal(async () => {
const response = await this.client.post<
{ id: number; name: string; longitude: number; latitude: number; color: string; notes: string | null; created_at: string }