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 Search from '../../components/generic/Search';
|
||||
import Pager from '../../components/generic/Pager';
|
||||
import FiltersMenu from '../../components/challenges_list/FiltersMenu';
|
||||
import challengeSearchQueryHandler from './challengeSearchQueryHandler';
|
||||
import renderChallenges from './renderChallenges';
|
||||
import Media from 'react-media';
|
||||
@ -13,6 +12,8 @@ import getChallenges from '../../api/getChallenges';
|
||||
import { CALC_PAGES, CHALLENGES_STATUS_FILTER } from '../../utils/globals';
|
||||
import Loading from '../../components/generic/Loading';
|
||||
import ChallengesStyle from './ChallengesStyle';
|
||||
import FiltersMenu from '../../components/challenges_list/FiltersMenu';
|
||||
import statusFilter from './statusFilter';
|
||||
|
||||
const Challenges = () => {
|
||||
const [pageNr, setPageNr] = React.useState(1);
|
||||
@ -29,6 +30,10 @@ const Challenges = () => {
|
||||
challengesRequest();
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
statusFilter(status, challenges, setChallenges);
|
||||
}, [challenges, status]);
|
||||
|
||||
const challengesRequest = () => {
|
||||
getChallenges(setChallengesFromAPI);
|
||||
getChallenges(setChallenges, setLoading);
|
||||
@ -62,12 +67,13 @@ const Challenges = () => {
|
||||
setFiltersMenu(newFiltersMenu);
|
||||
};
|
||||
|
||||
const mobileRender = () => {
|
||||
const filtersMenuRender = (
|
||||
translateX = '0',
|
||||
opacity = '1',
|
||||
transBackDisplay = 'none'
|
||||
) => {
|
||||
return (
|
||||
<>
|
||||
<FiltersMenu
|
||||
translateX={filtersMenu ? '0' : '100vw'}
|
||||
opacity={filtersMenu ? '1' : '0'}
|
||||
toggleFiltersMenu={toggleFiltersMenu}
|
||||
sortByHandler={setSortBy}
|
||||
statusHandler={setStatus}
|
||||
@ -77,6 +83,32 @@ const Challenges = () => {
|
||||
status={status}
|
||||
challengeType={challengeType}
|
||||
commercial={commercial}
|
||||
translateX={translateX}
|
||||
opacity={opacity}
|
||||
transBackDisplay={transBackDisplay}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const mobileRender = () => {
|
||||
return (
|
||||
<>
|
||||
{filtersMenuRender(
|
||||
filtersMenu ? '0' : '100vw',
|
||||
filtersMenu ? '1' : '0'
|
||||
)}
|
||||
<FiltersMenu
|
||||
toggleFiltersMenu={toggleFiltersMenu}
|
||||
sortByHandler={setSortBy}
|
||||
statusHandler={setStatus}
|
||||
challengeTypeHandler={setChallengeType}
|
||||
commercialHandler={setCommercial}
|
||||
sortBy={sortBy}
|
||||
status={status}
|
||||
challengeType={challengeType}
|
||||
commercial={commercial}
|
||||
translateX={filtersMenu ? '0' : '100vw'}
|
||||
opacity={filtersMenu ? '1' : '0'}
|
||||
/>
|
||||
<ChallengesStyle as="main" id="start">
|
||||
<FlexColumn className="ChallengesStyle__page-container">
|
||||
@ -110,18 +142,7 @@ const Challenges = () => {
|
||||
const desktopRender = () => {
|
||||
return (
|
||||
<>
|
||||
<FiltersMenu
|
||||
toggleFiltersMenu={toggleFiltersMenu}
|
||||
transBackDisplay="none"
|
||||
sortByHandler={setSortBy}
|
||||
statusHandler={setStatus}
|
||||
challengeTypeHandler={setChallengeType}
|
||||
commercialHandler={setCommercial}
|
||||
sortBy={sortBy}
|
||||
status={status}
|
||||
challengeType={challengeType}
|
||||
commercial={commercial}
|
||||
/>
|
||||
{filtersMenuRender()}
|
||||
<ChallengesStyle as="main" id="start">
|
||||
<FlexColumn className="ChallengesStyle__page-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;
|
||||
if (challenges && challenges !== []) {
|
||||
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