refactor Challenges structure and add animation to filters menu button

This commit is contained in:
mattyl006 2022-07-12 14:21:08 +02:00
parent f73961fe52
commit d9f5d87081
10 changed files with 52 additions and 32 deletions

View File

@ -1,7 +1,7 @@
import styled, {ThemeProvider} from 'styled-components'; import {ThemeProvider} from 'styled-components';
import theme from "./utils/theme"; import theme from "./utils/theme";
import LandingPage from "./pages/LandingPage"; import LandingPage from "./pages/LandingPage";
import Challenges from "./pages/Challenges"; import Challenges from "./pages/Challanges/Challenges";
import {BrowserRouter, Route, Routes} from "react-router-dom"; import {BrowserRouter, Route, Routes} from "react-router-dom";
import NavBar from "./components/elements/NavBar"; import NavBar from "./components/elements/NavBar";
import Footer from "./components/sections/Footer"; import Footer from "./components/sections/Footer";

View File

@ -74,9 +74,9 @@ const MiniChallenge = (props) => {
<IconLabel size='24px' gap='8px' type='baseline'> <IconLabel size='24px' gap='8px' type='baseline'>
{props.baseline ? props.baseline : 'xxx'} {props.baseline ? props.baseline : 'xxx'}
</IconLabel> </IconLabel>
<IconLabel size='24px' gap='8px' type='prize'> {props.prize ? <IconLabel size='24px' gap='8px' type='prize'>
{props.prize ? props.prize : 'xxx'} {props.prize}
</IconLabel> </IconLabel> : ''}
</IconsGrid> </IconsGrid>
</ChallengeStyle> </ChallengeStyle>
); );

View File

@ -23,6 +23,11 @@ const SearchStyle = styled(FlexRow)`
margin-left: 12px; margin-left: 12px;
width: 14px; width: 14px;
height: 20px; height: 20px;
transition: transform 0.3s ease-in-out;
&:hover {
transform: scale(1.25);
}
} }
input { input {

View File

@ -2,7 +2,6 @@ import React from "react";
import {Container, FlexRow} from "../../utils/containers"; import {Container, FlexRow} from "../../utils/containers";
import styled from "styled-components"; import styled from "styled-components";
import {Medium} from "../../utils/fonts"; import {Medium} from "../../utils/fonts";
import {Link} from "react-router-dom";
const FooterStyle = styled(FlexRow)` const FooterStyle = styled(FlexRow)`
width: 100%; width: 100%;
@ -12,7 +11,7 @@ const FooterStyle = styled(FlexRow)`
align-items: center; align-items: center;
background-color: ${({theme}) => theme.colors.green}; background-color: ${({theme}) => theme.colors.green};
* { p, a {
color: ${({theme}) => theme.colors.white} color: ${({theme}) => theme.colors.white}
} }

View File

@ -1,12 +1,13 @@
import React from "react"; import React from "react";
import {H1} from "../utils/fonts"; import {H1} from "../../utils/fonts";
import {FlexColumn, Grid} from "../utils/containers"; import {FlexColumn, Grid} from "../../utils/containers";
import Search from "../components/elements/Search"; import Search from "../../components/elements/Search";
import MiniChallenge from "../components/elements/MiniChallenge"; import Pager from "../../components/elements/Pager";
import Pager from "../components/elements/Pager"; import {ELEMENTS_PER_PAGE} from "../../utils/globals";
import {ELEMENTS_PER_PAGE, API} from "../utils/globals"; import FiltersMenu from "../../components/elements/FiltersMenu";
import FiltersMenu from "../components/elements/FiltersMenu";
import _searchQueryHandler from "./_searchQueryHandler"; import _searchQueryHandler from "./_searchQueryHandler";
import _challengesRequest from "./_challengesRequest";
import _renderChallenges from "./_renderChallenges";
const Challenges = () => { const Challenges = () => {
const [pageNr, setPageNr] = React.useState(1); const [pageNr, setPageNr] = React.useState(1);
@ -23,12 +24,7 @@ const Challenges = () => {
}, []); }, []);
const challengesRequest = () => { const challengesRequest = () => {
fetch(`${API}/list-challenges`) _challengesRequest(setChallengesFromAPI, setChallenges);
.then(response => response.json())
.then(data => {
setChallengesFromAPI(data);
setChallenges(data);
});
} }
const sortByHandler = (value) => { const sortByHandler = (value) => {
@ -70,17 +66,7 @@ const Challenges = () => {
} }
const renderChallenges = () => { const renderChallenges = () => {
const n = (pageNr - 1) * ELEMENTS_PER_PAGE; return _renderChallenges(pageNr, challenges);
return (
challenges.slice(n, n + ELEMENTS_PER_PAGE).map((challenge, index) => {
return (
<MiniChallenge key={`challenge-${index}`} title={challenge.title} type={challenge.type}
description={challenge.description} metric={challenge.mainMetric}
bestScore={challenge.bestScore} baseline={challenge.baseline}
prize={challenge.prize} deadline={challenge.deadline}/>
);
})
)
} }
const toggleFiltersMenu = () => { const toggleFiltersMenu = () => {

View File

@ -0,0 +1,12 @@
import {API} from "../../utils/globals";
const _challengesRequest = (setChallengesFromAPI, setChallenges) => {
fetch(`${API}/list-challenges`)
.then(response => response.json())
.then(data => {
setChallengesFromAPI(data);
setChallenges(data);
});
}
export default _challengesRequest;

View File

@ -0,0 +1,18 @@
import {ELEMENTS_PER_PAGE} from "../../utils/globals";
import MiniChallenge from "../../components/elements/MiniChallenge";
const _renderChallenges = (pageNr, challenges) => {
const n = (pageNr - 1) * ELEMENTS_PER_PAGE;
return (
challenges.slice(n, n + ELEMENTS_PER_PAGE).map((challenge, index) => {
return (
<MiniChallenge key={`challenge-${index}`} title={challenge.title} type={challenge.type}
description={challenge.description} metric={challenge.mainMetric}
bestScore={challenge.bestScore} baseline={challenge.baseline}
prize={challenge.prize} deadline={challenge.deadline}/>
);
})
)
}
export default _renderChallenges;

View File

@ -0,0 +1 @@
export {default} from './Challenges';

View File

@ -17,7 +17,6 @@ const Container = styled.div`
border: ${({border}) => border ? border : 'none'}; border: ${({border}) => border ? border : 'none'};
cursor: ${({cursor}) => cursor ? cursor : 'auto'}; cursor: ${({cursor}) => cursor ? cursor : 'auto'};
display: ${({display}) => display ? display : 'block'}; display: ${({display}) => display ? display : 'block'};
outline: ${({outline}) => outline ? outline : 'none'};
text-decoration: ${({textDecoration}) => textDecoration ? textDecoration : 'none'}; text-decoration: ${({textDecoration}) => textDecoration ? textDecoration : 'none'};
text-transform: ${({textTransform}) => textTransform ? textTransform : 'none'}; text-transform: ${({textTransform}) => textTransform ? textTransform : 'none'};
opacity: ${({opacity}) => opacity ? opacity : '1'}; opacity: ${({opacity}) => opacity ? opacity : '1'};