From 270f6efaa6c8d379324969d03a1358a24acede24 Mon Sep 17 00:00:00 2001
From: dvelo <52332868+DeveloLongScript@users.noreply.github.com>
Date: Fri, 3 Jan 2025 13:40:13 -0600
Subject: [PATCH] fix: issue
---
CONTRIBUTING.md | 1 +
.../server/[server]/statistics/page.tsx | 7 +
src/components/ServerList.tsx | 16 +-
src/components/ServerView.tsx | 3 +-
src/components/charts/DailyChart.tsx | 174 ++++++++++++++++
src/components/charts/ExampleChart.tsx | 191 ++++++++++++++++++
src/components/charts/MonthlyChart.tsx | 160 +++++++++++++++
src/components/charts/NewChart.tsx | 4 +-
src/components/misc/MiniJoinsChart.tsx | 2 +-
src/lib/api.ts | 22 ++
src/lib/hooks/use-daily-trend.tsx | 80 ++++++++
src/lib/hooks/use-trend.tsx | 95 +++++++++
.../v0/account-linking/claim-account-code.ts | 2 +-
src/pages/api/v0/account-linking/is-owned.ts | 2 +-
.../api/v0/account-linking/own-server.ts | 2 +-
.../api/v0/account-linking/owned-user.ts | 2 +-
.../api/v0/account-linking/unlink-account.ts | 2 +-
.../api/v0/account-linking/unown-server.ts | 2 +-
src/pages/api/v0/achievements/[server].ts | 2 +-
.../api/v0/customization/[server]/get.ts | 2 +-
.../api/v0/customization/[server]/set.ts | 2 +-
src/pages/api/v0/customization/getList.ts | 2 +-
.../favorites/[server]/community-favorites.ts | 2 +-
.../v0/favorites/[server]/favorite-server.ts | 2 +-
.../api/v0/favorites/[server]/favorited.ts | 2 +-
.../api/v0/favorites/account-favorites.ts | 2 +-
.../api/v0/history/[server]/get-daily-data.ts | 62 ++++++
.../v0/history/[server]/get-monthly-data.ts | 62 ++++++
src/pages/api/v0/sorting/favorites.ts | 2 +-
29 files changed, 887 insertions(+), 22 deletions(-)
create mode 100644 src/components/charts/DailyChart.tsx
create mode 100644 src/components/charts/ExampleChart.tsx
create mode 100644 src/components/charts/MonthlyChart.tsx
create mode 100644 src/lib/hooks/use-daily-trend.tsx
create mode 100644 src/lib/hooks/use-trend.tsx
create mode 100644 src/pages/api/v0/history/[server]/get-daily-data.ts
create mode 100644 src/pages/api/v0/history/[server]/get-monthly-data.ts
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 9a00da6..77322cf 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -42,6 +42,7 @@ We use [Atlas](https://www.mongodb.com/atlas) to host our MongoDB database, but
```dotenv
MONGO_DB="mongodb+srv://..."
```
+You can also set `CUSTOM_MONGO_DB` to a database name that will apply to all operations except statistical operations.
## Smaller things (for production-ready servers)
diff --git a/src/app/(main)/server/[server]/statistics/page.tsx b/src/app/(main)/server/[server]/statistics/page.tsx
index 6c80b7f..c1a7afa 100644
--- a/src/app/(main)/server/[server]/statistics/page.tsx
+++ b/src/app/(main)/server/[server]/statistics/page.tsx
@@ -36,6 +36,8 @@ import TabServer from "@/components/misc/TabServer";
import type { Metadata, ResolvingMetadata } from "next";
import StickyTopbar from "@/components/misc/StickyTopbar";
import { RelativeChart } from "@/components/charts/RelativeChart";
+import { MonthlyChart } from "@/components/charts/MonthlyChart";
+import { DailyChart } from "@/components/charts/DailyChart";
type Props = {
params: { server: string };
@@ -113,6 +115,11 @@ export default function ServerPage({ params }: { params: { server: string } }) {
+
+ Ever wondered how a server was doing? MHSF constantly monitors servers + and shows you statistics about how a server is doing at any point of time. +
+
This means that the server can{"'"}t loading some resources, like
diff --git a/src/components/charts/DailyChart.tsx b/src/components/charts/DailyChart.tsx
new file mode 100644
index 0000000..cc189e2
--- /dev/null
+++ b/src/components/charts/DailyChart.tsx
@@ -0,0 +1,174 @@
+/*
+ * MHSF, Minehut Server List
+ * All external content is rather licensed under the ECA Agreement
+ * located here: https://mhsf.app/docs/legal/external-content-agreement
+ *
+ * All code under MHSF is licensed under the MIT License
+ * by open source contributors
+ *
+ * Copyright (c) 2024 dvelo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+"use client";
+
+import { TrendingDown, TrendingUp } from "lucide-react";
+import {
+ Bar,
+ BarChart,
+ CartesianGrid,
+ LabelList,
+ Rectangle,
+ XAxis,
+ YAxis,
+} from "recharts";
+import { useEffect, useState } from "react";
+
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+} from "@/components/ui/card";
+import {
+ ChartConfig,
+ ChartContainer,
+ ChartTooltip,
+ ChartTooltipContent,
+} from "@/components/ui/chart";
+import { Skeleton } from "../ui/skeleton";
+import { getDailyData, getMonthlyData } from "@/lib/api";
+import { useTrend } from "@/lib/hooks/use-daily-trend";
+
+const chartConfig = {
+ result: {
+ label: "Players",
+ color: "hsl(var(--chart-3))",
+ },
+} satisfies ChartConfig;
+
+export function DailyChart({ server }: { server: string }) {
+ const [chartData, setChartData] = useState<{ day: string; result: number }[]>(
+ [],
+ );
+ const [loading, setLoading] = useState(true);
+ const { trend, percentage, success } = useTrend(chartData);
+
+ useEffect(() => {
+ getDailyData(server).then((c) => {
+ setChartData(c);
+ setLoading(false);
+ });
+ }, [server]);
+
+ if (loading) return