Files
pawol.nu/pages/awtis/index.js
T

89 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-12-11 01:52:31 +01:00
import PropTypes from 'prop-types'
2022-05-20 02:18:16 +04:00
import {Box, Container, Grid} from '@mui/material'
2020-12-11 01:52:31 +01:00
2022-05-20 02:18:16 +04:00
import {jwennAwtisPajinasyon} from '../../lib/oki-api'
2020-12-11 01:52:31 +01:00
2022-05-21 17:56:56 +04:00
import ChecheAwtis from '../../components/awtis/cheche-awtis'
2022-05-11 03:05:59 +04:00
import AwtisKat from '../../components/awtis/awtis-kat'
import Pajinasyon from '../../components/awtis/pajinasyon'
import HeadLayout from '../../components/head-layout'
2022-05-20 02:18:16 +04:00
import Footer from '../../components/footer'
2020-12-11 01:52:31 +01:00
2022-05-20 02:18:16 +04:00
import Custom404 from '../404'
import Custom500 from '../500'
export default function Awtis({errorCode, error404, errorMessage, pajTotal, awtisPouChakPaj, paj}) {
if (error404) {
return <Custom404 statusCode={error404} />
}
if (errorCode) {
console.log('⚠️ error', errorMessage)
return <Custom500 statusCode={errorCode} />
}
2020-12-12 21:50:16 +01:00
2020-12-11 01:52:31 +01:00
return (
2022-02-07 16:25:39 +04:00
<HeadLayout title='Awtis - Liste des artistes' tab={2} slug='awtis'>
2022-05-20 02:18:16 +04:00
<Box sx={{display: 'flex', flexDirection: 'column', minHeight: '100vh'}}>
<Pajinasyon pajTotal={pajTotal} paj={paj} />
2022-05-21 17:56:56 +04:00
<ChecheAwtis />
2022-05-20 02:18:16 +04:00
<Container sx={{marginBottom: 5, flexGrow: 100}}>
<Grid container spacing={{xs: 2, md: 3}}>
{awtisPouChakPaj.map(artiste => <AwtisKat key={artiste.id} artiste={artiste.attributes} />)}
</Grid>
</Container>
<Footer />
</Box>
2020-12-15 23:46:05 +01:00
</HeadLayout>
2020-12-11 01:52:31 +01:00
)
}
export async function getServerSideProps({query}) {
const {paj} = query
2022-05-20 02:18:16 +04:00
let error404
let errorCode
let errorMessage
let awtisPouChakPaj
2020-12-11 01:52:31 +01:00
2020-12-14 13:23:51 +01:00
const pajParsed = Array.isArray(paj) ? Number.parseInt(paj[1], 10) : Number.parseInt(paj, 10)
2020-12-11 01:52:31 +01:00
2022-05-20 02:18:16 +04:00
try {
awtisPouChakPaj = await jwennAwtisPajinasyon(pajParsed)
} catch (error) {
errorMessage = error.message
errorCode = true
}
const pajTotal = Math.ceil(awtisPouChakPaj.meta.pagination.total / awtisPouChakPaj.meta.pagination.limit)
if (pajParsed > pajTotal || pajParsed < 1) {
error404 = true
2020-12-11 01:52:31 +01:00
}
return {
props: {
2022-05-20 02:18:16 +04:00
error404: error404 || null,
errorCode: errorCode || null,
errorMessage: errorMessage || null,
2020-12-11 01:52:31 +01:00
pajTotal,
2022-05-20 02:18:16 +04:00
awtisPouChakPaj: awtisPouChakPaj.data,
2020-12-11 01:52:31 +01:00
paj: pajParsed
}
}
}
2022-05-20 02:18:16 +04:00
Awtis.defaultProps = {
error404: null,
errorCode: null,
errorMessage: null,
}
Awtis.propTypes = {
error404: PropTypes.bool,
errorCode: PropTypes.bool,
errorMessage: PropTypes.string,
pajTotal: PropTypes.number.isRequired,
awtisPouChakPaj: PropTypes.array.isRequired,
paj: PropTypes.number.isRequired
}