Add map import and export with durable refresh progress
This commit is contained in:
17
shared/map-refresh.ts
Normal file
17
shared/map-refresh.ts
Normal 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 ?? ""
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user