From 5ae3a3fc545a1e8b70f170f0e460dff87682154e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Fri, 11 Dec 2020 01:52:31 +0100 Subject: [PATCH] Create Awtis page --- pages/awtis.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 pages/awtis.js diff --git a/pages/awtis.js b/pages/awtis.js new file mode 100644 index 0000000..370b928 --- /dev/null +++ b/pages/awtis.js @@ -0,0 +1,50 @@ +import PropTypes from 'prop-types' +import {Container, Grid} from '@material-ui/core' + +import {jwennAwtisKantite, jwennAwtisPajinasyon} from '../lib/oki-api' + +import Navigasyon from '../components/navigasyon' +import AwtisKat from '../components/awtis/awtis-kat' +import Pajinasyon from '../components/awtis/pajinasyon' + +export default function Awtis({pajTotal, awtisPouChakPaj, paj}) { + return ( + <> + + + + + {awtisPouChakPaj.map(anAwtis => )} + + + + ) +} + +Awtis.propTypes = { + pajTotal: PropTypes.number.isRequired, + awtisPouChakPaj: PropTypes.array.isRequired, + paj: PropTypes.number.isRequired +} + +export async function getServerSideProps({query}) { + const {paj} = query + + const pajParsed = Number.parseInt(paj[1] || paj, 10) + const awtisPouChakPaj = await jwennAwtisPajinasyon(pajParsed) + const awtisCountRequest = await jwennAwtisKantite() + const awtisCount = Number.parseInt(awtisCountRequest, 10) + const pajTotal = Math.ceil(awtisCount / 8) + + if (pajParsed > pajTotal) { + throw new Error('Pa twouvé paj-la') + } + + return { + props: { + pajTotal, + awtisPouChakPaj, + paj: pajParsed + } + } +}