Updated page
This commit is contained in:
@@ -1,9 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import { usePathname } from "next/navigation"
|
||||
import { usePathname, useSearchParams } from "next/navigation"
|
||||
import z from "zod"
|
||||
|
||||
export function GuildPageLoadText() {
|
||||
const path = usePathname()
|
||||
const params = useSearchParams()
|
||||
|
||||
return <p>{`Loading ${path.split("/").at(-1)}'s guild...`}</p>
|
||||
const { data: type } = z.literal("id").or(z.literal("name")).or(z.literal("player")).default("player").safeParse(params.get("type"))
|
||||
|
||||
switch (type) {
|
||||
case "player":
|
||||
return <p>{`Loading stats ${path.split("/").at(-1)}'s guild...`}</p>
|
||||
case "id":
|
||||
return <p>{`Loading stats for the guild id ${path.split("/").at(-1)}...`}</p>
|
||||
case "name":
|
||||
return <p>{`Loading stats for the guild name ${path.split("/").at(-1)}...`}</p>
|
||||
case undefined:
|
||||
return <p>{`Loading stats ${path.split("/").at(-1)}'s guild...`}</p>
|
||||
default:
|
||||
throw new Error(`Unknown type: ${type satisfies never}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'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'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 (
|
||||
|
||||
Reference in New Issue
Block a user