| const handleSelectCategory = (category) => { | const handleSelectCategory = (category) => { | ||||
| filters.category.setSelectedCategory(category); | filters.category.setSelectedCategory(category); | ||||
| filters.subcategory.setSelectedSubcategory({}); | filters.subcategory.setSelectedSubcategory({}); | ||||
| props.offers.applyFilters(); | |||||
| }; | }; | ||||
| console.log(props); | |||||
| useImperativeHandle(ref, () => ({ | useImperativeHandle(ref, () => ({ | ||||
| closeSection: () => { | closeSection: () => { | ||||
| setIsOpened(false); | setIsOpened(false); | ||||
| setSelected={handleSelectCategory} | setSelected={handleSelectCategory} | ||||
| selected={filters.category.selectedCategoryLocally} | selected={filters.category.selectedCategoryLocally} | ||||
| firstOption={firstCategoryOption} | firstOption={firstCategoryOption} | ||||
| offers={props.offers} | |||||
| /> | /> | ||||
| ); | ); | ||||
| }); | }); | ||||
| CategoryChoser.propTypes = { | CategoryChoser.propTypes = { | ||||
| filters: PropTypes.any, | filters: PropTypes.any, | ||||
| offers: PropTypes.any, | |||||
| }; | }; | ||||
| export default CategoryChoser; | export default CategoryChoser; |
| title={t("filters.company.title")} | title={t("filters.company.title")} | ||||
| setItemsSelected={filters.companies.setSelectedCompanies} | setItemsSelected={filters.companies.setSelectedCompanies} | ||||
| companies | companies | ||||
| offers={props.offers} | |||||
| /> | /> | ||||
| ); | ); | ||||
| }); | }); | ||||
| CompanyChoser.propTypes = { | CompanyChoser.propTypes = { | ||||
| filters: PropTypes.any, | filters: PropTypes.any, | ||||
| offers: PropTypes.any, | |||||
| }; | }; | ||||
| export default CompanyChoser; | export default CompanyChoser; |
| import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useState } from "react"; | |||||
| import React, { | |||||
| forwardRef, | |||||
| useEffect, | |||||
| useImperativeHandle, | |||||
| useMemo, | |||||
| useState, | |||||
| } from "react"; | |||||
| import PropTypes from "prop-types"; | import PropTypes from "prop-types"; | ||||
| import FilterCheckboxDropdown from "../../FilterDropdown/Checkbox/FilterCheckboxDropdown"; | import FilterCheckboxDropdown from "../../FilterDropdown/Checkbox/FilterCheckboxDropdown"; | ||||
| import { LocationIcon } from "./LocationChoser.styled"; | import { LocationIcon } from "./LocationChoser.styled"; | ||||
| const [isOpened, setIsOpened] = useState(false); | const [isOpened, setIsOpened] = useState(false); | ||||
| const filters = props.filters; | const filters = props.filters; | ||||
| const allLocations = useMemo(() => filters.locations.allLocations || [], [filters.locations]) | |||||
| console.log(props); | |||||
| const allLocations = useMemo( | |||||
| () => filters.locations.allLocations || [], | |||||
| [filters.locations] | |||||
| ); | |||||
| useImperativeHandle(ref, () => ({ | useImperativeHandle(ref, () => ({ | ||||
| closeSection: () => { | closeSection: () => { | ||||
| if (filters.locations.selectedLocationsLocally.length > 0 && !isOpened) { | if (filters.locations.selectedLocationsLocally.length > 0 && !isOpened) { | ||||
| setIsOpened(true); | setIsOpened(true); | ||||
| } | } | ||||
| }, [filters.locations.selectedLocationsLocally]) | |||||
| }, [filters.locations.selectedLocationsLocally]); | |||||
| return ( | return ( | ||||
| <FilterCheckboxDropdown | <FilterCheckboxDropdown | ||||
| searchPlaceholder={t("filters.location.placeholder")} | searchPlaceholder={t("filters.location.placeholder")} | ||||
| icon={<LocationIcon />} | icon={<LocationIcon />} | ||||
| title={t("filters.location.title")} | title={t("filters.location.title")} | ||||
| setItemsSelected={filters.locations.setSelectedLocations} | setItemsSelected={filters.locations.setSelectedLocations} | ||||
| offers={props.offers} | |||||
| /> | /> | ||||
| ); | ); | ||||
| }); | }); | ||||
| LocationChoser.propTypes = { | LocationChoser.propTypes = { | ||||
| filters: PropTypes.any, | filters: PropTypes.any, | ||||
| offers: PropTypes.any, | |||||
| }; | }; | ||||
| export default LocationChoser; | export default LocationChoser; |
| disabled={isDisabled} | disabled={isDisabled} | ||||
| handleOpen={handleOpen} | handleOpen={handleOpen} | ||||
| firstOption={filters.subcategory.initialOption} | firstOption={filters.subcategory.initialOption} | ||||
| offers={props.offers} | |||||
| /> | /> | ||||
| ); | ); | ||||
| }); | }); | ||||
| categoryOpened: PropTypes.bool, | categoryOpened: PropTypes.bool, | ||||
| queryStringHook: PropTypes.any, | queryStringHook: PropTypes.any, | ||||
| isMyOffers: PropTypes.bool, | isMyOffers: PropTypes.bool, | ||||
| offers: PropTypes.any, | |||||
| }; | }; | ||||
| export default SubcategoryChoser; | export default SubcategoryChoser; |
| import { ContentContainer, FilterCardContainer } from "./FilterCard.styled"; | import { ContentContainer, FilterCardContainer } from "./FilterCard.styled"; | ||||
| import HeaderBack from "../../ItemDetails/Header/Header"; | import HeaderBack from "../../ItemDetails/Header/Header"; | ||||
| import FilterHeader from "./FilterHeader/FilterHeader"; | import FilterHeader from "./FilterHeader/FilterHeader"; | ||||
| import FilterFooter from "./FilterFooter/FilterFooter"; | |||||
| // import FilterFooter from "./FilterFooter/FilterFooter"; | |||||
| import CategoryChoser from "./Choser/CategoryChoser/CategoryChoser"; | import CategoryChoser from "./Choser/CategoryChoser/CategoryChoser"; | ||||
| import SubcategoryChoser from "./Choser/SubcategoryChoser/SubcategoryChoser"; | import SubcategoryChoser from "./Choser/SubcategoryChoser/SubcategoryChoser"; | ||||
| import LocationChoser from "./Choser/LocationChoser/LocationChoser"; | import LocationChoser from "./Choser/LocationChoser/LocationChoser"; | ||||
| <ContentContainer> | <ContentContainer> | ||||
| {/* Categories */} | {/* Categories */} | ||||
| <CategoryChoser filters={filters} ref={categoryRef} /> | |||||
| <CategoryChoser filters={filters} ref={categoryRef} offers={offers} /> | |||||
| {/* Subcategories */} | {/* Subcategories */} | ||||
| <SubcategoryChoser | <SubcategoryChoser | ||||
| ref={subcategoryRef} | ref={subcategoryRef} | ||||
| categoryOpened={categoryRef.current?.isOpened} | categoryOpened={categoryRef.current?.isOpened} | ||||
| isMyOffers={props.myOffers} | isMyOffers={props.myOffers} | ||||
| offers={offers} | |||||
| /> | /> | ||||
| {/* Locations */} | {/* Locations */} | ||||
| {!props.myOffers && ( | {!props.myOffers && ( | ||||
| <LocationChoser filters={filters} ref={locationRef} /> | |||||
| <LocationChoser filters={filters} ref={locationRef} offers={offers} /> | |||||
| )} | )} | ||||
| {/* Companies */} | {/* Companies */} | ||||
| {!props.myOffers && ( | {!props.myOffers && ( | ||||
| <CompanyChoser filters={filters} ref={companyRef} /> | |||||
| <CompanyChoser filters={filters} ref={companyRef} offers={offers} /> | |||||
| )} | )} | ||||
| </ContentContainer> | </ContentContainer> | ||||
| <FilterFooter | |||||
| {/* <FilterFooter | |||||
| toggleFilters={props.toggleFilters} | toggleFilters={props.toggleFilters} | ||||
| filters={offers} | filters={offers} | ||||
| closeAllSections={closeAllSections} | closeAllSections={closeAllSections} | ||||
| isMyOffers={props.myOffers} | isMyOffers={props.myOffers} | ||||
| /> | |||||
| /> */} | |||||
| </FilterCardContainer> | </FilterCardContainer> | ||||
| ); | ); | ||||
| }; | }; |
| const [isOpened, setIsOpened] = useState(false); | const [isOpened, setIsOpened] = useState(false); | ||||
| const handleDelete = (item) => { | const handleDelete = (item) => { | ||||
| props.setItemsSelected([...props.filters.filter((p) => p !== item)]); | props.setItemsSelected([...props.filters.filter((p) => p !== item)]); | ||||
| props.offers.applyFilters(); | |||||
| }; | }; | ||||
| const handleOpen = () => { | const handleOpen = () => { | ||||
| setIsOpened((prevState) => !prevState); | setIsOpened((prevState) => !prevState); | ||||
| open: PropTypes.bool, | open: PropTypes.bool, | ||||
| handleOpen: PropTypes.func, | handleOpen: PropTypes.func, | ||||
| companies: PropTypes.bool, | companies: PropTypes.bool, | ||||
| offers: PropTypes.any, | |||||
| }; | }; | ||||
| export default CheckboxDropdownList; | export default CheckboxDropdownList; |
| const [isOpened, setIsOpened] = useState(false); | const [isOpened, setIsOpened] = useState(false); | ||||
| const [toSearch, setToSearch] = useState(""); | const [toSearch, setToSearch] = useState(""); | ||||
| const { data } = props; | const { data } = props; | ||||
| console.log(props); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| setDataToShow([...data]); | setDataToShow([...data]); | ||||
| (p) => p?.city?.toString() !== item?.city?.toString() | (p) => p?.city?.toString() !== item?.city?.toString() | ||||
| ), | ), | ||||
| ]); | ]); | ||||
| props.offers.applyFilters(); | |||||
| } else { | } else { | ||||
| props.setItemsSelected([...props.filters, item]); | props.setItemsSelected([...props.filters, item]); | ||||
| props.offers.applyFilters(); | |||||
| } | } | ||||
| } | } | ||||
| }; | }; | ||||
| handleOpen={handleOpen} | handleOpen={handleOpen} | ||||
| setItemsSelected={props.setItemsSelected} | setItemsSelected={props.setItemsSelected} | ||||
| companies={props.companies} | companies={props.companies} | ||||
| offers={props.offers} | |||||
| > | > | ||||
| {(isOpened || props?.open) && | {(isOpened || props?.open) && | ||||
| dataToShow.map((item) => { | dataToShow.map((item) => { | ||||
| open: PropTypes.bool, | open: PropTypes.bool, | ||||
| handleOpen: PropTypes.func, | handleOpen: PropTypes.func, | ||||
| companies: PropTypes.bool, | companies: PropTypes.bool, | ||||
| offers: PropTypes.any, | |||||
| }; | }; | ||||
| FilterCheckboxDropdown.defaultProps = { | FilterCheckboxDropdown.defaultProps = { | ||||
| oneValueAllowed: false, | oneValueAllowed: false, |
| (p) => p?.companyName?.toString() !== item?.companyName?.toString() | (p) => p?.companyName?.toString() !== item?.companyName?.toString() | ||||
| ), | ), | ||||
| ]); | ]); | ||||
| props.offers.applyFilters(); | |||||
| } else { | } else { | ||||
| props.setItemsSelected([...props.filters, item]); | props.setItemsSelected([...props.filters, item]); | ||||
| props.offers.applyFilters(); | |||||
| } | } | ||||
| } | } | ||||
| }; | }; | ||||
| companies: PropTypes.bool, | companies: PropTypes.bool, | ||||
| letters: PropTypes.any, | letters: PropTypes.any, | ||||
| dataToShow: PropTypes.array, | dataToShow: PropTypes.array, | ||||
| offers: PropTypes.any, | |||||
| }; | }; | ||||
| FilterSmallDropdown.defaultProps = { | FilterSmallDropdown.defaultProps = { | ||||
| oneValueAllowed: false, | oneValueAllowed: false, |
| filters={props.filters} | filters={props.filters} | ||||
| setItemsSelected={props.setItemsSelected} | setItemsSelected={props.setItemsSelected} | ||||
| companies={props.companies} | companies={props.companies} | ||||
| offers={props.offers} | |||||
| /> | /> | ||||
| <FilterSmallDropdown | <FilterSmallDropdown | ||||
| letters={t("filters.company.secondSort")} | letters={t("filters.company.secondSort")} | ||||
| filters={props.filters} | filters={props.filters} | ||||
| setItemsSelected={props.setItemsSelected} | setItemsSelected={props.setItemsSelected} | ||||
| companies={props.companies} | companies={props.companies} | ||||
| offers={props.offers} | |||||
| /> | /> | ||||
| <FilterSmallDropdown | <FilterSmallDropdown | ||||
| letters={t("filters.company.thirdSort")} | letters={t("filters.company.thirdSort")} | ||||
| filters={props.filters} | filters={props.filters} | ||||
| setItemsSelected={props.setItemsSelected} | setItemsSelected={props.setItemsSelected} | ||||
| companies={props.companies} | companies={props.companies} | ||||
| offers={props.offers} | |||||
| /> | /> | ||||
| </> | </> | ||||
| )} | )} | ||||
| open: PropTypes.bool, | open: PropTypes.bool, | ||||
| handleOpen: PropTypes.func, | handleOpen: PropTypes.func, | ||||
| companies: PropTypes.bool, | companies: PropTypes.bool, | ||||
| offers: PropTypes.any, | |||||
| }; | }; | ||||
| FilterSubDropdown.defaultProps = { | FilterSubDropdown.defaultProps = { | ||||
| oneValueAllowed: false, | oneValueAllowed: false, |
| import useLocationsFilter from "./useLocationsFilter"; | import useLocationsFilter from "./useLocationsFilter"; | ||||
| import useSubcategoryFilter from "./useSubcategoryFilter"; | import useSubcategoryFilter from "./useSubcategoryFilter"; | ||||
| const useFilters = (clearAll = false) => { | |||||
| const useFilters = (clearAll = false, applyFilters) => { | |||||
| const category = useCategoryFilter(); | const category = useCategoryFilter(); | ||||
| const subcategory = useSubcategoryFilter(); | |||||
| const subcategory = useSubcategoryFilter(applyFilters); | |||||
| const locations = useLocationsFilter(); | const locations = useLocationsFilter(); | ||||
| const companies = useCompaniesFilter(); | const companies = useCompaniesFilter(); | ||||
| const useOffers = () => { | const useOffers = () => { | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const filters = useFilters(); | |||||
| const apply = () => { | |||||
| filters.apply(); | |||||
| const newQueryString = makeQueryStringHelper( | |||||
| filters, | |||||
| paging, | |||||
| search, | |||||
| sorting | |||||
| ); | |||||
| dispatch(setQueryString(convertQueryStringForBackend(newQueryString))); | |||||
| }; | |||||
| const filters = useFilters(false, apply); | |||||
| const queryStringHook = useQueryString(); | const queryStringHook = useQueryString(); | ||||
| const pinnedOffers = useSelector(selectPinnedOffers); | const pinnedOffers = useSelector(selectPinnedOffers); | ||||
| const offers = useSelector(selectOffers); | const offers = useSelector(selectOffers); | ||||
| } | } | ||||
| }, [filtersCleared]); | }, [filtersCleared]); | ||||
| const apply = () => { | |||||
| filters.apply(); | |||||
| const newQueryString = makeQueryStringHelper( | |||||
| filters, | |||||
| paging, | |||||
| search, | |||||
| sorting | |||||
| ); | |||||
| dispatch(setQueryString(convertQueryStringForBackend(newQueryString))); | |||||
| }; | |||||
| const applyFilters = () => { | const applyFilters = () => { | ||||
| setFiltersCleared(true); | setFiltersCleared(true); | ||||
| }; | }; |
| import { setFilteredSubcategory } from "../../store/actions/filters/filtersActions"; | import { setFilteredSubcategory } from "../../store/actions/filters/filtersActions"; | ||||
| import { selectSelectedSubcategory } from "../../store/selectors/filtersSelectors"; | import { selectSelectedSubcategory } from "../../store/selectors/filtersSelectors"; | ||||
| const useSubcategoryFilter = () => { | |||||
| const useSubcategoryFilter = (applyFilters) => { | |||||
| const selectedSubcategory = useSelector(selectSelectedSubcategory); | const selectedSubcategory = useSelector(selectSelectedSubcategory); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const initialOption = { | const initialOption = { | ||||
| if (selectedSubcategory) | if (selectedSubcategory) | ||||
| if ("_id" in selectedSubcategory) { | if ("_id" in selectedSubcategory) { | ||||
| setSelectedSubcategoryLocally(selectedSubcategory); | setSelectedSubcategoryLocally(selectedSubcategory); | ||||
| applyFilters(); | |||||
| } | } | ||||
| }, [selectedSubcategory]); | }, [selectedSubcategory]); | ||||
| } | } | ||||
| }, [initialOption]); | }, [initialOption]); | ||||
| const setSelectedSubcategory = (subcategory, immediateApply = false) => { | |||||
| const setSelectedSubcategory = (subcategory) => { | |||||
| setSelectedSubcategoryLocally(subcategory); | setSelectedSubcategoryLocally(subcategory); | ||||
| if (immediateApply) { | |||||
| dispatch(setFilteredSubcategory(subcategory)); | |||||
| } | |||||
| // if (immediateApply) { | |||||
| dispatch(setFilteredSubcategory(subcategory)); | |||||
| // } | |||||
| }; | }; | ||||
| const apply = () => { | const apply = () => { |