diff --git a/client/components/map/FilterPanel.tsx b/client/components/map/FilterPanel.tsx index 3b7bf5d..95a5d15 100644 --- a/client/components/map/FilterPanel.tsx +++ b/client/components/map/FilterPanel.tsx @@ -1,28 +1,30 @@ import { Box, - VStack, HStack, - Spacer, - Button, Text, Slider, SliderTrack, SliderFilledTrack, SliderThumb, + Modal, + ModalContent, + ModalOverlay, Divider, - CheckboxGroup, - Checkbox, - Stack, + Button, + Flex, + useCheckbox, + chakra, + CheckboxProps, + useCheckboxGroup, } from "@chakra-ui/react"; -import { XButton } from "./Buttons"; import { COLORS } from "theme"; import { TItemSelection, TEmptyItem } from "app-context/SheetyContext/types"; import { OptionType } from "spa-pages"; -import { ChangeEvent } from "react"; +import React, { ChangeEvent } from "react"; +import { Methods } from "api/sheety/enums"; type FilterProps = { - isMobile: boolean | undefined; - setFilterShow: () => void; + isOpen: boolean; filterApply: () => void; handleSliderChange: (val: number) => void; range: number; @@ -32,8 +34,7 @@ type FilterProps = { }; export const FilterPanel = ({ - isMobile, - setFilterShow, + isOpen, filterApply, handleSliderChange, range, @@ -41,77 +42,169 @@ export const FilterPanel = ({ selectOptions, handleCheckboxChange, }: FilterProps) => { + const selectedOptionsWithCheckedState = selectOptions.map((option) => { + const isChecked = itemState.some( + (item) => item.name === option.value && item.method === option.method, + ); + return { ...option, isChecked }; + }); + return ( - - - - - - - + undefined}> + + + + Apply + + } + > + + + + + + + Nearest + + + Most items + + + - - - Distance - - + + 3km 10km handleSliderChange(val)} > - + - + - - - - - Items - - item.name)} - > - - {selectOptions.map((item) => ( - handleCheckboxChange(e)} - key={item.idx} - data-key={item.idx} - value={item.value} - name={item.method} - > - {item.value} - - ))} - - - - + + + + ); +}; + +function FilterSection({ + title, + hideDivider, + button, + children, +}: React.PropsWithChildren<{ title: string; hideDivider?: boolean; button?: JSX.Element }>) { + return ( + + + {title} + {button} + + {children} + ); +} + +type PillBoxItem = { + value: string; + method?: Methods; + isChecked: boolean; +}; + +const PillBox = ({ + items, + handleItemSelect, +}: { + items: Array; + handleItemSelect: (item: any) => void; +}) => { + const { getCheckboxProps } = useCheckboxGroup({ + value: items.filter((item) => item.isChecked).map((item) => item.value), + }); + + return ( + + {items.map((item) => ( + + ))} + + {items.map((item) => ( + + ))} + + ); +}; + +const PillBoxItem = (props: CheckboxProps) => { + const { state, getInputProps, getLabelProps, htmlProps } = useCheckbox(props); + + return ( + + + + {props.value} + + + ); }; diff --git a/client/spa-pages/components/MapPage.tsx b/client/spa-pages/components/MapPage.tsx index ea621bf..193d14d 100644 --- a/client/spa-pages/components/MapPage.tsx +++ b/client/spa-pages/components/MapPage.tsx @@ -1,6 +1,6 @@ // General Imports import { BasePage } from "layouts/BasePage"; -import { Flex, VStack, Box, IconButton } from "@chakra-ui/react"; +import { Flex, VStack, Box, IconButton, useDisclosure } from "@chakra-ui/react"; import { Dispatch, SetStateAction, useState } from "react"; import { Pages } from "spa-pages/pageEnums"; import { useUserInputs } from "hooks/useUserSelection"; @@ -78,7 +78,7 @@ const MapInner = ({ setPage }: Props) => { ////// States ////// // Filters - const [filterShow, setFilterShow] = useState(false); + const { isOpen: isFilterOpen, onOpen: onFilterOpen, onClose: onFilterClose } = useDisclosure(); const [range, setRange] = useState(60); // const [isExpanded, setIsExpanded] = useState(false); @@ -353,7 +353,7 @@ const MapInner = ({ setPage }: Props) => { { getMatchingFacility={getMatchingFacility} /> )} */} - {filterShow && ( - setFilterShow(true)} - filterApply={() => setFilterShow(false)} - handleSliderChange={handleSliderChange} - range={range} - itemState={itemState} - selectOptions={selectOptions} - handleCheckboxChange={handleCheckboxChange} - /> - )} + onFilterClose()} + handleSliderChange={handleSliderChange} + range={range} + itemState={itemState} + selectOptions={selectOptions} + handleCheckboxChange={handleCheckboxChange} + /> ); }; @@ -423,15 +420,14 @@ export const MapPage = ({ setPage }: Props) => ( export const MapHeaderButtons = ({ setPage, - setFilterShow, selectedOptions, selectOptions, handleMultiselectOnChange, itemState, handleChangedLocation, + onFilterOpen, }: { setPage: Dispatch>; - setFilterShow: Dispatch>; selectedOptions: OptionType[]; selectOptions: OptionType[]; handleMultiselectOnChange: ( @@ -440,6 +436,7 @@ export const MapHeaderButtons = ({ ) => void; itemState: (TItemSelection | TEmptyItem)[]; handleChangedLocation: (itemEntry: (TItemSelection | TEmptyItem)[]) => void; + onFilterOpen: () => void; }) => { return ( - setFilterShow(true)} height="44px" /> + );