mirror of
https://github.com/DeveloLongScript/MHSF.git
synced 2026-05-09 07:04:59 -05:00
bump to 0.4.5
This commit is contained in:
parent
14c43b89d5
commit
250127312a
@ -15,6 +15,7 @@ import { banner } from "@/banner";
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import TabServer from "@/components/misc/TabServer";
|
import TabServer from "@/components/misc/TabServer";
|
||||||
import { ChartComponent } from "@/components/Chart";
|
import { ChartComponent } from "@/components/Chart";
|
||||||
|
import { NewChart } from "@/components/NewChart";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
params: { server: string };
|
params: { server: string };
|
||||||
@ -81,9 +82,8 @@ export default function ServerPage({ params }: { params: { server: string } }) {
|
|||||||
<TabServer server={params.server} tabDef="historical" />
|
<TabServer server={params.server} tabDef="historical" />
|
||||||
<div className="pt-8">
|
<div className="pt-8">
|
||||||
<ServerView server={params.server} />
|
<ServerView server={params.server} />
|
||||||
<div className="p-4 grid grid-cols-2 gap-4">
|
<div className="p-4 gap-4">
|
||||||
<ChartComponent chart="player_count" server={params.server} />
|
<NewChart server={params.server} />
|
||||||
<ChartComponent chart="favorites" server={params.server} />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -14,7 +14,7 @@ export default function FavoritesView() {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
useEffectOnce(() => {
|
useEffectOnce(() => {
|
||||||
fetch("/api/accountLocked/getAllFavorites").then((c) => {
|
fetch("/api/favorites/getAllFavorites").then((c) => {
|
||||||
c.json().then((d) => {
|
c.json().then((d) => {
|
||||||
let num = 0;
|
let num = 0;
|
||||||
d.result.forEach((a: any, i: number) => {
|
d.result.forEach((a: any, i: number) => {
|
||||||
@ -28,7 +28,7 @@ export default function FavoritesView() {
|
|||||||
if (num == d.result.length) {
|
if (num == d.result.length) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
if (d.result.length == 0) setLoading(false);
|
if (d.result.length == 0) setLoading(false);
|
||||||
@ -65,7 +65,7 @@ export default function FavoritesView() {
|
|||||||
className=" min-w-[128px] max-w-[328px] mb-2 h-[32px] max-md:hidden"
|
className=" min-w-[128px] max-w-[328px] mb-2 h-[32px] max-md:hidden"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigator.clipboard.writeText(
|
navigator.clipboard.writeText(
|
||||||
server.name + ".mshf.minehut.gg",
|
server.name + ".mshf.minehut.gg"
|
||||||
);
|
);
|
||||||
toast.success("Copied IP to clipboard");
|
toast.success("Copied IP to clipboard");
|
||||||
}}
|
}}
|
||||||
@ -105,7 +105,7 @@ export default function FavoritesView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function convert(value: number) {
|
function convert(value: number) {
|
||||||
var result: string = "";
|
var result: string = value.toString();
|
||||||
if (value >= 1000000) {
|
if (value >= 1000000) {
|
||||||
result = Math.floor(value / 1000000) + "m";
|
result = Math.floor(value / 1000000) + "m";
|
||||||
} else if (value >= 1000) {
|
} else if (value >= 1000) {
|
||||||
|
|||||||
174
src/components/NewChart.tsx
Normal file
174
src/components/NewChart.tsx
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import * as React from "react";
|
||||||
|
import { CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from "@/components/ui/card";
|
||||||
|
import {
|
||||||
|
ChartConfig,
|
||||||
|
ChartContainer,
|
||||||
|
ChartTooltip,
|
||||||
|
ChartTooltipContent,
|
||||||
|
} from "@/components/ui/chart";
|
||||||
|
import { useEffectOnce } from "@/lib/useEffectOnce";
|
||||||
|
import { ServerResponse } from "./ServerView";
|
||||||
|
|
||||||
|
const chartConfig = {
|
||||||
|
player_count: {
|
||||||
|
label: "Joins",
|
||||||
|
color: "hsl(var(--chart-1))",
|
||||||
|
},
|
||||||
|
favorites: {
|
||||||
|
label: "Favorites",
|
||||||
|
color: "hsl(var(--chart-3))",
|
||||||
|
},
|
||||||
|
} satisfies ChartConfig;
|
||||||
|
|
||||||
|
export function NewChart({ server }: { server: string }) {
|
||||||
|
const [activeChart, setActiveChart] =
|
||||||
|
React.useState<keyof typeof chartConfig>("player_count");
|
||||||
|
|
||||||
|
const [chartData, setChartData] = React.useState<any>([]);
|
||||||
|
const [joins, setJoins] = React.useState<any>(0);
|
||||||
|
const [favorites, setFavorites] = React.useState<any>(0);
|
||||||
|
|
||||||
|
const allNums = { player_count: joins, favorites };
|
||||||
|
useEffectOnce(() => {
|
||||||
|
fetch("/api/history/getShortTermData", {
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
scopes: ["player_count", "favorites", "time"],
|
||||||
|
server,
|
||||||
|
}),
|
||||||
|
method: "POST",
|
||||||
|
}).then((c) => {
|
||||||
|
c.json().then((b) => {
|
||||||
|
setChartData(b.data);
|
||||||
|
fetch("/api/favorites/getCommunityNum", {
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ server }),
|
||||||
|
method: "POST",
|
||||||
|
}).then((b) =>
|
||||||
|
b.json().then((f) => {
|
||||||
|
setFavorites(f.result);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
fetch("https://api.minehut.com/server/" + server + "?byName=true").then(
|
||||||
|
(k) => {
|
||||||
|
k.json().then((p: { server: ServerResponse }) => {
|
||||||
|
setJoins(p.server.joins);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="w-full">
|
||||||
|
<CardHeader className="flex flex-col items-stretch space-y-0 border-b p-0 sm:flex-row">
|
||||||
|
<div className="flex flex-1 flex-col justify-center gap-1 px-6 py-5 sm:py-6">
|
||||||
|
<CardTitle>
|
||||||
|
{chartConfig[activeChart].label} Chart for {server}
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>Showing the past 30 entries.</CardDescription>
|
||||||
|
</div>
|
||||||
|
<div className="flex">
|
||||||
|
{["player_count", "favorites"].map((key) => {
|
||||||
|
const chart = key as keyof typeof chartConfig;
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={chart}
|
||||||
|
data-active={activeChart === chart}
|
||||||
|
className="flex flex-1 flex-col justify-center gap-1 border-t px-6 py-4 text-left even:border-l data-[active=true]:bg-muted/50 sm:border-l sm:border-t-0 sm:px-8 sm:py-6"
|
||||||
|
onClick={() => setActiveChart(chart)}
|
||||||
|
>
|
||||||
|
<span className="text-xs text-muted-foreground">
|
||||||
|
{chartConfig[chart].label}
|
||||||
|
</span>
|
||||||
|
<span className="text-lg font-bold leading-none sm:text-3xl">
|
||||||
|
{convert(allNums[chart])}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="px-2 sm:p-6">
|
||||||
|
<ChartContainer
|
||||||
|
config={chartConfig}
|
||||||
|
className="aspect-auto h-[250px] w-full"
|
||||||
|
>
|
||||||
|
<LineChart
|
||||||
|
accessibilityLayer
|
||||||
|
data={chartData}
|
||||||
|
margin={{
|
||||||
|
left: 12,
|
||||||
|
right: 12,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CartesianGrid vertical={false} />
|
||||||
|
<XAxis
|
||||||
|
dataKey="time"
|
||||||
|
tickLine={false}
|
||||||
|
axisLine={false}
|
||||||
|
tickMargin={8}
|
||||||
|
minTickGap={32}
|
||||||
|
tickFormatter={(value) => {
|
||||||
|
const date = new Date(value);
|
||||||
|
return date.toLocaleTimeString("en-US", {
|
||||||
|
timeStyle: "short",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<YAxis
|
||||||
|
dataKey={activeChart}
|
||||||
|
tickLine={false}
|
||||||
|
axisLine={false}
|
||||||
|
tickFormatter={(value) => {
|
||||||
|
return (
|
||||||
|
value +
|
||||||
|
(activeChart == "player_count"
|
||||||
|
? ` plyr${value != 1 ? "s" : ""}.`
|
||||||
|
: ` ${value == 1 ? "favorite" : "favrts."}`)
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<ChartTooltip
|
||||||
|
content={
|
||||||
|
<ChartTooltipContent
|
||||||
|
className="w-[150px]"
|
||||||
|
nameKey={activeChart}
|
||||||
|
hideLabel
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Line
|
||||||
|
dataKey={activeChart}
|
||||||
|
type="monotone"
|
||||||
|
stroke={`var(--color-${activeChart})`}
|
||||||
|
strokeWidth={2}
|
||||||
|
dot={false}
|
||||||
|
/>
|
||||||
|
</LineChart>
|
||||||
|
</ChartContainer>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function convert(value: number) {
|
||||||
|
var result: string = value.toString();
|
||||||
|
if (value >= 1000000) {
|
||||||
|
result = Math.floor(value / 1000000) + "m";
|
||||||
|
} else if (value >= 1000) {
|
||||||
|
result = Math.floor(value / 1000) + "k";
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@ -54,7 +54,7 @@ export default function ServerView(props: { server: string }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setRandomText(getRandomText());
|
setRandomText(getRandomText());
|
||||||
single.init().then(() => {
|
single.init().then(() => {
|
||||||
fetch("/api/accountLocked/isFavorited", {
|
fetch("/api/favorites/isFavorited", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@ -211,7 +211,7 @@ export default function ServerView(props: { server: string }) {
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
fetch("/api/accountLocked/favoriteServer", {
|
fetch("/api/favorites/favoriteServer", {
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
server: single.grabOffline()?.name,
|
server: single.grabOffline()?.name,
|
||||||
@ -223,7 +223,7 @@ export default function ServerView(props: { server: string }) {
|
|||||||
>
|
>
|
||||||
{favorited && (
|
{favorited && (
|
||||||
<motion.div
|
<motion.div
|
||||||
animate={{ color: "yellow", fill: "yellow" }}
|
animate={{ color: "yellow", fill: "yellow" }}
|
||||||
transition={{ duration: 2 }}
|
transition={{ duration: 2 }}
|
||||||
>
|
>
|
||||||
<Star
|
<Star
|
||||||
@ -237,7 +237,7 @@ export default function ServerView(props: { server: string }) {
|
|||||||
{!favorited && (
|
{!favorited && (
|
||||||
<motion.div
|
<motion.div
|
||||||
transition={{ duration: 1 }}
|
transition={{ duration: 1 }}
|
||||||
animate={{ color: "yellow", fill: "yellow" }}
|
animate={{ color: "yellow", fill: "yellow" }}
|
||||||
>
|
>
|
||||||
<Star className="mr-2" size="16" />
|
<Star className="mr-2" size="16" />
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { decreaseNum, increaseNum } from "./getCommunityNum";
|
|||||||
|
|
||||||
export default async function handler(
|
export default async function handler(
|
||||||
req: NextApiRequest,
|
req: NextApiRequest,
|
||||||
res: NextApiResponse,
|
res: NextApiResponse
|
||||||
) {
|
) {
|
||||||
const { userId } = getAuth(req);
|
const { userId } = getAuth(req);
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ export default async function handler(
|
|||||||
{
|
{
|
||||||
user: userId,
|
user: userId,
|
||||||
favorites: existingFavorites,
|
favorites: existingFavorites,
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
res.send({ message: "Unfavorited " + server });
|
res.send({ message: "Unfavorited " + server });
|
||||||
} else {
|
} else {
|
||||||
@ -52,7 +52,7 @@ export default async function handler(
|
|||||||
{
|
{
|
||||||
user: userId,
|
user: userId,
|
||||||
favorites: existingFavorites,
|
favorites: existingFavorites,
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
res.send({ message: "Favorited " + server });
|
res.send({ message: "Favorited " + server });
|
||||||
}
|
}
|
||||||
@ -4,13 +4,8 @@ import { getAuth } from "@clerk/nextjs/server";
|
|||||||
|
|
||||||
export default async function handler(
|
export default async function handler(
|
||||||
req: NextApiRequest,
|
req: NextApiRequest,
|
||||||
res: NextApiResponse,
|
res: NextApiResponse
|
||||||
) {
|
) {
|
||||||
const { userId } = getAuth(req);
|
|
||||||
|
|
||||||
if (!userId) {
|
|
||||||
return res.status(401).json({ error: "Unauthorized" });
|
|
||||||
}
|
|
||||||
const server = checkForInfoOrLeave(res, req.body.server);
|
const server = checkForInfoOrLeave(res, req.body.server);
|
||||||
const client = new MongoClient(process.env.MONGO_DB as string);
|
const client = new MongoClient(process.env.MONGO_DB as string);
|
||||||
|
|
||||||
@ -47,7 +42,7 @@ export async function increaseNum(client: MongoClient, server: string) {
|
|||||||
const entry = find[0];
|
const entry = find[0];
|
||||||
collection.findOneAndReplace(
|
collection.findOneAndReplace(
|
||||||
{ server: server },
|
{ server: server },
|
||||||
{ server: server, favorites: entry.favorites + 1 },
|
{ server: server, favorites: entry.favorites + 1 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,7 +59,7 @@ export async function decreaseNum(client: MongoClient, server: string) {
|
|||||||
const entry = find[0];
|
const entry = find[0];
|
||||||
collection.findOneAndReplace(
|
collection.findOneAndReplace(
|
||||||
{ server: server },
|
{ server: server },
|
||||||
{ server: server, favorites: entry.favorites - 1 },
|
{ server: server, favorites: entry.favorites - 1 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
export const version = "b-0.4";
|
export const version = "b-0.5";
|
||||||
|
|
||||||
const User = ({ user }: { user: string }) => (
|
const User = ({ user }: { user: string }) => (
|
||||||
<span className="cursor-pointer bg-[rgba(255,165,0,0.25);] rounded p-[2.5px]">
|
<span className="cursor-pointer bg-[rgba(255,165,0,0.25);] rounded p-[2.5px]">
|
||||||
@ -10,7 +10,17 @@ export const Changelog = () => (
|
|||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
<strong className="flex items-center">
|
<strong className="flex items-center">
|
||||||
Version b-0.4 (July 24th 2024):
|
Version b-0.4.5 (July 26th 2024):
|
||||||
|
</strong>
|
||||||
|
<ul>
|
||||||
|
<li>• Made charts better</li>
|
||||||
|
<li>• Sorted API endpoints</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<br />
|
||||||
|
<div>
|
||||||
|
<strong className="flex items-center">
|
||||||
|
Version b-0.4 (July 24th 2024):
|
||||||
</strong>
|
</strong>
|
||||||
<ul>
|
<ul>
|
||||||
<li>• Added Info button</li>
|
<li>• Added Info button</li>
|
||||||
@ -21,7 +31,7 @@ export const Changelog = () => (
|
|||||||
<br />
|
<br />
|
||||||
<div>
|
<div>
|
||||||
<strong className="flex items-center">
|
<strong className="flex items-center">
|
||||||
Version b-0.3 (July 23th 2024):
|
Version b-0.3 (July 23th 2024):
|
||||||
</strong>
|
</strong>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
@ -32,7 +42,7 @@ export const Changelog = () => (
|
|||||||
<br />
|
<br />
|
||||||
<div>
|
<div>
|
||||||
<strong className="flex items-center">
|
<strong className="flex items-center">
|
||||||
Version b-0.2 (July 23th 2024):
|
Version b-0.2 (July 23th 2024):
|
||||||
</strong>
|
</strong>
|
||||||
<ul>
|
<ul>
|
||||||
<li>• Inital release!</li>
|
<li>• Inital release!</li>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user