diff --git a/src/components/elements/IconLabel.js b/src/components/elements/IconLabel.js index fd30c3f..5305566 100644 --- a/src/components/elements/IconLabel.js +++ b/src/components/elements/IconLabel.js @@ -14,7 +14,8 @@ import imageIco from '../../assets/image_ico.svg'; const HoverLabel = styled(Body)` position: absolute; top: -32px; - left: 0; + left: ${({type}) => (type === 'text' || type === 'image' || type === 'tabular') ? '-32px' : 0}; + width: 100px; display: none; justify-content: center; align-items: center; @@ -26,7 +27,7 @@ const HoverLabel = styled(Body)` const renderHoverLabel = (type) => { const hoverLabel = (label) => - + {label} ; diff --git a/src/components/elements/Pager.js b/src/components/elements/Pager.js index 053b84b..68491a4 100644 --- a/src/components/elements/Pager.js +++ b/src/components/elements/Pager.js @@ -17,29 +17,13 @@ const RightArrow = styled(Svg)` `; const Pager = (props) => { - const [page, setPage] = React.useState(1); - - const nextPage = () => { - if (page !== props.pages) { - let newPage = page + 1; - setPage(newPage); - } - } - - const previousPage = () => { - if (page !== 1) { - let newPage = page - 1; - setPage(newPage); - } - } - return ( - - - + + + ); } diff --git a/src/pages/Challenges.js b/src/pages/Challenges.js index 9150df8..70eed3c 100644 --- a/src/pages/Challenges.js +++ b/src/pages/Challenges.js @@ -4,8 +4,39 @@ import {FlexColumn, Grid} from "../utils/containers"; import Search from "../components/elements/Search"; import MiniChallenge from "../components/elements/MiniChallenge"; import Pager from "../components/elements/Pager"; +import challenges from "../prototypeData/challenges"; +import {ELEMENTS_PER_PAGE} from "../utils/globals"; const Challenges = () => { + const [pageNr, setPageNr] = React.useState(1); + const pages = Math.ceil(challenges.length / ELEMENTS_PER_PAGE); + + const nextPage = () => { + if (pageNr !== pages) { + let newPage = pageNr + 1; + setPageNr(newPage); + } + } + + const previousPage = () => { + if (pageNr !== 1) { + let newPage = pageNr - 1; + setPageNr(newPage); + } + } + + const renderChallenges = () => { + const n = (pageNr - 1) * ELEMENTS_PER_PAGE; + return ( + challenges.slice(n, n + ELEMENTS_PER_PAGE).map((challenge, index) => { + return ( + + ); + }) + ) + } + return ( @@ -16,16 +47,12 @@ const Challenges = () => { - - - + {renderChallenges()} - + ); } diff --git a/src/prototypeData/challenges.js b/src/prototypeData/challenges.js new file mode 100644 index 0000000..7d278e3 --- /dev/null +++ b/src/prototypeData/challenges.js @@ -0,0 +1,241 @@ +const challenges = [ + { + title: 'Challenging America geo prediction', + describe: 'Guess publication location for a piece of text', + type: 'text', + }, + { + title: 'Challenging America geo prediction', + describe: 'Guess publication location for a piece of text', + type: 'image', + }, + { + title: 'Challenging America geo prediction', + describe: 'Guess publication location for a piece of text', + type: 'tabular', + }, + { + title: 'Example 1', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'text', + }, + { + title: 'Example 2', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'tabular', + }, + { + title: 'Example 3', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'image', + }, + { + title: 'Example 4', + describe: 'Guess publication location for a piece of text', + type: 'text', + }, + { + title: 'Example 5', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'tabular', + }, + { + title: 'Example 6', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'image', + }, + { + title: 'Example 7', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'text', + }, + { + title: 'Example 8', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'tabular', + }, + { + title: 'Example 9', + describe: 'Guess publication location for a piece of text', + type: 'text', + }, + { + title: 'Example 10', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'image', + }, + { + title: 'Example 11', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'tabular', + }, + { + title: 'Challenging America geo prediction', + describe: 'Guess publication location for a piece of text', + type: 'text', + }, + { + title: 'Challenging America geo prediction', + describe: 'Guess publication location for a piece of text', + type: 'image', + }, + { + title: 'Challenging America geo prediction', + describe: 'Guess publication location for a piece of text', + type: 'tabular', + }, + { + title: 'Example 1', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'text', + }, + { + title: 'Example 2', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'tabular', + }, + { + title: 'Example 3', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'image', + }, + { + title: 'Example 4', + describe: 'Guess publication location for a piece of text', + type: 'text', + }, + { + title: 'Example 5', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'tabular', + }, + { + title: 'Example 6', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'image', + }, + { + title: 'Example 7', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'text', + }, + { + title: 'Example 8', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'tabular', + }, + { + title: 'Example 9', + describe: 'Guess publication location for a piece of text', + type: 'text', + }, + { + title: 'Example 10', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'image', + }, + { + title: 'Example 11', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'tabular', + }, + { + title: 'Challenging America geo prediction', + describe: 'Guess publication location for a piece of text', + type: 'text', + }, + { + title: 'Challenging America geo prediction', + describe: 'Guess publication location for a piece of text', + type: 'image', + }, + { + title: 'Challenging America geo prediction', + describe: 'Guess publication location for a piece of text', + type: 'tabular', + }, + { + title: 'Example 1', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'text', + }, + { + title: 'Example 2', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'tabular', + }, + { + title: 'Example 3', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'image', + }, + { + title: 'Example 4', + describe: 'Guess publication location for a piece of text', + type: 'text', + }, + { + title: 'Example 5', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'tabular', + }, + { + title: 'Example 6', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'image', + }, + { + title: 'Example 7', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'text', + }, + { + title: 'Example 8', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'tabular', + }, + { + title: 'Example 9', + describe: 'Guess publication location for a piece of text', + type: 'text', + }, + { + title: 'Example 10', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'image', + }, + { + title: 'Example 11', + describe: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lobortis nunc odio, + ut lacinia mi vestibulum eget. Donec non tellus lorem. Aliquam maximus semper accumsan.`, + type: 'tabular', + } +] + +export default challenges; \ No newline at end of file diff --git a/src/utils/globals.js b/src/utils/globals.js new file mode 100644 index 0000000..a390960 --- /dev/null +++ b/src/utils/globals.js @@ -0,0 +1,3 @@ +const ELEMENTS_PER_PAGE = 12 + +export {ELEMENTS_PER_PAGE}; \ No newline at end of file