[resumes][fix] filter out selected options

pull/506/head
Keane Chan 3 years ago
parent 152b0fe8cb
commit b64a04884d
No known key found for this signature in database
GPG Key ID: 32718398E1E9F87C

@ -18,16 +18,18 @@ type BaseProps = Pick<
type Props = BaseProps & type Props = BaseProps &
Readonly<{ Readonly<{
onSelect: (option: TypeaheadOption | null) => void; onSelect: (option: TypeaheadOption | null) => void;
value?: TypeaheadOption | null; selectedValues?: Set<string>;
}>; }>;
export default function ResumeExperienceTypeahead({ export default function ResumeExperienceTypeahead({
onSelect, onSelect,
value, selectedValues = new Set(),
...props ...props
}: Props) { }: Props) {
const [query, setQuery] = useState(''); const [query, setQuery] = useState('');
const options = EXPERIENCES.filter( const options = EXPERIENCES.filter(
({ value }) => !selectedValues.has(value),
).filter(
({ label }) => ({ label }) =>
label.toLocaleLowerCase().indexOf(query.toLocaleLowerCase()) > -1, label.toLocaleLowerCase().indexOf(query.toLocaleLowerCase()) > -1,
); );
@ -38,7 +40,6 @@ export default function ResumeExperienceTypeahead({
noResultsMessage="No available experiences." noResultsMessage="No available experiences."
nullable={true} nullable={true}
options={options} options={options}
value={value}
onQueryChange={setQuery} onQueryChange={setQuery}
onSelect={onSelect} onSelect={onSelect}
{...props} {...props}

@ -1,5 +1,5 @@
import type { ComponentProps } from 'react'; import type { ComponentProps } from 'react';
import { useState } from 'react'; import { useMemo, useState } from 'react';
import type { TypeaheadOption } from '@tih/ui'; import type { TypeaheadOption } from '@tih/ui';
import { Typeahead } from '@tih/ui'; import { Typeahead } from '@tih/ui';
@ -18,12 +18,12 @@ type BaseProps = Pick<
type Props = BaseProps & type Props = BaseProps &
Readonly<{ Readonly<{
onSelect: (option: TypeaheadOption | null) => void; onSelect: (option: TypeaheadOption | null) => void;
value?: TypeaheadOption | null; selectedValues?: Set<string>;
}>; }>;
export default function ResumeLocationTypeahead({ export default function ResumeLocationTypeahead({
onSelect, onSelect,
value, selectedValues = new Set(),
...props ...props
}: Props) { }: Props) {
const [query, setQuery] = useState(''); const [query, setQuery] = useState('');
@ -34,21 +34,27 @@ export default function ResumeLocationTypeahead({
}, },
]); ]);
const options = useMemo(() => {
const { data } = countries; const { data } = countries;
if (data == null) {
return [];
}
return data
.map(({ id, name }) => ({
id,
label: name,
value: id,
}))
.filter(({ value }) => !selectedValues.has(value));
}, [countries, selectedValues]);
return ( return (
<Typeahead <Typeahead
label="Location" label="Location"
noResultsMessage="No location found" noResultsMessage="No location found"
nullable={true} nullable={true}
options={ options={options}
data?.map(({ id, name }) => ({
id,
label: name,
value: id,
})) ?? []
}
value={value}
onQueryChange={setQuery} onQueryChange={setQuery}
onSelect={onSelect} onSelect={onSelect}
{...props} {...props}

@ -18,12 +18,12 @@ type BaseProps = Pick<
type Props = BaseProps & type Props = BaseProps &
Readonly<{ Readonly<{
onSelect: (option: TypeaheadOption | null) => void; onSelect: (option: TypeaheadOption | null) => void;
value?: TypeaheadOption | null; selectedValues?: Set<string>;
}>; }>;
export default function ResumeRoleTypeahead({ export default function ResumeRoleTypeahead({
onSelect, onSelect,
value, selectedValues = new Set(),
...props ...props
}: Props) { }: Props) {
const [query, setQuery] = useState(''); const [query, setQuery] = useState('');
@ -33,6 +33,7 @@ export default function ResumeRoleTypeahead({
label, label,
value: slug, value: slug,
})) }))
.filter(({ value }) => !selectedValues.has(value))
.filter( .filter(
({ label }) => ({ label }) =>
label.toLocaleLowerCase().indexOf(query.toLocaleLowerCase()) > -1, label.toLocaleLowerCase().indexOf(query.toLocaleLowerCase()) > -1,
@ -44,7 +45,6 @@ export default function ResumeRoleTypeahead({
noResultsMessage="No available roles." noResultsMessage="No available roles."
nullable={true} nullable={true}
options={options} options={options}
value={value}
onQueryChange={setQuery} onQueryChange={setQuery}
onSelect={onSelect} onSelect={onSelect}
{...props} {...props}

@ -354,6 +354,9 @@ export default function ResumeHomePage() {
<ResumeExperienceTypeahead <ResumeExperienceTypeahead
isLabelHidden={true} isLabelHidden={true}
placeholder="Select experiences" placeholder="Select experiences"
selectedValues={
new Set(userFilters[filterId].map(({ value }) => value))
}
onSelect={onSelect} onSelect={onSelect}
/> />
); );
@ -362,6 +365,9 @@ export default function ResumeHomePage() {
<ResumeLocationTypeahead <ResumeLocationTypeahead
isLabelHidden={true} isLabelHidden={true}
placeholder="Select locations" placeholder="Select locations"
selectedValues={
new Set(userFilters[filterId].map(({ value }) => value))
}
onSelect={onSelect} onSelect={onSelect}
/> />
); );
@ -370,6 +376,9 @@ export default function ResumeHomePage() {
<ResumeRoleTypeahead <ResumeRoleTypeahead
isLabelHidden={true} isLabelHidden={true}
placeholder="Select roles" placeholder="Select roles"
selectedValues={
new Set(userFilters[filterId].map(({ value }) => value))
}
onSelect={onSelect} onSelect={onSelect}
/> />
); );

Loading…
Cancel
Save