ShipSearch: prevent dupes in exact matches

Fixes urbit/landscape#522
This commit is contained in:
Liam Fitzgerald 2021-03-12 15:13:07 +10:00
parent f20da46745
commit d21c929518
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB

View File

@ -159,6 +159,14 @@ export function ShipSearch<I extends string, V extends Value<I>>(
const error = _.compact(errors[id] as string[]);
const isExact = useCallback((s: string) => {
const ship = `~${deSig(s)}`;
const result = ob.isValidPatp(ship);
return (result && !selected.includes(deSig(s)))
? deSig(s) ?? undefined
: undefined;
}, [selected]);
return (
<FieldArray
name={id}
@ -185,11 +193,7 @@ export function ShipSearch<I extends string, V extends Value<I>>(
<DropdownSearch<string>
mt="2"
isExact={(s) => {
const ship = `~${deSig(s)}`;
const result = ob.isValidPatp(ship);
return result ? deSig(s) ?? undefined : undefined;
}}
isExact={isExact}
placeholder="Search for ships"
candidates={peers}
renderCandidate={renderCandidate}