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

fix(maps): undef func call, flyTo issue, visible column, and silent save failures

jakeaturner1d1945dae408
diff --git a/admin/app/models/map_marker.ts b/admin/app/models/map_marker.ts
index 7a53ee91..16420868 100644
--- a/admin/app/models/map_marker.ts
+++ b/admin/app/models/map_marker.ts
@@ -44,7 +44,11 @@ export default class MapMarker extends BaseModel {
@column()
declare icon_color: string | null
- @column()
+ @column({
+ // MySQL stores this as tinyint(1) and mysql2 hands back 1/0, not true/false.
+ // Without this, strict comparisons (visible === false) silently never match.
+ consume: (value: number | boolean) => Boolean(value),
+ })
declare visible: boolean
@column.dateTime({ autoCreate: true })
diff --git a/admin/inertia/components/maps/MapComponent.tsx b/admin/inertia/components/maps/MapComponent.tsx
index ca4e0136..20d81b66 100644
--- a/admin/inertia/components/maps/MapComponent.tsx
+++ b/admin/inertia/components/maps/MapComponent.tsx
@@ -50,11 +50,21 @@ type SavedMapView = { longitude: number; latitude: number; zoom: number }
const getMapLocationParams = (): MapLocationParams | null => {
const params = new URLSearchParams(window.location.search)
- const lat = Number(params.get('lat'))
+ const latParam = params.get('lat')
const lngParam = params.get('lng')
const longParam = params.get('long')
- const lng = Number(lngParam ?? longParam)
- const zoom = Number(params.get('zoom') ?? 12)
+ const rawLng = lngParam ?? longParam
+
+ // Both coordinates must actually be present. Coercing a missing param instead
+ // yields Number(null) === 0, which passes every bounds check below and flies
+ // the map to 0,0 on a plain visit to /maps -- overriding the restored view and
+ // then persisting Null Island back over it via onMoveEnd.
+ if (!latParam || !rawLng) return null
+
+ const lat = Number(latParam)
+ const lng = Number(rawLng)
+ const zoomParam = params.get('zoom')
+ const zoom = zoomParam ? Number(zoomParam) : 12
if (
!Number.isFinite(lat) ||
@@ -461,8 +471,8 @@ export default function MapComponent({
latitude={placingMarker.lat}
onDirtyChange={setHasUnsavedMarkerChanges}
onMouseEnter={hideCoordinates}
- onSave={async ({ name, notes, color, customColor, icon }) => {
- await addMarker({
+ onSave={async ({ name, notes, color, customColor, icon }) => {
+ const saved = await addMarker({
name,
longitude: placingMarker.lng,
latitude: placingMarker.lat,
@@ -472,6 +482,11 @@ export default function MapComponent({
notes: notes || null,
})
+ // Leave the popup open on failure. api.ts already surfaces the
+ // error toast, but closing here would throw away what was typed
+ // with nothing to retry against.
+ if (!saved) return
+
setPlacingMarker(null)
setHasUnsavedMarkerChanges(false)
setTargetIndicator(null)
@@ -503,10 +518,10 @@ export default function MapComponent({
initialMarker={selectedMarker}
onDirtyChange={setHasUnsavedMarkerChanges}
onMouseEnter={hideCoordinates}
- onSave={async ({ id, name, notes, color, customColor, icon }) => {
+ onSave={async ({ id, name, notes, color, customColor, icon }) => {
if (!id) return
- await updateMarker(id, {
+ const saved = await updateMarker(id, {
name,
notes: notes || null,
color,
@@ -514,6 +529,8 @@ export default function MapComponent({
icon,
})
+ if (!saved) return
+
setEditingMarkerId(null)
setHasUnsavedMarkerChanges(false)
}}
diff --git a/admin/inertia/components/maps/MarkerPanel.tsx b/admin/inertia/components/maps/MarkerPanel.tsx
index c96683aa..70e3a57f 100644
--- a/admin/inertia/components/maps/MarkerPanel.tsx
+++ b/admin/inertia/components/maps/MarkerPanel.tsx
@@ -3,15 +3,11 @@ import { useEffect, useMemo, useState } from 'react'
import {
IconEye,
IconEyeOff,
- IconList,
IconMapPin,
IconMapPinFilled,
- IconSitemap,
IconTrash,
IconX,
} from '@tabler/icons-react'
-import type { IconProps } from '@tabler/icons-react'
-import type { ComponentType } from 'react'
import { PIN_COLORS } from '~/hooks/useMapMarkers'
import type { MapMarker } from '~/hooks/useMapMarkers'
@@ -34,12 +30,6 @@ type ColorSortValue = {
lightness: number
}
-type MarkerGroup = {
- key: string
- label: string
- markers: MapMarker[]
-}
-
const normalizeColorHex = (color: string, customColor?: string | null) => {
if (customColor) return customColor
@@ -84,35 +74,6 @@ const getColorSortValue = (color: string, customColor?: string | null): ColorSor
}
}
-const getHueGroupLabel = ({ bucket, hue, lightness }: ColorSortValue) => {
- if (bucket === 0) {
- return lightness < 0.34
- ? 'Grayscale — Dark'
- : lightness < 0.67
- ? 'Grayscale — Mid'
- : 'Grayscale — Light'
- }
-
- if (bucket === 2) return 'Other colors'
-
- if (hue < 30 || hue >= 330) return 'Red'
- if (hue < 60) return 'Orange'
- if (hue < 90) return 'Yellow'
- if (hue < 150) return 'Green'
- if (hue < 210) return 'Cyan'
- if (hue < 270) return 'Blue'
- return 'Purple'
-}
-const getReadableIconName = (icon?: string | null) => {
- if (!icon) return 'Default pin'
-
- return icon
- .replace(/^fa:/, '')
- .replace(/^tabler:/, '')
- .replace(/^Fa/, '')
- .replace(/^Icon/, '')
-}
-
export default function MarkerPanel({
markers,
onDelete,
@@ -365,10 +326,7 @@ export default function MarkerPanel({
<div className="flex gap-2">
<select
value={sortField}
- onChange={(e) => {
- setSortField(e.target.value as SortField)
- setCollapsedGroups(new Set())
- }}
+ onChange={(e) => setSortField(e.target.value as SortField)}
className="flex-1 rounded border border-border-default bg-surface-primary px-2 py-1 text-xs text-text-primary focus:border-desert-green focus:outline-none"
>
<option value="name">Sort by name</option>
diff --git a/admin/inertia/components/maps/MarkerPin.tsx b/admin/inertia/components/maps/MarkerPin.tsx
index 44d78e16..2e0ed791 100644
--- a/admin/inertia/components/maps/MarkerPin.tsx
+++ b/admin/inertia/components/maps/MarkerPin.tsx
@@ -1,7 +1,5 @@
import { resolveMarkerIcon } from './marker_icons'
import { IconCircleFilled } from '@tabler/icons-react'
-import type { IconProps } from '@tabler/icons-react'
-import type { ComponentType } from 'react'
import { PIN_COLORS } from '~/hooks/useMapMarkers'
import type { PinColorId } from '~/hooks/useMapMarkers'
diff --git a/admin/inertia/hooks/useMapMarkers.ts b/admin/inertia/hooks/useMapMarkers.ts
index 1cec088c..5480441b 100644
--- a/admin/inertia/hooks/useMapMarkers.ts
+++ b/admin/inertia/hooks/useMapMarkers.ts
@@ -123,7 +123,11 @@ export function useMapMarkers() {
setMarkers((prev) =>
prev.map((existingMarker) => (existingMarker.id === id ? marker : existingMarker))
)
+
+ return marker
}
+
+ return null
}, [])
const deleteMarker = useCallback(async (id: number) => {