Files
pawol.nu/pages/index.js
T

146 lines
4.5 KiB
JavaScript
Raw Normal View History

import PropTypes from 'prop-types'
2022-05-25 06:39:40 +04:00
import Container from '@mui/material/Container'
import Typography from '@mui/material/Typography'
import Box from '@mui/material/Box'
import Divider from '@mui/material/Divider'
import Chip from '@mui/material/Chip'
import Grid from '@mui/material/Grid'
2022-06-17 22:18:17 +04:00
import Button from '@mui/material/Button'
2022-06-19 02:36:22 +04:00
import OpenInNewIcon from '@mui/icons-material/OpenInNew'
2022-09-09 23:23:14 +04:00
import Tooltip from '@mui/material/Tooltip'
2020-12-17 09:08:18 +01:00
2020-12-15 23:46:05 +01:00
import HeadLayout from '../components/head-layout'
2021-06-14 23:30:00 +02:00
import Footer from '../components/footer'
2022-05-23 00:25:46 +04:00
import {jwennStats} from '../lib/oki-api'
2022-05-25 06:40:00 +04:00
import KatStats from '../components/stats/kat-stats'
2022-05-23 00:25:46 +04:00
import KatKayLa from '../components/kat-kay-la'
2020-12-17 22:36:27 +01:00
2022-05-14 03:37:04 +04:00
import Custom500 from './500'
2022-05-23 00:25:46 +04:00
export default function Home({errorCode, errorMessage, stats}) {
2022-05-14 03:37:04 +04:00
if (errorCode) {
console.log('⚠️ error', errorMessage)
return <Custom500 statusCode={errorCode} />
}
2022-05-25 06:40:00 +04:00
const {parolesWithoutTranslation} = stats
const statsByLang = [
{
code: 'fr',
value: parolesWithoutTranslation.francais,
emoji: '&#127467;&#127479;'
},
{
code: 'en',
value: parolesWithoutTranslation.anglais,
emoji: '&#127468;&#127463;'
},
{
code: 'es',
value: parolesWithoutTranslation.espagnol,
emoji: '&#127466;&#127480;'
},
{
code: 'de',
value: parolesWithoutTranslation.allemand,
emoji: '&#127465;&#127466;'
},
{
code: 'it',
value: parolesWithoutTranslation.italien,
emoji: '&#127470;&#127481;'
}
]
2020-12-04 20:16:24 +01:00
return (
2020-12-15 23:46:05 +01:00
<HeadLayout tab={0}>
2022-01-20 18:01:52 +04:00
<Box sx={{display: 'flex', flexDirection: 'column', minHeight: '100vh'}}>
2022-05-23 00:25:46 +04:00
<Box sx={{flexGrow: 1, marginBottom: 3, marginTop: 1}}>
2022-05-10 02:10:06 +04:00
<Container sx={{marginBottom: 2}} align='center'>
2022-02-01 20:59:38 +04:00
<Typography sx={{fontWeight: 'bold'}} variant='h6' component='h1'>
2022-01-22 12:31:55 +04:00
#OKi
</Typography>
2022-02-01 20:59:38 +04:00
<Typography sx={{fontWeight: 'bold'}} variant='h6' component='h2'>
2022-01-20 18:01:52 +04:00
Organisation KA Internationale
</Typography>
2022-02-01 23:44:18 +04:00
<Typography sx={{fontStyle: 'italic'}} variant='caption' component='h3'>
2022-06-19 02:20:56 +04:00
Paroles, traductions et Fédiverse
2022-02-01 20:59:38 +04:00
</Typography>
</Container>
2022-08-20 22:33:32 +04:00
<Container>
<Grid container justifyContent='center' spacing={2}>
<Grid item>
2022-10-23 05:04:50 +04:00
<Tooltip arrow title='asso.oki.re' placement='top'>
<Button variant='outlined' endIcon={<OpenInNewIcon />} onClick={() => window.open('https://asso.oki.re/public/members/new.php', '_blank')}>
<strong>Adhésion</strong>
</Button>
</Tooltip>
2022-08-20 22:33:32 +04:00
</Grid>
<Grid item>
2022-10-23 05:04:50 +04:00
<Tooltip arrow title='o-k-i.net' placement='top'>
2022-09-09 23:23:14 +04:00
<Button variant='outlined' endIcon={<OpenInNewIcon />} onClick={() => window.open('https://o-k-i.net', '_blank')}>
<strong>Fédiverse</strong>
</Button>
</Tooltip>
2022-08-20 22:33:32 +04:00
</Grid>
</Grid>
2022-01-20 18:01:52 +04:00
</Container>
</Box>
2022-05-14 03:37:04 +04:00
<Container sx={{flexGrow: 100}}>
2022-05-23 00:25:46 +04:00
<Divider sx={{marginBottom: 3}}>
2022-09-09 23:24:44 +04:00
<Chip sx={{fontWeight: 'bold'}} color='primary' label='Statistiques' variant='outlined' />
</Divider>
2022-05-23 00:25:46 +04:00
<Grid container spacing={2} sx={{marginBottom: 3}}>
2022-05-23 18:34:55 +04:00
<KatKayLa tit='Paroles' kantite={stats.countParole} href='/paroles' as='/paroles' />
2022-05-23 00:25:46 +04:00
<KatKayLa tit='Artistes' kantite={stats.countArtiste} href='/awtis?paj&paj=1' as='/awtis/paj/1' />
</Grid>
2022-06-04 01:38:19 +04:00
<Typography marginBottom={2} textAlign='center' sx={{fontWeight: 'bold'}} variant='h6' component='h4'>
Traductions
</Typography>
<Grid container justifyContent='space-between' spacing={2} marginBottom={3}>
2022-05-25 06:40:00 +04:00
{statsByLang.map(({code, value, emoji}) => (
<KatStats key={code} emoji={emoji} value={value} total={stats.countParole} />
))}
2022-06-02 07:41:38 +04:00
</Grid>
</Container>
2021-06-14 23:30:00 +02:00
<Footer />
2022-01-20 18:01:52 +04:00
</Box>
2020-12-15 23:46:05 +01:00
</HeadLayout>
2020-12-04 20:16:24 +01:00
)
}
export async function getServerSideProps() {
2022-05-23 00:25:46 +04:00
let stats
2022-05-14 03:37:04 +04:00
let errorCode
let errorMessage
try {
2022-05-23 00:25:46 +04:00
stats = await jwennStats()
2022-05-14 03:37:04 +04:00
} catch (error) {
errorMessage = error.message
errorCode = true
}
return {
props: {
2022-05-14 03:37:04 +04:00
errorCode: errorCode || null,
errorMessage: errorMessage || null,
2022-05-23 00:25:46 +04:00
stats: stats || null
}
}
}
2022-05-14 03:37:04 +04:00
Home.defaultProps = {
errorCode: null,
errorMessage: null,
2022-05-23 00:25:46 +04:00
stats: null
2022-05-14 03:37:04 +04:00
}
Home.propTypes = {
2022-05-14 03:37:04 +04:00
errorCode: PropTypes.bool,
errorMessage: PropTypes.string,
2022-05-23 00:25:46 +04:00
stats: PropTypes.object
}