Fixed guild page
This commit is contained in:
@@ -2,10 +2,10 @@ import { getColor } from "@/lib/colors"
|
|||||||
import { env } from "@/lib/env/server"
|
import { env } from "@/lib/env/server"
|
||||||
import { getGuild } from "@/lib/hypixel/api/guild"
|
import { getGuild } from "@/lib/hypixel/api/guild"
|
||||||
import { getUuid } from "@/lib/hypixel/api/mojang"
|
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 { cn, parseSearchParams } from "@/lib/utils"
|
||||||
import { Loader2Icon, ShieldAlert } from "lucide-react"
|
import { Loader2Icon, ShieldAlert } from "lucide-react"
|
||||||
import { Suspense } from "react"
|
import { ReactNode, Suspense } from "react"
|
||||||
import z from "zod"
|
import z from "zod"
|
||||||
import { GuildPageLoadText } from "./_client"
|
import { GuildPageLoadText } from "./_client"
|
||||||
import Sidebar from "./_components/sidebar"
|
import Sidebar from "./_components/sidebar"
|
||||||
@@ -39,60 +39,48 @@ export default function GuildPage({ params, searchParams }: PageProps<"/guild/[v
|
|||||||
async function SuspendedPage({ params, searchParams }: Pick<PageProps<"/guild/[value]">, "params" | "searchParams">) {
|
async function SuspendedPage({ params, searchParams }: Pick<PageProps<"/guild/[value]">, "params" | "searchParams">) {
|
||||||
const { value } = await params
|
const { value } = await params
|
||||||
const ptype = parseSearchParams(await searchParams).getValue("type")
|
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 { data: type } = z.literal("id").or(z.literal("name")).or(z.literal("player")).default("player").safeParse(ptype)
|
||||||
|
|
||||||
const mc = await getUuid(value)
|
let guild: Guild["guild"] | null = null
|
||||||
if (!mc) {
|
let component: ReactNode | null = null
|
||||||
return (
|
|
||||||
<div className="flex flex-col items-center min-h-screen">
|
switch (type) {
|
||||||
<h1 className="pt-30">Player not found</h1>
|
case "id":
|
||||||
</div>
|
guild = await getGuild(value, type)
|
||||||
)
|
component = (
|
||||||
|
<div className="flex flex-col items-center min-h-screen">
|
||||||
|
<h1 className="pt-30">{`The guild with the id ${value} doesn't exist`}</h1>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
break
|
||||||
|
case "name":
|
||||||
|
guild = await getGuild(value, type)
|
||||||
|
component = (
|
||||||
|
<div className="flex flex-col items-center min-h-screen">
|
||||||
|
<h1 className="pt-30">{`The guild with the name ${value} doesn't exist`}</h1>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
break
|
||||||
|
case "player":
|
||||||
|
case undefined:
|
||||||
|
const uuid = await getUuid(value)
|
||||||
|
if (!uuid) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col items-center min-h-screen">
|
||||||
|
<h1 className="pt-30">Player not found</h1>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
guild = await getGuild(uuid.id, type)
|
||||||
|
component = (
|
||||||
|
<div className="flex flex-col items-center min-h-screen">
|
||||||
|
<h1 className="pt-30">{`${uuid.name} is not in a guild or has not logged on to hypixel`}</h1>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
const player = await getPlayer(mc.id)
|
if (!guild) return component
|
||||||
|
|
||||||
if (!player) {
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col items-center min-h-screen">
|
|
||||||
<h1 className="pt-30">Player hasn't joined hypixel</h1>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const guild = await getGuild(mc.id, type)
|
|
||||||
|
|
||||||
if (!guild) {
|
|
||||||
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 (
|
return (
|
||||||
<div className="flex flex-col items-center pb-5 pt-30">
|
<div className="flex flex-col items-center pb-5 pt-30">
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export async function getGuild(id: string, type: "id" | "player" | "name" = "pla
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (!res.ok) return null
|
if (!res.ok) return null
|
||||||
|
console.log(res.url)
|
||||||
|
|
||||||
const { success, data } = guildSchema.safeParse(await res.json())
|
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
|
return data.guild
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user