import { useState, useContext, ReactNode, useEffect } from "react"; import { useDispatch, useSelector } from "react-redux"; import { ChevronDown } from "react-feather"; import { CustomizeContext } from "../../providers/CustomizeProvider"; import useClickOutside from "../../hooks/useClickOutside"; import { setSortPref } from "../../state/quotesSlice"; import { SubTitle } from "./SubTitle"; export const SortPreference = () => { const dispatch = useDispatch(); const sortPref = useSelector((state: any) => state.quotes.sortPref); const [dropdown, openDropdown] = useState(false); const dropdownRef = useClickOutside(() => openDropdown(false)); const customSettings = useContext(CustomizeContext); const { borderRadius } = customSettings.customization; // Option Labels const LABEL_STATE = { OUTPUT: "High Return", TIME: "Fastest", }; // Option Values const sortOptions = [ { id: "output", label: LABEL_STATE.OUTPUT }, { id: "time", label: LABEL_STATE.TIME }, ]; const handleChange = (item) => { dispatch(setSortPref(item.id)); openDropdown(false); }; function getSortOption(id) { return sortOptions.filter((x) => x.id === id)?.[0]; } return (
Preferred Route
{dropdown && (
{sortOptions.map((x) => { return ( ); })}
)}
); }; const Option = ({ children, onClick, active = false, }: { children: ReactNode; onClick: () => void; active?: boolean; }) => { return ( ); };