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( (latest, source) => !latest || Date.parse(source.created_at) > Date.parse(latest.created_at) ? source : latest, undefined, )?.id ?? "" ); }