Set up API spec and basic components

This commit is contained in:
Ben Grant 2023-05-20 01:52:44 +10:00
parent 2adecd13f7
commit 61bd31eb7e
20 changed files with 353 additions and 26 deletions

View file

@ -0,0 +1,24 @@
.wrapper {
display: flex;
justify-content: space-around;
align-items: flex-start;
flex-wrap: wrap;
& > div {
text-align: center;
padding: 0 6px;
min-width: 160px;
margin: 10px 0;
}
}
.number {
display: block;
font-weight: 900;
color: var(--secondary);
font-size: 2em;
}
.label {
display: block;
}

View file

@ -0,0 +1,33 @@
import { API_BASE, StatsResponse } from '/src/config/api'
import { useTranslation } from '/src/i18n/server'
import styles from './Stats.module.scss'
const getStats = async () => {
const res = await fetch(new URL('/stats', API_BASE))
.catch(console.warn)
if (!res?.ok) return
return StatsResponse.parse(await res.json())
}
const Stats = async () => {
const stats = await getStats()
const { t } = await useTranslation('home')
return <div className={styles.wrapper}>
<div>
<span className={styles.number}>
{new Intl.NumberFormat().format(stats?.event_count || 17000)}{!stats?.event_count && '+'}
</span>
<span className={styles.label}>{t('about.events')}</span>
</div>
<div>
<span className={styles.number}>
{new Intl.NumberFormat().format(stats?.person_count || 65000)}{!stats?.person_count && '+'}
</span>
<span className={styles.label}>{t('about.availabilities')}</span>
</div>
</div>
}
export default Stats