mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
b1c7bd0a33
The KML skip reasons and the file errors were looked up from plain maps, which lint:i18n-keys cannot follow, so the new map keys counted as unused. Both are switches over t() now; the older file error keys are reached as well, so collection.ts holds 29 unused keys instead of 35.
131 lines
5.4 KiB
TypeScript
131 lines
5.4 KiB
TypeScript
import type { CollectionFile, CollectionMapReadResult, CollectionMapSkipReason } from '@trek/shared';
|
|
import { Check, ChevronDown, Folder, Info, MapPin } from 'lucide-react';
|
|
import React, { useState } from 'react';
|
|
import type { TranslationFn } from '../../types';
|
|
import { fs } from '../shared/DialogShell';
|
|
|
|
/** Why a placemark was left out, in words; a switch, so a new reason does not build without them. */
|
|
function skipText(reason: CollectionMapSkipReason, t: TranslationFn): string {
|
|
switch (reason) {
|
|
case 'line':
|
|
return t('collections.file.mapSkipLine');
|
|
case 'no_point':
|
|
return t('collections.file.mapSkipNoPoint');
|
|
case 'invalid':
|
|
return t('collections.file.mapSkipInvalid');
|
|
}
|
|
}
|
|
|
|
/** What a list file holds for a place; the file schema leaves its places to the server to check. */
|
|
type MapPlace = { name?: string; address?: string | null };
|
|
|
|
interface MapImportPreviewProps {
|
|
file: CollectionFile;
|
|
map: Pick<CollectionMapReadResult, 'skipped' | 'folders'>;
|
|
/** Indexes into `file.places` that will be imported. */
|
|
picked: Set<number>;
|
|
onToggle: (index: number) => void;
|
|
onAll: (on: boolean) => void;
|
|
t: TranslationFn;
|
|
}
|
|
|
|
/**
|
|
* The places a KML or KMZ map holds, each one to keep or leave out (PLC-22), and
|
|
* what did not become a place and why. Nothing is written before the import button,
|
|
* so a map with a hundred pins can be narrowed to the six that matter first.
|
|
*/
|
|
export default function MapImportPreview({
|
|
file,
|
|
map,
|
|
picked,
|
|
onToggle,
|
|
onAll,
|
|
t,
|
|
}: MapImportPreviewProps): React.ReactElement {
|
|
const [showSkipped, setShowSkipped] = useState(false);
|
|
const all = picked.size === file.places.length;
|
|
return (
|
|
<div className="flex flex-col gap-2">
|
|
<div className="flex items-center justify-between gap-2">
|
|
<span className="font-semibold text-content-muted" style={fs(12, 'body')}>
|
|
{t('collections.file.mapPicked', { picked: picked.size, total: file.places.length })}
|
|
</span>
|
|
<button
|
|
type="button"
|
|
onClick={() => onAll(!all)}
|
|
className="rounded-[8px] px-2 py-1 font-semibold text-content-muted hover:bg-surface-secondary"
|
|
style={fs(12, 'body')}
|
|
>
|
|
{all ? t('collections.file.mapNone') : t('collections.file.mapAll')}
|
|
</button>
|
|
</div>
|
|
<ul className="m-0 flex max-h-[34vh] list-none flex-col gap-0.5 overflow-y-auto rounded-[14px] border border-edge-faint bg-surface-secondary p-1.5">
|
|
{(file.places as MapPlace[]).map((place, index) => {
|
|
const on = picked.has(index);
|
|
const folder = map.folders[index];
|
|
return (
|
|
<li key={`${index}-${place.name}`}>
|
|
<button
|
|
type="button"
|
|
role="checkbox"
|
|
aria-checked={on}
|
|
onClick={() => onToggle(index)}
|
|
className={`flex min-h-[44px] w-full items-center gap-2.5 rounded-[10px] px-2.5 py-1.5 text-start ${on ? 'bg-surface-card shadow-sm' : 'opacity-60 hover:bg-surface-card'}`}
|
|
>
|
|
<span
|
|
className={`grid h-5 w-5 flex-none place-items-center rounded-md border ${on ? 'border-accent bg-accent text-accent-text' : 'border-edge bg-surface-card'}`}
|
|
>
|
|
{on && <Check size={12} strokeWidth={3} />}
|
|
</span>
|
|
<span className="min-w-0 flex-1">
|
|
<span className="block truncate font-semibold text-content" style={fs(13, 'body')}>
|
|
{place.name}
|
|
</span>
|
|
<span className="flex items-center gap-2 truncate text-content-faint" style={fs(11.5)}>
|
|
{folder && (
|
|
<span className="inline-flex min-w-0 items-center gap-1">
|
|
<Folder size={11} className="flex-none" />
|
|
<span className="truncate">{folder}</span>
|
|
</span>
|
|
)}
|
|
{place.address && (
|
|
<span className="inline-flex min-w-0 items-center gap-1">
|
|
<MapPin size={11} className="flex-none" />
|
|
<span className="truncate">{place.address}</span>
|
|
</span>
|
|
)}
|
|
</span>
|
|
</span>
|
|
</button>
|
|
</li>
|
|
);
|
|
})}
|
|
</ul>
|
|
{map.skipped.length > 0 && (
|
|
<div className="flex flex-col gap-1">
|
|
<button
|
|
type="button"
|
|
onClick={() => setShowSkipped((v) => !v)}
|
|
aria-expanded={showSkipped}
|
|
className="flex items-center gap-2 self-start text-content-muted"
|
|
style={fs(12, 'body')}
|
|
>
|
|
<Info size={13} className="flex-none text-content-faint" />
|
|
{t('collections.file.mapSkipped', { count: map.skipped.length })}
|
|
<ChevronDown size={13} className={`transition-transform ${showSkipped ? 'rotate-180' : ''}`} />
|
|
</button>
|
|
{showSkipped && (
|
|
<ul className="m-0 flex list-none flex-col gap-0.5 ps-5">
|
|
{map.skipped.map((entry, i) => (
|
|
<li key={i} className="text-content-faint" style={fs(11.5)}>
|
|
{entry.name || t('collections.file.mapUnnamed')}: {skipText(entry.reason, t)}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|