2023-06-13 23:40:23 -05:00
|
|
|
import React, { Dispatch, SetStateAction } from "react";
|
2023-05-28 17:40:28 -05:00
|
|
|
import ClickAwayHandler from "./ClickAwayHandler";
|
|
|
|
import RadioButton from "./RadioButton";
|
2023-06-13 21:44:50 -05:00
|
|
|
import { Sort } from "@/types/global";
|
2023-05-28 17:40:28 -05:00
|
|
|
|
|
|
|
type Props = {
|
2023-06-13 21:44:50 -05:00
|
|
|
sortBy: Sort;
|
2023-06-13 23:40:23 -05:00
|
|
|
setSort: Dispatch<SetStateAction<Sort>>;
|
|
|
|
|
2023-05-28 17:40:28 -05:00
|
|
|
toggleSortDropdown: Function;
|
|
|
|
};
|
|
|
|
|
2023-06-13 23:40:23 -05:00
|
|
|
export default function SortDropdown({
|
2023-05-28 17:40:28 -05:00
|
|
|
sortBy,
|
|
|
|
toggleSortDropdown,
|
2023-06-13 23:40:23 -05:00
|
|
|
setSort,
|
2023-05-28 17:40:28 -05:00
|
|
|
}: Props) {
|
|
|
|
return (
|
|
|
|
<ClickAwayHandler
|
|
|
|
onClickOutside={(e: Event) => {
|
|
|
|
const target = e.target as HTMLInputElement;
|
|
|
|
if (target.id !== "sort-dropdown") toggleSortDropdown();
|
|
|
|
}}
|
2023-08-14 22:25:25 -05:00
|
|
|
className="absolute top-8 right-0 border border-sky-100 dark:border-neutral-700 shadow-md bg-gray-50 dark:bg-neutral-800 rounded-md p-2 z-20 w-48"
|
2023-05-28 17:40:28 -05:00
|
|
|
>
|
2023-08-11 00:11:02 -05:00
|
|
|
<p className="mb-2 text-black dark:text-white text-center font-semibold">
|
2023-08-10 23:44:44 -05:00
|
|
|
Sort by
|
|
|
|
</p>
|
2023-05-28 17:40:28 -05:00
|
|
|
<div className="flex flex-col gap-2">
|
2023-06-14 17:34:54 -05:00
|
|
|
<RadioButton
|
|
|
|
label="Date (Newest First)"
|
|
|
|
state={sortBy === Sort.DateNewestFirst}
|
|
|
|
onClick={() => setSort(Sort.DateNewestFirst)}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<RadioButton
|
|
|
|
label="Date (Oldest First)"
|
|
|
|
state={sortBy === Sort.DateOldestFirst}
|
|
|
|
onClick={() => setSort(Sort.DateOldestFirst)}
|
|
|
|
/>
|
|
|
|
|
2023-05-28 17:40:28 -05:00
|
|
|
<RadioButton
|
|
|
|
label="Name (A-Z)"
|
2023-06-13 21:44:50 -05:00
|
|
|
state={sortBy === Sort.NameAZ}
|
2023-06-13 23:40:23 -05:00
|
|
|
onClick={() => setSort(Sort.NameAZ)}
|
2023-05-28 17:40:28 -05:00
|
|
|
/>
|
|
|
|
|
|
|
|
<RadioButton
|
|
|
|
label="Name (Z-A)"
|
2023-06-13 21:44:50 -05:00
|
|
|
state={sortBy === Sort.NameZA}
|
2023-06-13 23:40:23 -05:00
|
|
|
onClick={() => setSort(Sort.NameZA)}
|
2023-05-28 17:40:28 -05:00
|
|
|
/>
|
|
|
|
|
|
|
|
<RadioButton
|
2023-06-13 23:40:23 -05:00
|
|
|
label="Description (A-Z)"
|
|
|
|
state={sortBy === Sort.DescriptionAZ}
|
|
|
|
onClick={() => setSort(Sort.DescriptionAZ)}
|
2023-05-28 17:40:28 -05:00
|
|
|
/>
|
|
|
|
|
|
|
|
<RadioButton
|
2023-06-13 23:40:23 -05:00
|
|
|
label="Description (Z-A)"
|
|
|
|
state={sortBy === Sort.DescriptionZA}
|
|
|
|
onClick={() => setSort(Sort.DescriptionZA)}
|
2023-05-28 17:40:28 -05:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</ClickAwayHandler>
|
|
|
|
);
|
|
|
|
}
|