2023-08-15 17:41:51 +00:00
|
|
|
import { useQuery } from '@apollo/client'
|
2024-03-20 00:37:31 +00:00
|
|
|
import PageLoading from '@/components/page-loading'
|
|
|
|
import { ME_REWARDS } from '@/fragments/rewards'
|
|
|
|
import { CenterLayout } from '@/components/layout'
|
2023-08-15 17:41:51 +00:00
|
|
|
import dynamic from 'next/dynamic'
|
|
|
|
import { useRouter } from 'next/router'
|
2024-03-20 00:37:31 +00:00
|
|
|
import { getGetServerSideProps } from '@/api/ssrApollo'
|
|
|
|
import { fixedDecimal } from '@/lib/format'
|
|
|
|
import Trophy from '@/svgs/trophy-fill.svg'
|
|
|
|
import { ListItem } from '@/components/items'
|
|
|
|
import { dayMonthYear } from '@/lib/time'
|
2024-03-23 03:47:21 +00:00
|
|
|
import { GrowthPieChartSkeleton } from '@/components/charts-skeletons'
|
2023-08-15 17:41:51 +00:00
|
|
|
|
2024-03-20 00:37:31 +00:00
|
|
|
const GrowthPieChart = dynamic(() => import('@/components/charts').then(mod => mod.GrowthPieChart), {
|
2024-03-23 03:47:21 +00:00
|
|
|
loading: () => <GrowthPieChartSkeleton />
|
2023-08-15 17:41:51 +00:00
|
|
|
})
|
|
|
|
|
2023-08-28 17:52:15 +00:00
|
|
|
export const getServerSideProps = getGetServerSideProps({
|
2024-03-31 19:21:08 +00:00
|
|
|
query: ME_REWARDS,
|
|
|
|
notFound: (data, params) => data.rewards.reduce((a, r) => a || new Date(r.time) > new Date(), false)
|
2023-08-28 17:52:15 +00:00
|
|
|
})
|
2023-08-15 17:41:51 +00:00
|
|
|
|
|
|
|
export default function Rewards ({ ssrData }) {
|
|
|
|
const router = useRouter()
|
|
|
|
const { data } = useQuery(ME_REWARDS, { variables: { ...router.query } })
|
|
|
|
if (!data && !ssrData) return <PageLoading />
|
|
|
|
|
2023-08-30 00:13:21 +00:00
|
|
|
const { rewards, meRewards } = data || ssrData
|
2023-08-15 17:41:51 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<CenterLayout footerLinks>
|
2023-08-30 00:13:21 +00:00
|
|
|
<div className='mw-100'>
|
|
|
|
{rewards.map(({ total, sources, time }, i) => (
|
|
|
|
<div className='py-3 w-100 d-grid' key={time} style={{ gridTemplateColumns: 'minmax(0, 1fr)' }}>
|
|
|
|
<h4 className='fw-bold text-muted ps-0'>
|
|
|
|
{time && <div className='text-muted fst-italic fs-6 fw-normal pb-1'>On {dayMonthYear(time)} at 12a CT</div>}
|
|
|
|
{total} sats were rewarded
|
2023-08-15 17:41:51 +00:00
|
|
|
</h4>
|
2023-08-30 00:13:21 +00:00
|
|
|
<div className='my-3 w-100 justify-self-center'>
|
|
|
|
<GrowthPieChart data={sources} />
|
2023-08-15 17:41:51 +00:00
|
|
|
</div>
|
2023-08-30 00:13:21 +00:00
|
|
|
{meRewards[i] &&
|
|
|
|
<div className='justify-self-center mw-100'>
|
|
|
|
<h4 className='fw-bold text-muted'>
|
|
|
|
you earned {meRewards[i].total} sats ({fixedDecimal(meRewards[i].total * 100 / total, 2)}%)
|
|
|
|
</h4>
|
|
|
|
<div>
|
|
|
|
{meRewards[i].rewards?.map((r, i) => <Reward key={[r.rank, r.type].join('-')} {...r} />)}
|
|
|
|
</div>
|
|
|
|
</div>}
|
|
|
|
</div>
|
|
|
|
))}
|
2023-08-15 17:41:51 +00:00
|
|
|
</div>
|
|
|
|
</CenterLayout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-08-29 21:05:09 +00:00
|
|
|
function Reward ({ rank, type, sats, item }) {
|
2023-08-15 17:41:51 +00:00
|
|
|
if (!rank) return null
|
|
|
|
|
|
|
|
const color = rank <= 3 ? 'text-primary' : 'text-muted'
|
|
|
|
|
|
|
|
let category = type
|
|
|
|
switch (type) {
|
|
|
|
case 'TIP_POST':
|
|
|
|
category = 'in post zapping'
|
|
|
|
break
|
|
|
|
case 'TIP_COMMENT':
|
|
|
|
category = 'in comment zapping'
|
|
|
|
break
|
|
|
|
case 'POST':
|
|
|
|
category = 'among posts'
|
|
|
|
break
|
|
|
|
case 'COMMENT':
|
|
|
|
category = 'among comments'
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-08-29 21:05:09 +00:00
|
|
|
<div>
|
|
|
|
<div className={color}>
|
|
|
|
<Trophy height={20} width={20} /> <b>#{rank}</b> {category} for <i><b>{sats} sats</b></i>
|
|
|
|
</div>
|
|
|
|
{item &&
|
|
|
|
<div className={item.parentId ? 'pt-0' : 'pt-2'}>
|
|
|
|
<ListItem item={item} />
|
|
|
|
</div>}
|
2023-08-15 17:41:51 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|