| import PropTypes from "prop-types"; | import PropTypes from "prop-types"; | ||||
| import { | import { | ||||
| CategoryCardContainer, | CategoryCardContainer, | ||||
| CategoryCardDetailsContainer, | |||||
| CategoryCardLeftContainer, | CategoryCardLeftContainer, | ||||
| CategoryCardRightContainer, | CategoryCardRightContainer, | ||||
| } from "./CategoryCard.styled"; | } from "./CategoryCard.styled"; | ||||
| <CategoryCardContainer> | <CategoryCardContainer> | ||||
| <CategoryCardLeftContainer> | <CategoryCardLeftContainer> | ||||
| <CategoryCardName categoryName={props?.category?.name} /> | <CategoryCardName categoryName={props?.category?.name} /> | ||||
| <CategoryDetail | |||||
| label={t("admin.categories.noOfOffers")} | |||||
| value={props?.category?.offerCount} | |||||
| /> | |||||
| {!props.hideSecondLabel && ( | |||||
| <CategoryCardDetailsContainer> | |||||
| <CategoryDetail | <CategoryDetail | ||||
| label={props?.secondLabel} | |||||
| value={props?.category?.subcategories?.length} | |||||
| label={t("admin.categories.noOfOffers")} | |||||
| value={props?.category?.offerCount} | |||||
| /> | /> | ||||
| )} | |||||
| {!props.hideSecondLabel && ( | |||||
| <CategoryDetail | |||||
| label={props?.secondLabel} | |||||
| value={props?.category?.subcategories?.length} | |||||
| /> | |||||
| )} | |||||
| </CategoryCardDetailsContainer> | |||||
| </CategoryCardLeftContainer> | </CategoryCardLeftContainer> | ||||
| <CategoryCardRightContainer> | <CategoryCardRightContainer> | ||||
| <CategoryRemoveButton /> | <CategoryRemoveButton /> |
| import { Box } from "@mui/material"; | import { Box } from "@mui/material"; | ||||
| import styled from "styled-components"; | import styled from "styled-components"; | ||||
| import selectedTheme from "../../../themes"; | |||||
| export const CategoryCardContainer = styled(Box)` | export const CategoryCardContainer = styled(Box)` | ||||
| background: white; | background: white; | ||||
| margin: 5px; | margin: 5px; | ||||
| margin-top: 13px; | margin-top: 13px; | ||||
| margin-bottom: 13px; | margin-bottom: 13px; | ||||
| border: 1px solid ${selectedTheme.colors.borderNormal}; | |||||
| border-radius: 4px; | |||||
| display: flex; | display: flex; | ||||
| flex-direction: row; | flex-direction: row; | ||||
| justify-content: space-between; | justify-content: space-between; | ||||
| position: relative; | |||||
| @media (max-width: 600px) { | |||||
| height: 102px; | |||||
| } | |||||
| `; | `; | ||||
| export const CategoryCardLeftContainer = styled(Box)` | export const CategoryCardLeftContainer = styled(Box)` | ||||
| display: flex; | display: flex; | ||||
| display: flex; | display: flex; | ||||
| flex-direction: row; | flex-direction: row; | ||||
| `; | `; | ||||
| export const CategoryCardDetailsContainer = styled(Box)` | |||||
| display: flex; | |||||
| flex-direction: row; | |||||
| @media (max-width: 600px) { | |||||
| position: absolute; | |||||
| bottom: 18px; | |||||
| left: 0; | |||||
| max-height: 16px; | |||||
| } | |||||
| `; |
| padding-top: 12px; | padding-top: 12px; | ||||
| color: ${selectedTheme.colors.primaryPurple}; | color: ${selectedTheme.colors.primaryPurple}; | ||||
| cursor: pointer; | cursor: pointer; | ||||
| @media (max-width: 600px) { | |||||
| font-size: 18px; | |||||
| padding: 0; | |||||
| } | |||||
| `; | `; |
| min-width: 150px; | min-width: 150px; | ||||
| text-align: center; | text-align: center; | ||||
| border-left: 1px solid ${hexToRGB(selectedTheme.colors.primaryText, 0.13)}; | border-left: 1px solid ${hexToRGB(selectedTheme.colors.primaryText, 0.13)}; | ||||
| @media (max-width: 600px) { | |||||
| margin: 0; | |||||
| min-width: 123px; | |||||
| &:nth-child(1) { | |||||
| border-left: 0; | |||||
| } | |||||
| &:nth-child(2) { | |||||
| padding-left: 18px; | |||||
| } | |||||
| } | |||||
| `; | `; | ||||
| export const CategoryDetailLabel = styled(Typography)` | export const CategoryDetailLabel = styled(Typography)` | ||||
| font-family: ${selectedTheme.fonts.textFont}; | font-family: ${selectedTheme.fonts.textFont}; | ||||
| letter-spacing: 0.01rem; | letter-spacing: 0.01rem; | ||||
| padding-top: 14px; | padding-top: 14px; | ||||
| padding-right: 3px; | padding-right: 3px; | ||||
| @media (max-width: 600px) { | |||||
| position: relative; | |||||
| bottom: 2.5px; | |||||
| padding-top: 0; | |||||
| } | |||||
| `; | `; | ||||
| export const CategoryDetailValue = styled(Typography)` | export const CategoryDetailValue = styled(Typography)` | ||||
| font-family: ${selectedTheme.fonts.textFont}; | font-family: ${selectedTheme.fonts.textFont}; | ||||
| line-height: 21px; | line-height: 21px; | ||||
| padding-top: 11px; | padding-top: 11px; | ||||
| color: ${selectedTheme.colors.primaryPurple}; | color: ${selectedTheme.colors.primaryPurple}; | ||||
| @media (max-width: 600px) { | |||||
| position: relative; | |||||
| bottom: 2.5px; | |||||
| padding: 0; | |||||
| font-size: 12px; | |||||
| font-weight: 600; | |||||
| } | |||||
| `; | `; |
| padding-top: 2px; | padding-top: 2px; | ||||
| text-align: center; | text-align: center; | ||||
| @media (max-width: 600px) { | @media (max-width: 600px) { | ||||
| width: 30px; | |||||
| height: 30px; | |||||
| top: 16px; | |||||
| right: 16px; | |||||
| width: 32px; | |||||
| height: 32px; | |||||
| top: 18px; | |||||
| right: 18px; | |||||
| margin-right: 0; | |||||
| padding: 0; | padding: 0; | ||||
| ${(props) => | ${(props) => | ||||
| props.vertical && | props.vertical && | ||||
| height: 16px; | height: 16px; | ||||
| position: relative; | position: relative; | ||||
| top: -3px; | top: -3px; | ||||
| left: -3.5px; | |||||
| left: -1.5px; | |||||
| } | } | ||||
| } | } | ||||
| `; | `; |
| padding-top: 2px; | padding-top: 2px; | ||||
| text-align: center; | text-align: center; | ||||
| @media (max-width: 600px) { | @media (max-width: 600px) { | ||||
| width: 30px; | |||||
| height: 30px; | |||||
| top: 16px; | |||||
| right: 16px; | |||||
| width: 32px; | |||||
| height: 32px; | |||||
| top: 18px; | |||||
| right: 12px; | |||||
| padding: 0; | padding: 0; | ||||
| ${(props) => | ${(props) => | ||||
| props.vertical && | props.vertical && | ||||
| height: 16px; | height: 16px; | ||||
| position: relative; | position: relative; | ||||
| top: -3px; | top: -3px; | ||||
| left: -3.5px; | |||||
| left: -1.5px; | |||||
| } | } | ||||
| } | } | ||||
| `; | `; |
| import UserButton from "./UserButton/UserButton"; | import UserButton from "./UserButton/UserButton"; | ||||
| import LoginButton from "./LoginButton/LoginButton"; | import LoginButton from "./LoginButton/LoginButton"; | ||||
| import RegisterButton from "./RegisterButton/RegisterButton"; | import RegisterButton from "./RegisterButton/RegisterButton"; | ||||
| import useIsMobile from "../../hooks/useIsMobile"; | |||||
| const Header = () => { | const Header = () => { | ||||
| const [showCreateOfferModal, setShowCreateOfferModal] = useState(false); | const [showCreateOfferModal, setShowCreateOfferModal] = useState(false); | ||||
| const drawerRef = useRef(null); | const drawerRef = useRef(null); | ||||
| const [shouldShow, setShouldShow] = useState(true); | const [shouldShow, setShouldShow] = useState(true); | ||||
| const routeMatch = useRouteMatch(); | const routeMatch = useRouteMatch(); | ||||
| const { isMobile } = useIsMobile(); | |||||
| // Dont show header on auth routes(login, register, etc.) and admin routes | // Dont show header on auth routes(login, register, etc.) and admin routes | ||||
| useEffect(() => { | useEffect(() => { | ||||
| if (isAuthRoute() || isAdminRoute()) setShouldShow(false); | |||||
| if (isAuthRoute() || (isAdminRoute && !isMobile)) setShouldShow(false); | |||||
| else setShouldShow(true); | else setShouldShow(true); | ||||
| }, [routeMatch]); | |||||
| }, [routeMatch, isMobile]); | |||||
| // Fetch mine profile on loading home page | // Fetch mine profile on loading home page | ||||
| useEffect(() => { | useEffect(() => { | ||||
| } | } | ||||
| // Handling search when user is on marketplace and when he is not | // Handling search when user is on marketplace and when he is not | ||||
| const handleSearch = (value) => { | const handleSearch = (value) => { | ||||
| if (!routeMatches(HOME_PAGE) && !routeMatches(BASE_PAGE)) { | |||||
| const newQueryString = new URLSearchParams({ search: value }); | |||||
| history.push({ | |||||
| pathname: HOME_PAGE, | |||||
| search: newQueryString.toString(), | |||||
| }); | |||||
| if (isAdminRoute()) { | |||||
| console.log("admin"); | |||||
| search.setSearchStringManually(value); | |||||
| } else { | } else { | ||||
| search.searchOffersImmediately(value); | |||||
| if (!routeMatches(HOME_PAGE) && !routeMatches(BASE_PAGE)) { | |||||
| const newQueryString = new URLSearchParams({ search: value }); | |||||
| history.push({ | |||||
| pathname: HOME_PAGE, | |||||
| search: newQueryString.toString(), | |||||
| }); | |||||
| } else { | |||||
| search.searchOffersImmediately(value); | |||||
| } | |||||
| } | } | ||||
| }; | }; | ||||
| }; | }; | ||||
| if (!shouldShow) { | if (!shouldShow) { | ||||
| return (<></>) | |||||
| return <></>; | |||||
| } | } | ||||
| return ( | return ( | ||||
| Header.propTypes = { | Header.propTypes = { | ||||
| isGrid: PropTypes.bool, | isGrid: PropTypes.bool, | ||||
| showModalHandler: PropTypes.func, | showModalHandler: PropTypes.func, | ||||
| manualSearch: PropTypes.func, | |||||
| }; | }; | ||||
| export default Header; | export default Header; |
| </HeaderTitleText> | </HeaderTitleText> | ||||
| </HeaderTitleContainer> | </HeaderTitleContainer> | ||||
| ) : ( | ) : ( | ||||
| <ButtonContainer onClick={goBack}> | |||||
| <ArrowButton side={"left"}></ArrowButton> | |||||
| <HeaderText>{t("messages.goBack")}</HeaderText> | |||||
| </ButtonContainer> | |||||
| !props.hideBackButton && ( | |||||
| <ButtonContainer onClick={goBack}> | |||||
| <ArrowButton side={"left"}></ArrowButton> | |||||
| <HeaderText>{t("messages.goBack")}</HeaderText> | |||||
| </ButtonContainer> | |||||
| ) | |||||
| )} | )} | ||||
| </> | </> | ||||
| )} | )} | ||||
| </HeaderContainer> | </HeaderContainer> | ||||
| {isMobile && ( | {isMobile && ( | ||||
| <PageTitleContainer> | <PageTitleContainer> | ||||
| <SwapsIcon /> | |||||
| {props.users ? ( | |||||
| <UserIcon /> | |||||
| ) : props.categories ? ( | |||||
| <CategoryIcon /> | |||||
| ) : ( | |||||
| <SwapsIcon /> | |||||
| )} | |||||
| <SwapsTitle> | <SwapsTitle> | ||||
| {props?.myOffers ? t("header.myOffers") : t("offer.offers")} | |||||
| {props.users | |||||
| ? t("admin.users.headerTitle") | |||||
| : props.categories | |||||
| ? t("admin.categories.headerTitle") | |||||
| : props?.myOffers | |||||
| ? t("header.myOffers") | |||||
| : t("offer.offers")} | |||||
| </SwapsTitle> | </SwapsTitle> | ||||
| </PageTitleContainer> | </PageTitleContainer> | ||||
| )} | )} | ||||
| categories: PropTypes.bool, | categories: PropTypes.bool, | ||||
| hideGrid: PropTypes.bool, | hideGrid: PropTypes.bool, | ||||
| className: PropTypes.string, | className: PropTypes.string, | ||||
| hideBackButton: PropTypes.bool, | |||||
| }; | }; | ||||
| Header.defaultProps = { | Header.defaultProps = { | ||||
| isGrid: false, | isGrid: false, |
| position: relative; | position: relative; | ||||
| top: 4px; | top: 4px; | ||||
| right: 2px; | right: 2px; | ||||
| ` | |||||
| `; | |||||
| export const PageTitleContainer = styled(Box)` | export const PageTitleContainer = styled(Box)` | ||||
| position: relative; | position: relative; | ||||
| left: 6px; | left: 6px; | ||||
| margin-top: 36px; | margin-top: 36px; | ||||
| width: 100px; | width: 100px; | ||||
| @media (max-width: 600px) { | |||||
| & svg { | |||||
| width: 12px; | |||||
| height: 12px; | |||||
| top: 2px; | |||||
| } | |||||
| } | |||||
| `; | `; | ||||
| export const SwapsIcon = styled(RefreshIcon)` | export const SwapsIcon = styled(RefreshIcon)` | ||||
| width: 12px; | width: 12px; |
| const handleSearch = () => { | const handleSearch = () => { | ||||
| if (props.isAdmin) { | if (props.isAdmin) { | ||||
| console.log(searchRef.current.value); | console.log(searchRef.current.value); | ||||
| search.searchOffersImmediately(searchRef.current.value); | |||||
| if (props.handleSearch) props.handleSearch(searchRef.current.value); | |||||
| else search.searchOffersImmediately(searchRef.current.value); | |||||
| } else { | } else { | ||||
| props.searchMyOffers(searchRef.current.value); | props.searchMyOffers(searchRef.current.value); | ||||
| props.handleSearch(); | props.handleSearch(); |
| import { useHistory } from "react-router-dom"; | import { useHistory } from "react-router-dom"; | ||||
| import { BASE_PAGE, HOME_PAGE } from "../../constants/pages"; | import { BASE_PAGE, HOME_PAGE } from "../../constants/pages"; | ||||
| import { KEY_SEARCH } from "../../constants/queryStringConstants"; | import { KEY_SEARCH } from "../../constants/queryStringConstants"; | ||||
| import { setSearchString } from "../../store/actions/filters/filtersActions"; | |||||
| import { selectSearchString } from "../../store/selectors/filtersSelectors"; | |||||
| import { | |||||
| setManualSearchString, | |||||
| setSearchString, | |||||
| } from "../../store/actions/filters/filtersActions"; | |||||
| import { | |||||
| selectManualSearchString, | |||||
| selectSearchString, | |||||
| } from "../../store/selectors/filtersSelectors"; | |||||
| import { routeMatches } from "../../util/helpers/routeHelpers"; | import { routeMatches } from "../../util/helpers/routeHelpers"; | ||||
| const useSearch = (applyAllFilters) => { | const useSearch = (applyAllFilters) => { | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const searchString = useSelector(selectSearchString); | const searchString = useSelector(selectSearchString); | ||||
| const history = useHistory(); | const history = useHistory(); | ||||
| const manualSearchString = useSelector(selectManualSearchString); | |||||
| // On every global change of search string, new request to backend should be sent | // On every global change of search string, new request to backend should be sent | ||||
| useEffect(() => { | useEffect(() => { | ||||
| }, [searchStringLocally]); | }, [searchStringLocally]); | ||||
| const searchOffers = (searchValue) => { | const searchOffers = (searchValue) => { | ||||
| console.log('searchoff') | |||||
| setIsInitiallyLoaded(true); | setIsInitiallyLoaded(true); | ||||
| setSearchStringLocally(searchValue); | setSearchStringLocally(searchValue); | ||||
| }; | }; | ||||
| const searchOffersImmediately = (searchValue) => { | const searchOffersImmediately = (searchValue) => { | ||||
| console.log('searchoffersimm'); | |||||
| setIsInitiallyLoaded(true); | setIsInitiallyLoaded(true); | ||||
| searchOffers(searchValue); | searchOffers(searchValue); | ||||
| applyAllFilters(); | applyAllFilters(); | ||||
| }; | }; | ||||
| const setSearchStringManually = (searchValue) => { | |||||
| dispatch(setManualSearchString(searchValue)); | |||||
| }; | |||||
| const clear = () => { | const clear = () => { | ||||
| setSearchStringLocally(""); | setSearchStringLocally(""); | ||||
| }; | }; | ||||
| return { | return { | ||||
| searchOffers, | searchOffers, | ||||
| setSearchStringLocally, | setSearchStringLocally, | ||||
| setSearchStringManually, | |||||
| searchOffersImmediately, | searchOffersImmediately, | ||||
| searchStringLocally, | searchStringLocally, | ||||
| searchString, | searchString, | ||||
| manualSearchString, | |||||
| clear, | clear, | ||||
| }; | }; | ||||
| }; | }; |
| AdminCategoriesPageContainer, | AdminCategoriesPageContainer, | ||||
| AdminCategoriesSearchField, | AdminCategoriesSearchField, | ||||
| } from "./AdminCategoriesPage.styled"; | } from "./AdminCategoriesPage.styled"; | ||||
| import { selectManualSearchString } from "../../store/selectors/filtersSelectors"; | |||||
| import { useMemo } from "react"; | |||||
| import { setManualSearchString } from "../../store/actions/filters/filtersActions"; | |||||
| const AdminCategoriesPage = () => { | const AdminCategoriesPage = () => { | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const categories = useSelector(selectCategories); | const categories = useSelector(selectCategories); | ||||
| const manualSearchString = useSelector(selectManualSearchString); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| dispatch(fetchCategories()); | dispatch(fetchCategories()); | ||||
| }, []); | }, []); | ||||
| const handleSearch = (value) => { | |||||
| console.log(value); | |||||
| dispatch(setManualSearchString(value)); | |||||
| }; | |||||
| const categoriesToShow = useMemo(() => { | |||||
| if (categories) { | |||||
| console.log(categories); | |||||
| console.log(manualSearchString); | |||||
| if (manualSearchString) | |||||
| return categories.filter((item) => | |||||
| item.name.toLowerCase().includes(manualSearchString.toLowerCase()) | |||||
| ); | |||||
| return categories; | |||||
| } | |||||
| return []; | |||||
| }, [categories, manualSearchString]); | |||||
| return ( | return ( | ||||
| <AdminCategoriesPageContainer> | <AdminCategoriesPageContainer> | ||||
| <AdminCategoriesSearchField | <AdminCategoriesSearchField | ||||
| isAdmin | isAdmin | ||||
| handleSearch={handleSearch} | |||||
| placeholder={t("admin.categories.placeholder")} | placeholder={t("admin.categories.placeholder")} | ||||
| /> | /> | ||||
| <AdminCategoriesHeader myOffers categories hideGrid isAdmin /> | |||||
| {categories.map((category) => ( | |||||
| <AdminCategoriesHeader | |||||
| myOffers | |||||
| categories | |||||
| hideGrid | |||||
| isAdmin | |||||
| hideBackButton | |||||
| /> | |||||
| {categoriesToShow.map((category) => ( | |||||
| <CategoryCard | <CategoryCard | ||||
| key={category._id} | key={category._id} | ||||
| category={category} | category={category} |
| export const AdminCategoriesPageContainer = styled(Box)` | export const AdminCategoriesPageContainer = styled(Box)` | ||||
| padding: 60px; | padding: 60px; | ||||
| @media (max-width: 600px) { | |||||
| padding: 18px; | |||||
| position: relative; | |||||
| top: 65px; | |||||
| } | |||||
| `; | `; | ||||
| export const AdminCategoriesHeader = styled(Header)` | export const AdminCategoriesHeader = styled(Header)` | ||||
| /* top: 40px; */ | |||||
| top: 0; | |||||
| ` | |||||
| /* top: 40px; */ | |||||
| top: 0; | |||||
| @media (max-width: 600px) { | |||||
| top: -10px; | |||||
| & div { | |||||
| margin-top: 0; | |||||
| } | |||||
| & div div:nth-child(1) { | |||||
| top: 22px; | |||||
| } | |||||
| } | |||||
| `; | |||||
| export const AdminCategoriesSearchField = styled(SearchField)` | export const AdminCategoriesSearchField = styled(SearchField)` | ||||
| top: -15px; | |||||
| ` | |||||
| top: -15px; | |||||
| @media (max-width: 600px) { | |||||
| display: none; | |||||
| } | |||||
| `; |
| import { createClearType, createSetType } from "../actionHelpers" | |||||
| import { createClearType, createSetType } from "../actionHelpers"; | |||||
| const FILTERS_SCOPE = "FILTERS" | |||||
| const FILTERS_SCOPE = "FILTERS"; | |||||
| export const SET_FILTERS = createSetType(FILTERS_SCOPE); | export const SET_FILTERS = createSetType(FILTERS_SCOPE); | ||||
| export const CLEAR_FILTERS = createClearType(FILTERS_SCOPE); | export const CLEAR_FILTERS = createClearType(FILTERS_SCOPE); | ||||
| export const SET_CATEGORY = createSetType("FILTERS_SET_CATEGORY"); | export const SET_CATEGORY = createSetType("FILTERS_SET_CATEGORY"); | ||||
| export const SET_QUERY_STRING = createSetType("FILTERS_SET_QUERY_STRING"); | export const SET_QUERY_STRING = createSetType("FILTERS_SET_QUERY_STRING"); | ||||
| export const SET_HEADER_STRING = createSetType("FILTERS_SET_HEADER_STRING"); | export const SET_HEADER_STRING = createSetType("FILTERS_SET_HEADER_STRING"); | ||||
| export const SET_SEARCH_STRING = createSetType("FILTERS_SET_SEARCH"); | export const SET_SEARCH_STRING = createSetType("FILTERS_SET_SEARCH"); | ||||
| export const SET_MANUAL_SEARCH_STRING = createSetType( | |||||
| "FILTERS_SET_MANUAL_SEARCH_STRING" | |||||
| ); |
| import { CLEAR_FILTERS, SET_CATEGORY, SET_FILTERS, SET_HEADER_STRING, SET_IS_APPLIED, SET_LOCATIONS, SET_QUERY_STRING, SET_SEARCH_STRING, SET_SORT_OPTION, SET_SUBCATEGORY } from "./filtersActionConstants"; | |||||
| import { | |||||
| CLEAR_FILTERS, | |||||
| SET_CATEGORY, | |||||
| SET_FILTERS, | |||||
| SET_HEADER_STRING, | |||||
| SET_IS_APPLIED, | |||||
| SET_LOCATIONS, | |||||
| SET_MANUAL_SEARCH_STRING, | |||||
| SET_QUERY_STRING, | |||||
| SET_SEARCH_STRING, | |||||
| SET_SORT_OPTION, | |||||
| SET_SUBCATEGORY, | |||||
| } from "./filtersActionConstants"; | |||||
| export const setFilters = (payload) => ({ | export const setFilters = (payload) => ({ | ||||
| type: SET_FILTERS, | |||||
| payload, | |||||
| }) | |||||
| type: SET_FILTERS, | |||||
| payload, | |||||
| }); | |||||
| export const clearFilters = () => ({ | export const clearFilters = () => ({ | ||||
| type: CLEAR_FILTERS | |||||
| }) | |||||
| type: CLEAR_FILTERS, | |||||
| }); | |||||
| export const setFilteredCategory = (payload) => ({ | export const setFilteredCategory = (payload) => ({ | ||||
| type: SET_CATEGORY, | |||||
| payload | |||||
| }) | |||||
| type: SET_CATEGORY, | |||||
| payload, | |||||
| }); | |||||
| export const setFilteredSubcategory = (payload) => ({ | export const setFilteredSubcategory = (payload) => ({ | ||||
| type: SET_SUBCATEGORY, | |||||
| payload | |||||
| }) | |||||
| type: SET_SUBCATEGORY, | |||||
| payload, | |||||
| }); | |||||
| export const setManualSearchString = (payload) => ({ | |||||
| type: SET_MANUAL_SEARCH_STRING, | |||||
| payload, | |||||
| }); | |||||
| export const setFilteredLocations = (payload) => ({ | export const setFilteredLocations = (payload) => ({ | ||||
| type: SET_LOCATIONS, | |||||
| payload | |||||
| }) | |||||
| type: SET_LOCATIONS, | |||||
| payload, | |||||
| }); | |||||
| export const setFilteredSortOption = (payload) => ({ | export const setFilteredSortOption = (payload) => ({ | ||||
| type: SET_SORT_OPTION, | |||||
| payload | |||||
| }) | |||||
| type: SET_SORT_OPTION, | |||||
| payload, | |||||
| }); | |||||
| export const setIsAppliedStatus = (payload) => ({ | export const setIsAppliedStatus = (payload) => ({ | ||||
| type: SET_IS_APPLIED, | |||||
| payload, | |||||
| }) | |||||
| type: SET_IS_APPLIED, | |||||
| payload, | |||||
| }); | |||||
| export const setQueryString = (payload) => ({ | export const setQueryString = (payload) => ({ | ||||
| type: SET_QUERY_STRING, | |||||
| payload, | |||||
| }) | |||||
| type: SET_QUERY_STRING, | |||||
| payload, | |||||
| }); | |||||
| export const setHeaderString = (payload) => ({ | export const setHeaderString = (payload) => ({ | ||||
| type: SET_HEADER_STRING, | |||||
| payload | |||||
| }) | |||||
| type: SET_HEADER_STRING, | |||||
| payload, | |||||
| }); | |||||
| export const setSearchString = (payload) => ({ | export const setSearchString = (payload) => ({ | ||||
| type: SET_SEARCH_STRING, | |||||
| payload | |||||
| }) | |||||
| type: SET_SEARCH_STRING, | |||||
| payload, | |||||
| }); |
| SET_HEADER_STRING, | SET_HEADER_STRING, | ||||
| SET_IS_APPLIED, | SET_IS_APPLIED, | ||||
| SET_LOCATIONS, | SET_LOCATIONS, | ||||
| SET_MANUAL_SEARCH_STRING, | |||||
| SET_SEARCH_STRING, | SET_SEARCH_STRING, | ||||
| SET_SORT_OPTION, | SET_SORT_OPTION, | ||||
| SET_SUBCATEGORY, | SET_SUBCATEGORY, | ||||
| categoryString: "", | categoryString: "", | ||||
| subcategoryString: "", | subcategoryString: "", | ||||
| locationsString: "", | locationsString: "", | ||||
| text: "" | |||||
| text: "", | |||||
| }, | }, | ||||
| searchString: "" | |||||
| searchString: "", | |||||
| manualSearchString: "", | |||||
| }, | }, | ||||
| }; | }; | ||||
| [SET_IS_APPLIED]: setIsAppliedStatus, | [SET_IS_APPLIED]: setIsAppliedStatus, | ||||
| [SET_HEADER_STRING]: setHeaderString, | [SET_HEADER_STRING]: setHeaderString, | ||||
| [SET_SEARCH_STRING]: setSearchString, | [SET_SEARCH_STRING]: setSearchString, | ||||
| [SET_MANUAL_SEARCH_STRING]: setManualSearchString, | |||||
| }, | }, | ||||
| initialState | initialState | ||||
| ); | ); | ||||
| function setManualSearchString(state, { payload }) { | |||||
| return { | |||||
| ...state, | |||||
| filters: { | |||||
| ...state.filters, | |||||
| manualSearchString: payload, | |||||
| }, | |||||
| }; | |||||
| } | |||||
| function setFilters(state, { payload }) { | function setFilters(state, { payload }) { | ||||
| return { | return { | ||||
| ...state, | ...state, | ||||
| }, | }, | ||||
| }; | }; | ||||
| } | } | ||||
| function setFilteredSortOption(state, {payload}) { | |||||
| function setFilteredSortOption(state, { payload }) { | |||||
| return { | return { | ||||
| ...state, | ...state, | ||||
| filters: { | filters: { | ||||
| ...state.filters, | ...state.filters, | ||||
| sortOption: payload, | sortOption: payload, | ||||
| } | |||||
| } | |||||
| }, | |||||
| }; | |||||
| } | } | ||||
| function setIsAppliedStatus(state, {payload}) { | |||||
| function setIsAppliedStatus(state, { payload }) { | |||||
| return { | return { | ||||
| ...state, | ...state, | ||||
| filters: { | filters: { | ||||
| ...state.filters, | ...state.filters, | ||||
| isApplied: payload, | isApplied: payload, | ||||
| } | |||||
| } | |||||
| }, | |||||
| }; | |||||
| } | } | ||||
| function setHeaderString(state, {payload}) { | |||||
| function setHeaderString(state, { payload }) { | |||||
| return { | return { | ||||
| ...state, | ...state, | ||||
| filters: { | filters: { | ||||
| ...state.filters, | ...state.filters, | ||||
| headerString: payload | |||||
| } | |||||
| } | |||||
| headerString: payload, | |||||
| }, | |||||
| }; | |||||
| } | } | ||||
| function setSearchString(state, {payload}) { | |||||
| function setSearchString(state, { payload }) { | |||||
| return { | return { | ||||
| ...state, | ...state, | ||||
| filters: { | filters: { | ||||
| ...state.filters, | ...state.filters, | ||||
| searchString: payload | |||||
| } | |||||
| } | |||||
| searchString: payload, | |||||
| }, | |||||
| }; | |||||
| } | } |
| import { createSelector } from 'reselect'; | |||||
| import { createSelector } from "reselect"; | |||||
| const filtersSelector = (state) => state.filters; | const filtersSelector = (state) => state.filters; | ||||
| export const selectFilters = createSelector( | export const selectFilters = createSelector( | ||||
| filtersSelector, | filtersSelector, | ||||
| (state) => state.filters, | |||||
| (state) => state.filters | |||||
| ); | ); | ||||
| export const selectSelectedCategory = createSelector( | export const selectSelectedCategory = createSelector( | ||||
| filtersSelector, | filtersSelector, | ||||
| (state => state.filters.category) | |||||
| ) | |||||
| (state) => state.filters.category | |||||
| ); | |||||
| export const selectSelectedSubcategory = createSelector( | export const selectSelectedSubcategory = createSelector( | ||||
| filtersSelector, | filtersSelector, | ||||
| (state) => state.filters.subcategory | (state) => state.filters.subcategory | ||||
| ) | |||||
| ); | |||||
| export const selectSelectedLocations = createSelector( | export const selectSelectedLocations = createSelector( | ||||
| filtersSelector, | filtersSelector, | ||||
| (state) => state.filters.locations | (state) => state.filters.locations | ||||
| ) | |||||
| ); | |||||
| export const selectSelectedSortOption = createSelector( | export const selectSelectedSortOption = createSelector( | ||||
| filtersSelector, | filtersSelector, | ||||
| (state) => state.filters.sortOption | (state) => state.filters.sortOption | ||||
| ) | |||||
| ); | |||||
| export const selectAppliedStatus = createSelector( | export const selectAppliedStatus = createSelector( | ||||
| filtersSelector, | filtersSelector, | ||||
| (state) => state.filters.isApplied | (state) => state.filters.isApplied | ||||
| ) | |||||
| ); | |||||
| export const selectHeaderString = createSelector( | export const selectHeaderString = createSelector( | ||||
| filtersSelector, | filtersSelector, | ||||
| (state) => state.filters.headerString | (state) => state.filters.headerString | ||||
| ) | |||||
| ); | |||||
| export const selectSearchString = createSelector( | export const selectSearchString = createSelector( | ||||
| filtersSelector, | filtersSelector, | ||||
| (state) => state.filters.searchString, | |||||
| ) | |||||
| (state) => state.filters.searchString | |||||
| ); | |||||
| export const selectManualSearchString = createSelector( | |||||
| filtersSelector, | |||||
| (state) => state.filters.manualSearchString | |||||
| ); |