This commit is contained in:
parent
4e3ba2d0c7
commit
0f70a50bd4
@ -1,89 +0,0 @@
|
||||
import AnalyticsChart from "@/components/AnalyticsChart";
|
||||
import Card from "@/components/Card";
|
||||
import Container from "@/components/Container";
|
||||
import { ScoresaberMetricsHistory } from "@/schemas/fascinated/scoresaberMetricsHistory";
|
||||
import ssrSettings from "@/ssrSettings.json";
|
||||
import { formatNumber } from "@/utils/numberUtils";
|
||||
import { formatDate } from "@/utils/timeUtils";
|
||||
import { isProduction } from "@/utils/utils";
|
||||
import { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
|
||||
async function getData() {
|
||||
const response = await fetch(
|
||||
"https://bs-tracker.fascinated.cc/analytics?time=30d",
|
||||
{
|
||||
next: {
|
||||
revalidate: isProduction() ? 600 : 0, // 10 minutes (0 seconds in dev)
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const json = await response.json();
|
||||
return {
|
||||
data: json as ScoresaberMetricsHistory,
|
||||
};
|
||||
}
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const { data } = await getData();
|
||||
|
||||
const description =
|
||||
"View Scoresaber metrics and statistics over the last 30 days.";
|
||||
|
||||
const lastActivePlayers =
|
||||
data.activePlayersHistory[data.activePlayersHistory.length - 1].value;
|
||||
const lastScoreCount =
|
||||
data.scoreCountHistory[data.scoreCountHistory.length - 1].value;
|
||||
|
||||
return {
|
||||
title: `Analytics`,
|
||||
description: description,
|
||||
openGraph: {
|
||||
siteName: ssrSettings.siteName,
|
||||
title: `Analytics`,
|
||||
description:
|
||||
description +
|
||||
`
|
||||
|
||||
Last Updated: ${formatDate(new Date().toISOString())}
|
||||
Players Online Today: ${formatNumber(lastActivePlayers)}
|
||||
Scores set Today: ${formatNumber(lastScoreCount)}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Analytics() {
|
||||
const { data } = await getData();
|
||||
|
||||
return (
|
||||
<main>
|
||||
<Container>
|
||||
<Card
|
||||
outerClassName="mt-2"
|
||||
className="flex flex-col items-center justify-center"
|
||||
>
|
||||
<h1 className="text-center text-3xl font-bold">Analytics</h1>
|
||||
<p className="text-center">
|
||||
Scoresaber metrics and statistics over the last 30 days.
|
||||
</p>
|
||||
<p className="text-gray-300">
|
||||
Want more in-depth data? Click{" "}
|
||||
<span className="text-pp-blue">
|
||||
<Link
|
||||
href="https://grafana.fascinated.cc/d/b3c6c28d-39e9-4fa9-8e2b-b0ddb10f875e/beatsaber-metrics"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
here
|
||||
</Link>
|
||||
</span>
|
||||
</p>
|
||||
<div className="mt-3 h-[400px] w-full">
|
||||
<AnalyticsChart historyData={data} />
|
||||
</div>
|
||||
</Card>
|
||||
</Container>
|
||||
</main>
|
||||
);
|
||||
}
|
@ -1,8 +1,4 @@
|
||||
import {
|
||||
CogIcon,
|
||||
MagnifyingGlassIcon,
|
||||
ServerIcon,
|
||||
} from "@heroicons/react/20/solid";
|
||||
import { MagnifyingGlassIcon } from "@heroicons/react/20/solid";
|
||||
import { GlobeAltIcon, TvIcon } from "@heroicons/react/24/outline";
|
||||
import { Card } from "../ui/card";
|
||||
import FriendsButton from "./FriendsButton";
|
||||
@ -29,12 +25,6 @@ export default function Navbar() {
|
||||
icon={<TvIcon height={23} width={23} />}
|
||||
href="/overlay/builder"
|
||||
/>
|
||||
<NavbarButton
|
||||
ariaLabel="View analytics for Scoresaber"
|
||||
text="Analytics"
|
||||
icon={<ServerIcon height={23} width={23} />}
|
||||
href="/analytics"
|
||||
/>
|
||||
|
||||
<div className="m-auto" />
|
||||
|
||||
|
@ -9,15 +9,34 @@ if (typeof window !== "undefined") {
|
||||
}
|
||||
|
||||
export const IDBStorage: StateStorage = {
|
||||
/**
|
||||
* Fetch an item from the storage
|
||||
*
|
||||
* @param name name of the item to be fetched
|
||||
* @returns the value of the item or null if it doesn't exist
|
||||
*/
|
||||
getItem: async (name: string): Promise<string | null> => {
|
||||
//console.log(name, "has been retrieved");
|
||||
|
||||
return (await get(name, storage)) || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Save an item to the storage
|
||||
*
|
||||
* @param name name of the item to be saved
|
||||
* @param value value of the item to be saved
|
||||
*/
|
||||
setItem: async (name: string, value: string): Promise<void> => {
|
||||
//console.log(name, "with value", value, "has been saved");
|
||||
await set(name, value, storage);
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete an item from the storage
|
||||
*
|
||||
* @param name name of the item to be deleted
|
||||
*/
|
||||
removeItem: async (name: string): Promise<void> => {
|
||||
//console.log(name, "has been deleted");
|
||||
await del(name, storage);
|
||||
|
Loading…
Reference in New Issue
Block a user