From 6c81316364715271874fe13533869dbe6fe35c5c Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 27 Oct 2024 19:30:58 +0000 Subject: [PATCH] auto reload site stats --- projects/website/src/app/(pages)/page.tsx | 13 +----- .../website/src/components/app-statistics.tsx | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 projects/website/src/components/app-statistics.tsx diff --git a/projects/website/src/app/(pages)/page.tsx b/projects/website/src/app/(pages)/page.tsx index 58d02bd..babc5b9 100644 --- a/projects/website/src/app/(pages)/page.tsx +++ b/projects/website/src/app/(pages)/page.tsx @@ -1,9 +1,9 @@ import { Button } from "@/components/ui/button"; import Link from "next/link"; import { AppStatistics } from "@ssr/common/types/backend/app-statistics"; -import Statistic from "@/components/home/statistic"; import { kyFetch } from "@ssr/common/utils/utils"; import { Config } from "@ssr/common/config"; +import { AppStats } from "@/components/app-statistics"; export const dynamic = "force-dynamic"; // Always generate the page on load @@ -21,16 +21,7 @@ export default async function HomePage() {

ScoreSaber Reloaded is a website that allows you to track your ScoreSaber data over time.

- {statistics && ( -
-

Site Statistics

- - - - - -
- )} + {statistics && }
diff --git a/projects/website/src/components/app-statistics.tsx b/projects/website/src/components/app-statistics.tsx new file mode 100644 index 0000000..77df1a3 --- /dev/null +++ b/projects/website/src/components/app-statistics.tsx @@ -0,0 +1,41 @@ +"use client"; + +import Statistic from "@/components/home/statistic"; +import { AppStatistics } from "@ssr/common/types/backend/app-statistics"; +import { useQuery } from "@tanstack/react-query"; +import { kyFetch } from "@ssr/common/utils/utils"; +import { Config } from "@ssr/common/config"; +import { useEffect, useState } from "react"; + +type AppStatisticsProps = { + /** + * The app statistics. + */ + initialStatistics: AppStatistics; +}; + +export function AppStats({ initialStatistics }: AppStatisticsProps) { + const [statistics, setStatistics] = useState(initialStatistics); + + const { data } = useQuery({ + queryKey: ["app-statistics"], + queryFn: () => kyFetch(Config.apiUrl + "/statistics"), + }); + + useEffect(() => { + if (data) { + setStatistics(data); + } + }, [data]); + + return ( +
+

Site Statistics

+ + + + + +
+ ); +}