feat(collections): own order, KML/KMZ import, copy options, position search, place names on the trip map

- A list keeps its own order: drag a place by its grip (desktop and phone) or
  move it with the arrow keys. Reordering is off while a search or filter hides
  places and the list says why. New PUT /collections/:id/places/reorder and the
  MCP tool reorder_collection_places; new places go to the end. Client and
  server now order ties the same way (sort_order, oldest first, id).
- Copying saved places into a trip no longer takes their notes and tags along
  unasked. The picker offers both; a tag taken along becomes a trip tag (a trip
  tag of the same name is reused), never someone's personal tag.
- The source trip and place a saved place names are only kept when the user can
  open that trip and the place belongs to it.
- A KML or KMZ map can be read into a list: the dialog lists every placemark to
  keep or leave out and says which entries were skipped and why
  (POST /collections/map/read writes nothing; the import does).
- A saved place without coordinates says so and can be looked up on the map
  from its edit form, on the phone too, where a missing position could not be
  added at all. A typed address without a pick says it will not be on the map.
- The trip map can show the place names beside the pins (desktop and phone,
  both renderers). Names that would cover another pin or a control give way,
  the selected place and the planned stops first.
This commit is contained in:
Maurice
2026-11-29 14:57:00 +01:00
parent 177a0febe2
commit 82165855c7
148 changed files with 4219 additions and 321 deletions
@@ -10,9 +10,14 @@ import {
type CollectionFileError,
type GpxLeftovers,
type GpxReader,
type MapReader,
type ParsedCollectionFile,
COLLECTION_FILE_EXTENSION,
COLLECTION_GPX_EXTENSION,
COLLECTION_KML_EXTENSION,
COLLECTION_KMZ_EXTENSION,
} from './collectionFile'
import MapImportPreview from './MapImportPreview'
interface ImportCollectionModalProps {
onImport: (file: CollectionFile, name?: string) => Promise<void>
@@ -24,6 +29,8 @@ interface ImportCollectionModalProps {
defaultListId?: number | null
/** Reads a GPX into a list file (#2301); the server does the parsing. */
onReadGpx: GpxReader
/** Reads a KML or KMZ map into a list file (PLC-22); the server does that as well. */
onReadMap?: MapReader
onClose: () => void
t: TranslationFn
}
@@ -34,6 +41,7 @@ const ERROR_KEYS: Record<CollectionFileError, string> = {
unreadable: 'collections.file.errorUnreadable',
'not-a-collection': 'collections.file.errorNotACollection',
'not-gpx': 'collections.file.errorNotGpx',
'not-map': 'collections.file.errorNotMap',
'too-many-places': 'collections.file.errorTooManyPlaces',
}
@@ -178,13 +186,16 @@ function ListChoice({ lists, selectedId, onSelect, t }: {
* in it alone and skips the places it already has.
*/
export default function ImportCollectionModal({
onImport, onImportInto, lists, defaultListId, onReadGpx, onClose, t,
onImport, onImportInto, lists, defaultListId, onReadGpx, onReadMap, onClose, t,
}: ImportCollectionModalProps): React.ReactElement {
const inputRef = useRef<HTMLInputElement>(null)
const titleId = useId()
const nameId = useId()
const [file, setFile] = useState<CollectionFile | null>(null)
const [leftovers, setLeftovers] = useState<GpxLeftovers | null>(null)
// A map's placemarks, each one to keep or not: all of them to start with.
const [map, setMap] = useState<ParsedCollectionFile['map']>(null)
const [picked, setPicked] = useState<Set<number>>(new Set())
const [name, setName] = useState('')
const [error, setError] = useState<CollectionFileError | 'failed' | null>(null)
const [failedMessage, setFailedMessage] = useState<string | null>(null)
@@ -208,14 +219,17 @@ export default function ImportCollectionModal({
setFailedMessage(null)
setReading(true)
try {
const result = await readCollectionFile(chosen, onReadGpx)
const result = await readCollectionFile(chosen, onReadGpx, onReadMap)
setFile(result.file)
setLeftovers(result.gpx ?? null)
setMap(result.map ?? null)
setPicked(new Set(result.file?.places.map((_, i) => i) ?? []))
setError(result.error)
if (result.file) setName(result.file.name)
} catch (err) {
setFile(null)
setLeftovers(null)
setMap(null)
setError('failed')
setFailedMessage(getApiErrorMessage(err, t('common.error')))
} finally {
@@ -229,17 +243,22 @@ export default function ImportCollectionModal({
void take(e.dataTransfer.files?.[0])
}
// A map goes in with the placemarks left ticked; the rest of its file is unchanged.
const chosenFile = (): CollectionFile | null =>
!file ? null : map ? { ...file, places: file.places.filter((_, i) => picked.has(i)) } : file
const submit = async () => {
if (!file || busy) return
const outgoing = chosenFile()
if (!outgoing || busy) return
setBusy(true)
setError(null)
setFailedMessage(null)
try {
if (intoExisting && listId != null) {
await onImportInto!(file, listId)
await onImportInto!(outgoing, listId)
} else {
const trimmed = name.trim()
await onImport(file, trimmed && trimmed !== file.name ? trimmed : undefined)
await onImport(outgoing, trimmed && trimmed !== outgoing.name ? trimmed : undefined)
}
} catch (err) {
setError('failed')
@@ -254,7 +273,7 @@ export default function ImportCollectionModal({
: error ? t(ERROR_KEYS[error], { count: MAX_COLLECTION_FILE_PLACES }) : null
// A GPX of nothing but a track would make an empty list, which is never what was meant.
const nothingToImport = !!leftovers && !!file && file.places.length === 0
const nothingToImport = (!!leftovers || !!map) && !!file && (map ? picked.size === 0 : file.places.length === 0)
return (
<DialogShell
@@ -290,7 +309,7 @@ export default function ImportCollectionModal({
<input
ref={inputRef}
type="file"
accept=".json,application/json,.gpx,application/gpx+xml"
accept={onReadMap ? ".json,application/json,.gpx,application/gpx+xml,.kml,.kmz,application/vnd.google-earth.kml+xml,application/vnd.google-earth.kmz" : ".json,application/json,.gpx,application/gpx+xml"}
className="hidden"
onChange={e => { void take(e.target.files?.[0]); e.target.value = '' }}
/>
@@ -314,7 +333,7 @@ export default function ImportCollectionModal({
<span className="font-semibold text-content" style={fs(13, 'body')}>
{reading ? t('collections.file.reading') : t('collections.file.choose')}
</span>
<span className="flex items-center gap-1.5 text-content-faint" style={fs(11.5)}><span>{COLLECTION_FILE_EXTENSION}</span><span>{COLLECTION_GPX_EXTENSION}</span></span>
<span className="flex items-center gap-1.5 text-content-faint" style={fs(11.5)}><span>{COLLECTION_FILE_EXTENSION}</span><span>{COLLECTION_GPX_EXTENSION}</span>{onReadMap && <><span>{COLLECTION_KML_EXTENSION}</span><span>{COLLECTION_KMZ_EXTENSION}</span></>}</span>
</button>
) : (
<>
@@ -322,7 +341,7 @@ export default function ImportCollectionModal({
<div className="flex flex-col gap-2.5">
<div className="flex items-center gap-3 rounded-[14px] border border-edge-faint bg-surface-secondary p-2.5">
<span className="grid h-9 w-9 flex-none place-items-center rounded-[10px]" style={swatch(file.color)}>
{leftovers ? <Route size={16} /> : <FileJson size={16} />}
{leftovers || map ? <Route size={16} /> : <FileJson size={16} />}
</span>
<span className="min-w-0 flex-1">
<span className="block truncate font-semibold text-content" style={fs(13, 'body')}>{file.name}</span>
@@ -348,6 +367,16 @@ export default function ImportCollectionModal({
)}
{leftovers && <GpxNotes leftovers={leftovers} placeCount={file.places.length} t={t} />}
{map && (
<MapImportPreview
file={file}
map={map}
picked={picked}
onToggle={i => setPicked(prev => { const next = new Set(prev); if (next.has(i)) next.delete(i); else next.add(i); return next })}
onAll={on => setPicked(new Set(on ? file.places.map((_, i) => i) : []))}
t={t}
/>
)}
</div>
{canChoose && (
@@ -379,7 +408,7 @@ export default function ImportCollectionModal({
label={t('collections.listName')}
htmlFor={nameId}
// Ratings and members are a TREK file's business; a GPX never had any.
hint={leftovers ? undefined : t('collections.file.hint')}
hint={leftovers || map ? undefined : t('collections.file.hint')}
>
<input
id={nameId}