From 2b78a4fffedc22f04c16a41f8cab23cd3f71cc7d Mon Sep 17 00:00:00 2001 From: Ryan Freeman Date: Tue, 11 Apr 2023 23:22:51 +0100 Subject: [PATCH] Changed dashboard to use GetServerSideProps --- lib/dashboard.ts | 3 ++- pages/dashboard.tsx | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/dashboard.ts b/lib/dashboard.ts index bd9a286..a4d9889 100644 --- a/lib/dashboard.ts +++ b/lib/dashboard.ts @@ -1,3 +1,4 @@ +import {GetServerSidePropsContext} from 'next' import { getTopRepo, getTotalFollowers, @@ -10,7 +11,7 @@ import {getTopArtist, getTopGenre} from '@/lib/spotify' import {getStats} from '@/lib/statsfm' import {Metric} from '@/types' -export async function getDashboardData() { +export async function getDashboardData(context: GetServerSidePropsContext) { const [totalRepos, totalFollowers] = await Promise.all([ getTotalRepos(), getTotalFollowers() diff --git a/pages/dashboard.tsx b/pages/dashboard.tsx index 38c5483..59213f3 100644 --- a/pages/dashboard.tsx +++ b/pages/dashboard.tsx @@ -1,6 +1,6 @@ import React from 'react' import Head from 'next/head' -import {GetStaticProps} from 'next' +import {GetServerSideProps} from 'next' import useSWR from 'swr' import {SimpleLayout} from '@/components/layouts/SimpleLayout' 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 { props: { - metrics: await getDashboardData() + metrics: await getDashboardData(context) } } }