refactor: create SortDropdownButton

This commit is contained in:
Sammy Teillet
2023-04-24 17:35:01 +02:00
parent 7cf1f913b0
commit 795f9e7af8
2 changed files with 50 additions and 18 deletions

View File

@ -0,0 +1,38 @@
import { useCallback } from 'react';
import DropdownButton from './DropdownButton';
import { SortType } from './SortAndFilterBar';
type OwnProps = {
sorts: SortType[];
setSorts: any;
sortsAvailable: any;
};
export function SortDropdownButton({
sortsAvailable,
setSorts,
sorts,
}: OwnProps) {
const onSortItemSelect = useCallback(
(sortId: string) => {
const newSorts = [
{
label: 'Created at',
order: 'asc',
id: sortId,
} satisfies SortType,
];
setSorts(newSorts);
},
[setSorts],
);
return (
<DropdownButton
label="Sort"
options={sortsAvailable}
onSortSelect={onSortItemSelect}
isActive={sorts.length > 0}
/>
);
}