Updated page

This commit is contained in:
2025-09-26 14:09:14 +02:00
parent 9978faf69d
commit 38f196bd9a
3 changed files with 68 additions and 12 deletions

View File

@@ -3,12 +3,13 @@ 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 { cn } from "@/lib/utils"
import { cn, parseSearchParams } from "@/lib/utils"
import { Loader2Icon, ShieldAlert } from "lucide-react"
import { Suspense } from "react"
import z from "zod"
import { GuildPageLoadText } from "./_client"
export default function GuildPage({ params }: PageProps<"/guild/[value]">) {
export default function GuildPage({ params, searchParams }: PageProps<"/guild/[value]">) {
const maintenance = env.MAINTENANCE_MODE
if (maintenance) {
@@ -29,13 +30,16 @@ export default function GuildPage({ params }: PageProps<"/guild/[value]">) {
</div>
}
>
<SuspendedPage params={params} />
<SuspendedPage params={params} searchParams={searchParams} />
</Suspense>
)
}
async function SuspendedPage({ params }: Pick<PageProps<"/guild/[value]">, "params">) {
async function SuspendedPage({ params, searchParams }: Pick<PageProps<"/guild/[value]">, "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) {
@@ -56,14 +60,37 @@ async function SuspendedPage({ params }: Pick<PageProps<"/guild/[value]">, "para
)
}
const guild = await getGuild(mc.id)
const guild = await getGuild(mc.id, type)
if (!guild) {
return (
<div className="flex flex-col items-center min-h-screen">
<h1 className="pt-30">Player is not in a guild.</h1>
</div>
)
switch (type) {
case "player":
return (
<div className="flex flex-col items-center min-h-screen">
<h1 className="pt-30">Player is not in a guild.</h1>
</div>
)
case "id":
return (
<div className="flex flex-col items-center min-h-screen">
<h1 className="pt-30">The guild with that id doesn&apos;t exist.</h1>
</div>
)
case "name":
return (
<div className="flex flex-col items-center min-h-screen">
<h1 className="pt-30">The guild with that name doesn&apos;t exist.</h1>
</div>
)
case undefined:
return (
<div className="flex flex-col items-center min-h-screen">
<h1 className="pt-30">Player is not in a guild.</h1>
</div>
)
default:
throw new Error(`Unknown type: ${type satisfies never}`)
}
}
return (