Changed dashboard to use GetServerSideProps

This commit is contained in:
Ryan Freeman 2023-04-11 23:22:51 +01:00
parent 4c2e1e4749
commit 2b78a4fffe
2 changed files with 5 additions and 4 deletions

View File

@ -1,3 +1,4 @@
import {GetServerSidePropsContext} from 'next'
import { import {
getTopRepo, getTopRepo,
getTotalFollowers, getTotalFollowers,
@ -10,7 +11,7 @@ import {getTopArtist, getTopGenre} from '@/lib/spotify'
import {getStats} from '@/lib/statsfm' import {getStats} from '@/lib/statsfm'
import {Metric} from '@/types' import {Metric} from '@/types'
export async function getDashboardData() { export async function getDashboardData(context: GetServerSidePropsContext) {
const [totalRepos, totalFollowers] = await Promise.all([ const [totalRepos, totalFollowers] = await Promise.all([
getTotalRepos(), getTotalRepos(),
getTotalFollowers() getTotalFollowers()

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import Head from 'next/head' import Head from 'next/head'
import {GetStaticProps} from 'next' import {GetServerSideProps} from 'next'
import useSWR from 'swr' import useSWR from 'swr'
import {SimpleLayout} from '@/components/layouts/SimpleLayout' import {SimpleLayout} from '@/components/layouts/SimpleLayout'
import {Card} from '@/components/ui/Card' import {Card} from '@/components/ui/Card'
@ -104,10 +104,10 @@ export default function Dashboard({metrics}: { metrics: MetricGroup }) {
) )
} }
export const getStaticProps: GetStaticProps = async () => { export const getServerSideProps: GetServerSideProps = async (context) => {
return { return {
props: { props: {
metrics: await getDashboardData() metrics: await getDashboardData(context)
} }
} }
} }