stacker.news/pages/stackers/[when].js

100 lines
2.6 KiB
JavaScript
Raw Normal View History

2023-05-18 23:41:56 +00:00
import { gql } from '@apollo/client'
import { getGetServerSideProps } from '../../api/ssrApollo'
import Layout from '../../components/layout'
2023-07-24 18:35:05 +00:00
import Col from 'react-bootstrap/Col'
import Row from 'react-bootstrap/Row'
2023-05-18 23:41:56 +00:00
import { UsageHeader } from '../../components/usage-header'
import { WhenLineChart, WhenAreaChart } from '../../components/when-charts'
2023-05-19 23:12:48 +00:00
import { useRouter } from 'next/router'
2023-05-18 23:41:56 +00:00
export const getServerSideProps = getGetServerSideProps(
gql`
query Growth($when: String!)
{
registrationGrowth(when: $when) {
time
data {
name
value
}
}
itemGrowth(when: $when) {
time
data {
name
value
}
}
spendingGrowth(when: $when) {
time
data {
name
value
}
}
spenderGrowth(when: $when) {
time
data {
name
value
}
}
stackingGrowth(when: $when) {
time
data {
name
value
}
}
stackerGrowth(when: $when) {
time
data {
name
value
}
}
}`)
export default function Growth ({
ssrData: { registrationGrowth, itemGrowth, spendingGrowth, spenderGrowth, stackingGrowth, stackerGrowth }
2023-05-18 23:41:56 +00:00
}) {
2023-05-19 23:12:48 +00:00
const router = useRouter()
const { when } = router.query
2023-05-21 17:08:41 +00:00
const avg = ['year', 'forever'].includes(when) ? 'avg daily ' : ''
2023-05-18 23:41:56 +00:00
return (
<Layout>
<UsageHeader />
<Row>
<Col className='mt-3'>
2023-07-24 18:35:05 +00:00
<div className='text-center text-muted fw-bold'>{avg}stackers</div>
2023-05-18 23:41:56 +00:00
<WhenLineChart data={stackerGrowth} />
</Col>
<Col className='mt-3'>
2023-07-24 18:35:05 +00:00
<div className='text-center text-muted fw-bold'>stacking</div>
2023-05-18 23:41:56 +00:00
<WhenAreaChart data={stackingGrowth} />
</Col>
</Row>
<Row>
<Col className='mt-3'>
2023-07-24 18:35:05 +00:00
<div className='text-center text-muted fw-bold'>{avg}spenders</div>
2023-05-18 23:41:56 +00:00
<WhenLineChart data={spenderGrowth} />
</Col>
<Col className='mt-3'>
2023-07-24 18:35:05 +00:00
<div className='text-center text-muted fw-bold'>spending</div>
2023-05-18 23:41:56 +00:00
<WhenAreaChart data={spendingGrowth} />
</Col>
</Row>
<Row>
<Col className='mt-3'>
2023-07-24 18:35:05 +00:00
<div className='text-center text-muted fw-bold'>registrations</div>
2023-05-18 23:41:56 +00:00
<WhenAreaChart data={registrationGrowth} />
</Col>
<Col className='mt-3'>
2023-07-24 18:35:05 +00:00
<div className='text-center text-muted fw-bold'>items</div>
2023-05-18 23:41:56 +00:00
<WhenAreaChart data={itemGrowth} />
</Col>
</Row>
</Layout>
)
}