Frontend Update visitor growth calculation display

pull/3/head
TZGyn 2 years ago
parent fa3abc523b
commit f16c2d4aef
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

Binary file not shown.

@ -108,6 +108,19 @@ export default function Dashboard() {
const thisMonth = new Date().getMonth() const thisMonth = new Date().getMonth()
const getVisitorGrowth = (visitorData: VisitorData[]) => {
const growth = visitorData[thisMonth]?.total
? visitorData[thisMonth].total -
visitorData[thisMonth - 1]?.total ?? 0
: 0
if (growth < 0) {
return `- ${Math.abs(growth)}`
}
return `+ ${growth}`
}
return ( return (
<ThemeProvider <ThemeProvider
defaultTheme='dark' defaultTheme='dark'
@ -153,13 +166,9 @@ export default function Dashboard() {
{visitorData[thisMonth]?.total ?? 0} {visitorData[thisMonth]?.total ?? 0}
</div> </div>
<p className='text-xs text-muted-foreground'> <p className='text-xs text-muted-foreground'>
{`+ ${ {`${getVisitorGrowth(
visitorData[thisMonth]?.total ?? visitorData
0 - )} since last month`}
visitorData[thisMonth - 1]
?.total ??
0
} since last month`}
</p> </p>
</CardContent> </CardContent>
</Card> </Card>

Loading…
Cancel
Save