filtersMenu render refactor
This commit is contained in:
parent
dcbbf1ccb6
commit
39f1cc68f3
@ -3,7 +3,6 @@ import { Body, H1 } from '../../utils/fonts';
|
|||||||
import { FlexColumn, FlexRow, Svg } from '../../utils/containers';
|
import { FlexColumn, FlexRow, Svg } from '../../utils/containers';
|
||||||
import Search from '../../components/generic/Search';
|
import Search from '../../components/generic/Search';
|
||||||
import Pager from '../../components/generic/Pager';
|
import Pager from '../../components/generic/Pager';
|
||||||
import FiltersMenu from '../../components/challenges_list/FiltersMenu';
|
|
||||||
import challengeSearchQueryHandler from './challengeSearchQueryHandler';
|
import challengeSearchQueryHandler from './challengeSearchQueryHandler';
|
||||||
import renderChallenges from './renderChallenges';
|
import renderChallenges from './renderChallenges';
|
||||||
import Media from 'react-media';
|
import Media from 'react-media';
|
||||||
@ -13,6 +12,8 @@ import getChallenges from '../../api/getChallenges';
|
|||||||
import { CALC_PAGES, CHALLENGES_STATUS_FILTER } from '../../utils/globals';
|
import { CALC_PAGES, CHALLENGES_STATUS_FILTER } from '../../utils/globals';
|
||||||
import Loading from '../../components/generic/Loading';
|
import Loading from '../../components/generic/Loading';
|
||||||
import ChallengesStyle from './ChallengesStyle';
|
import ChallengesStyle from './ChallengesStyle';
|
||||||
|
import FiltersMenu from '../../components/challenges_list/FiltersMenu';
|
||||||
|
import statusFilter from './statusFilter';
|
||||||
|
|
||||||
const Challenges = () => {
|
const Challenges = () => {
|
||||||
const [pageNr, setPageNr] = React.useState(1);
|
const [pageNr, setPageNr] = React.useState(1);
|
||||||
@ -29,6 +30,10 @@ const Challenges = () => {
|
|||||||
challengesRequest();
|
challengesRequest();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
statusFilter(status, challenges, setChallenges);
|
||||||
|
}, [challenges, status]);
|
||||||
|
|
||||||
const challengesRequest = () => {
|
const challengesRequest = () => {
|
||||||
getChallenges(setChallengesFromAPI);
|
getChallenges(setChallengesFromAPI);
|
||||||
getChallenges(setChallenges, setLoading);
|
getChallenges(setChallenges, setLoading);
|
||||||
@ -62,12 +67,37 @@ const Challenges = () => {
|
|||||||
setFiltersMenu(newFiltersMenu);
|
setFiltersMenu(newFiltersMenu);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const filtersMenuRender = (
|
||||||
|
translateX = '0',
|
||||||
|
opacity = '1',
|
||||||
|
transBackDisplay = 'none'
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
<FiltersMenu
|
||||||
|
toggleFiltersMenu={toggleFiltersMenu}
|
||||||
|
sortByHandler={setSortBy}
|
||||||
|
statusHandler={setStatus}
|
||||||
|
challengeTypeHandler={setChallengeType}
|
||||||
|
commercialHandler={setCommercial}
|
||||||
|
sortBy={sortBy}
|
||||||
|
status={status}
|
||||||
|
challengeType={challengeType}
|
||||||
|
commercial={commercial}
|
||||||
|
translateX={translateX}
|
||||||
|
opacity={opacity}
|
||||||
|
transBackDisplay={transBackDisplay}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const mobileRender = () => {
|
const mobileRender = () => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{filtersMenuRender(
|
||||||
|
filtersMenu ? '0' : '100vw',
|
||||||
|
filtersMenu ? '1' : '0'
|
||||||
|
)}
|
||||||
<FiltersMenu
|
<FiltersMenu
|
||||||
translateX={filtersMenu ? '0' : '100vw'}
|
|
||||||
opacity={filtersMenu ? '1' : '0'}
|
|
||||||
toggleFiltersMenu={toggleFiltersMenu}
|
toggleFiltersMenu={toggleFiltersMenu}
|
||||||
sortByHandler={setSortBy}
|
sortByHandler={setSortBy}
|
||||||
statusHandler={setStatus}
|
statusHandler={setStatus}
|
||||||
@ -77,6 +107,8 @@ const Challenges = () => {
|
|||||||
status={status}
|
status={status}
|
||||||
challengeType={challengeType}
|
challengeType={challengeType}
|
||||||
commercial={commercial}
|
commercial={commercial}
|
||||||
|
translateX={filtersMenu ? '0' : '100vw'}
|
||||||
|
opacity={filtersMenu ? '1' : '0'}
|
||||||
/>
|
/>
|
||||||
<ChallengesStyle as="main" id="start">
|
<ChallengesStyle as="main" id="start">
|
||||||
<FlexColumn className="ChallengesStyle__page-container">
|
<FlexColumn className="ChallengesStyle__page-container">
|
||||||
@ -110,18 +142,7 @@ const Challenges = () => {
|
|||||||
const desktopRender = () => {
|
const desktopRender = () => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FiltersMenu
|
{filtersMenuRender()}
|
||||||
toggleFiltersMenu={toggleFiltersMenu}
|
|
||||||
transBackDisplay="none"
|
|
||||||
sortByHandler={setSortBy}
|
|
||||||
statusHandler={setStatus}
|
|
||||||
challengeTypeHandler={setChallengeType}
|
|
||||||
commercialHandler={setCommercial}
|
|
||||||
sortBy={sortBy}
|
|
||||||
status={status}
|
|
||||||
challengeType={challengeType}
|
|
||||||
commercial={commercial}
|
|
||||||
/>
|
|
||||||
<ChallengesStyle as="main" id="start">
|
<ChallengesStyle as="main" id="start">
|
||||||
<FlexColumn className="ChallengesStyle__page-container">
|
<FlexColumn className="ChallengesStyle__page-container">
|
||||||
<FlexRow className="ChallengesStyle__page-header-container">
|
<FlexRow className="ChallengesStyle__page-header-container">
|
||||||
|
@ -18,7 +18,7 @@ const ChallengesGrid = styled(Grid)`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const renderChallenges = (pageNr, challenges) => {
|
const renderChallenges = (pageNr, challenges, statusFilter) => {
|
||||||
const n = (pageNr - 1) * ELEMENTS_PER_PAGE;
|
const n = (pageNr - 1) * ELEMENTS_PER_PAGE;
|
||||||
if (challenges && challenges !== []) {
|
if (challenges && challenges !== []) {
|
||||||
return (
|
return (
|
||||||
|
5
src/pages/Challanges/statusFilter.js
Normal file
5
src/pages/Challanges/statusFilter.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
const statusFilter = (status, challenges, setChallenges) => {
|
||||||
|
let result = challenges;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default statusFilter;
|
Loading…
Reference in New Issue
Block a user