From 818f1d420addf2d33170e51badda93b4e18025bc Mon Sep 17 00:00:00 2001 From: Taken Date: Sat, 27 Sep 2025 21:28:08 +0200 Subject: [PATCH] Fixed guild page --- src/app/(stats)/guild/[value]/page.tsx | 92 +++++++++++--------------- src/lib/hypixel/api/guild.ts | 2 +- 2 files changed, 41 insertions(+), 53 deletions(-) diff --git a/src/app/(stats)/guild/[value]/page.tsx b/src/app/(stats)/guild/[value]/page.tsx index bacf541..f260b8a 100644 --- a/src/app/(stats)/guild/[value]/page.tsx +++ b/src/app/(stats)/guild/[value]/page.tsx @@ -2,10 +2,10 @@ import { getColor } from "@/lib/colors" import { env } from "@/lib/env/server" import { getGuild } from "@/lib/hypixel/api/guild" import { getUuid } from "@/lib/hypixel/api/mojang" -import { getPlayer } from "@/lib/hypixel/api/player" +import { Guild } from "@/lib/schema/guild" import { cn, parseSearchParams } from "@/lib/utils" import { Loader2Icon, ShieldAlert } from "lucide-react" -import { Suspense } from "react" +import { ReactNode, Suspense } from "react" import z from "zod" import { GuildPageLoadText } from "./_client" import Sidebar from "./_components/sidebar" @@ -39,60 +39,48 @@ export default function GuildPage({ params, searchParams }: PageProps<"/guild/[v async function SuspendedPage({ params, searchParams }: Pick, "params" | "searchParams">) { const { value } = await params const ptype = parseSearchParams(await searchParams).getValue("type") - const { data: type } = z.literal("id").or(z.literal("name")).or(z.literal("player")).default("player").safeParse(ptype) - const mc = await getUuid(value) - if (!mc) { - return ( -
-

Player not found

-
- ) + let guild: Guild["guild"] | null = null + let component: ReactNode | null = null + + switch (type) { + case "id": + guild = await getGuild(value, type) + component = ( +
+

{`The guild with the id ${value} doesn't exist`}

+
+ ) + break + case "name": + guild = await getGuild(value, type) + component = ( +
+

{`The guild with the name ${value} doesn't exist`}

+
+ ) + break + case "player": + case undefined: + const uuid = await getUuid(value) + if (!uuid) { + return ( +
+

Player not found

+
+ ) + } + guild = await getGuild(uuid.id, type) + component = ( +
+

{`${uuid.name} is not in a guild or has not logged on to hypixel`}

+
+ ) + break } - const player = await getPlayer(mc.id) - - if (!player) { - return ( -
-

Player hasn't joined hypixel

-
- ) - } - - const guild = await getGuild(mc.id, type) - - if (!guild) { - switch (type) { - case "player": - return ( -
-

Player is not in a guild.

-
- ) - case "id": - return ( -
-

The guild with that id doesn't exist.

-
- ) - case "name": - return ( -
-

The guild with that name doesn't exist.

-
- ) - case undefined: - return ( -
-

Player is not in a guild.

-
- ) - default: - throw new Error(`Unknown type: ${type satisfies never}`) - } - } + if (!guild) return component return (
diff --git a/src/lib/hypixel/api/guild.ts b/src/lib/hypixel/api/guild.ts index effe2e3..3f1dc52 100644 --- a/src/lib/hypixel/api/guild.ts +++ b/src/lib/hypixel/api/guild.ts @@ -22,6 +22,7 @@ export async function getGuild(id: string, type: "id" | "player" | "name" = "pla }) if (!res.ok) return null + console.log(res.url) const { success, data } = guildSchema.safeParse(await res.json()) @@ -29,4 +30,3 @@ export async function getGuild(id: string, type: "id" | "player" | "name" = "pla return data.guild } -