106 lines
3.0 KiB
JavaScript
106 lines
3.0 KiB
JavaScript
import {useRouter} from 'next/router'
|
|
import PropTypes from 'prop-types'
|
|
import Container from '@mui/material/Container'
|
|
import Typography from '@mui/material/Typography'
|
|
import Box from '@mui/material/Box'
|
|
import Grid from '@mui/material/Grid'
|
|
import Button from '@mui/material/Button'
|
|
|
|
import Image from 'next/image'
|
|
import HeadLayout from '../components/head-layout'
|
|
import Footer from '../components/footer'
|
|
import {jwennStats} from '../lib/oki-api'
|
|
import okiLogo from '../public/logo-72x72.png'
|
|
|
|
import KatKayLa from '../components/kat-kay-la'
|
|
|
|
import Custom500 from './500'
|
|
|
|
export default function Home({errorCode, errorMessage, stats}) {
|
|
const router = useRouter()
|
|
|
|
if (errorCode) {
|
|
console.log('⚠️ error', errorMessage)
|
|
return <Custom500 statusCode={errorCode} />
|
|
}
|
|
|
|
return (
|
|
<HeadLayout tab={0}>
|
|
<Box sx={{display: 'flex', flexDirection: 'column', minHeight: '100vh'}}>
|
|
<Box sx={{flexGrow: 1, marginBottom: 3, marginTop: 3}}>
|
|
<Container align='center'>
|
|
<Box sx={{display: 'flex', alignItems: 'cetner', justifyContent: 'center'}}>
|
|
|
|
<Typography sx={{fontWeight: 'bold', mr: 1}} variant='h6' component='h1'>
|
|
OKI
|
|
</Typography>
|
|
|
|
<Image
|
|
width={32}
|
|
height={32}
|
|
atl='OKI logo'
|
|
src={okiLogo}
|
|
/>
|
|
</Box>
|
|
<Typography sx={{fontWeight: 'bold'}} variant='h6' component='h2'>
|
|
Organisation KA Internationale
|
|
</Typography>
|
|
<Typography sx={{fontStyle: 'italic'}} variant='caption' component='h3'>
|
|
Paroles et traductions
|
|
</Typography>
|
|
</Container>
|
|
<Container sx={{marginTop: 2}}>
|
|
<Grid container justifyContent='center' spacing={2}>
|
|
<Grid item>
|
|
<Button variant='outlined' onClick={() => router.push('/soumet')}>
|
|
<strong>Soumettre des paroles</strong>
|
|
</Button>
|
|
</Grid>
|
|
</Grid>
|
|
</Container>
|
|
</Box>
|
|
<Container sx={{flexGrow: 100}}>
|
|
<Grid container spacing={2} sx={{marginBottom: 3}}>
|
|
<KatKayLa tit='Paroles' kantite={stats.countParole} href='/paroles' as='/paroles' />
|
|
<KatKayLa tit='Artistes' kantite={stats.countArtiste} href='/awtis?paj&paj=1' as='/awtis/paj/1' />
|
|
</Grid>
|
|
</Container>
|
|
<Footer />
|
|
</Box>
|
|
</HeadLayout>
|
|
)
|
|
}
|
|
|
|
export async function getServerSideProps() {
|
|
let stats
|
|
let errorCode
|
|
let errorMessage
|
|
|
|
try {
|
|
stats = await jwennStats()
|
|
} catch (error) {
|
|
errorMessage = error.message
|
|
errorCode = true
|
|
}
|
|
|
|
return {
|
|
props: {
|
|
errorCode: errorCode || null,
|
|
errorMessage: errorMessage || null,
|
|
stats: stats || null
|
|
}
|
|
}
|
|
}
|
|
|
|
Home.defaultProps = {
|
|
errorCode: null,
|
|
errorMessage: null,
|
|
stats: null
|
|
}
|
|
|
|
Home.propTypes = {
|
|
errorCode: PropTypes.bool,
|
|
errorMessage: PropTypes.string,
|
|
stats: PropTypes.object
|
|
}
|