Add map import and export with durable refresh progress

This commit is contained in:
2026-10-07 19:44:49 +05:00
parent dac8650ac1
commit 1307436e65
37 changed files with 2207 additions and 85 deletions

17
shared/map-refresh.ts Normal file
View File

@@ -0,0 +1,17 @@
export type MapCapture = { id: string; name: string; created_at: string };
// A contribution can be newer than the original capture, even when both have
// the same name/date in the picker. Keep deliberate choices; otherwise use the
// newest eligible capture, including when accepting a contribution adds one.
export function refreshCapture(sources: MapCapture[], chosen?: string) {
if (chosen && sources.some((source) => source.id === chosen)) return chosen;
return (
sources.reduce<MapCapture | undefined>(
(latest, source) =>
!latest || Date.parse(source.created_at) > Date.parse(latest.created_at)
? source
: latest,
undefined,
)?.id ?? ""
);
}