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

113 lines
3.0 KiB
JavaScript
Raw Normal View History

import { gql, useQuery } from '@apollo/client'
2023-05-18 23:41:56 +00:00
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'
2023-05-19 23:12:48 +00:00
import { useRouter } from 'next/router'
2023-07-25 14:14:45 +00:00
import dynamic from 'next/dynamic'
import PageLoading from '../../components/page-loading'
2023-07-24 22:50:12 +00:00
const WhenAreaChart = dynamic(() => import('../../components/charts').then(mod => mod.WhenAreaChart), {
loading: () => <div>Loading...</div>
2023-07-25 14:14:45 +00:00
})
2023-07-24 22:50:12 +00:00
const WhenLineChart = dynamic(() => import('../../components/charts').then(mod => mod.WhenLineChart), {
loading: () => <div>Loading...</div>
2023-07-25 14:14:45 +00:00
})
2023-05-18 23:41:56 +00:00
const GROWTH_QUERY = gql`
query Growth($when: String!)
{
registrationGrowth(when: $when) {
time
data {
name
value
2023-05-18 23:41:56 +00:00
}
}
itemGrowth(when: $when) {
time
data {
name
value
2023-05-18 23:41:56 +00:00
}
}
spendingGrowth(when: $when) {
time
data {
name
value
2023-05-18 23:41:56 +00:00
}
}
spenderGrowth(when: $when) {
time
data {
name
value
2023-05-18 23:41:56 +00:00
}
}
stackingGrowth(when: $when) {
time
data {
name
value
2023-05-18 23:41:56 +00:00
}
}
stackerGrowth(when: $when) {
time
data {
name
value
2023-05-18 23:41:56 +00:00
}
}
}`
2023-05-18 23:41:56 +00:00
export const getServerSideProps = getGetServerSideProps(GROWTH_QUERY)
export default function Growth ({ ssrData }) {
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-07-24 22:50:12 +00:00
const { data } = useQuery(GROWTH_QUERY, { variables: { when } })
if (!data && !ssrData) return <PageLoading />
const { registrationGrowth, itemGrowth, spendingGrowth, spenderGrowth, stackingGrowth, stackerGrowth } = data || ssrData
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-07-25 14:14:45 +00:00
<WhenLineChart data={stackerGrowth} />
2023-05-18 23:41:56 +00:00
</Col>
<Col className='mt-3'>
2023-07-24 18:35:05 +00:00
<div className='text-center text-muted fw-bold'>stacking</div>
2023-07-25 14:14:45 +00:00
<WhenAreaChart data={stackingGrowth} />
2023-05-18 23:41:56 +00:00
</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-07-25 14:14:45 +00:00
<WhenLineChart data={spenderGrowth} />
2023-05-18 23:41:56 +00:00
</Col>
<Col className='mt-3'>
2023-07-24 18:35:05 +00:00
<div className='text-center text-muted fw-bold'>spending</div>
2023-07-25 14:14:45 +00:00
<WhenAreaChart data={spendingGrowth} />
2023-05-18 23:41:56 +00:00
</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-07-25 14:14:45 +00:00
<WhenAreaChart data={registrationGrowth} />
2023-05-18 23:41:56 +00:00
</Col>
<Col className='mt-3'>
2023-07-24 18:35:05 +00:00
<div className='text-center text-muted fw-bold'>items</div>
2023-07-25 14:14:45 +00:00
<WhenAreaChart data={itemGrowth} />
2023-05-18 23:41:56 +00:00
</Col>
</Row>
</Layout>
)
}