Updated cookie impl

This commit is contained in:
2025-09-16 13:42:38 +02:00
parent 4417485c93
commit 6feb61a289
3 changed files with 16 additions and 9 deletions

View File

@@ -1,6 +1,8 @@
"use client" "use client"
import { Accordion } from "@/components/ui/accordion" import { Accordion } from "@/components/ui/accordion"
import { COOKIE_VALUES } from "@/data/general"
import { Player } from "@/lib/schema/player"
import { closestCenter, DndContext, DragEndEvent, KeyboardSensor, PointerSensor, useSensor, useSensors } from "@dnd-kit/core" import { closestCenter, DndContext, DragEndEvent, KeyboardSensor, PointerSensor, useSensor, useSensors } from "@dnd-kit/core"
import { arrayMove, SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy } from "@dnd-kit/sortable" import { arrayMove, SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy } from "@dnd-kit/sortable"
import { useSortable } from "@dnd-kit/sortable" import { useSortable } from "@dnd-kit/sortable"
@@ -10,7 +12,6 @@ import { GripVertical } from "lucide-react"
import { usePathname } from "next/navigation" import { usePathname } from "next/navigation"
import { useEffect, useState } from "react" import { useEffect, useState } from "react"
import { Player } from "@/lib/schema/player"
import ArcadeStats from "./_stats/arcade/arcade" import ArcadeStats from "./_stats/arcade/arcade"
import BedwarsStats from "./_stats/bedwars/bedwars" import BedwarsStats from "./_stats/bedwars/bedwars"
import BlitzStats from "./_stats/blitz/blitz" import BlitzStats from "./_stats/blitz/blitz"
@@ -25,6 +26,12 @@ import TNTGamesStats from "./_stats/tnt-games/tnt-games"
import UHCStats from "./_stats/uhc/uhc" import UHCStats from "./_stats/uhc/uhc"
import WoolGamesStats from "./_stats/woolgames/woolgames" import WoolGamesStats from "./_stats/woolgames/woolgames"
export function PlayerPageLoadText() {
const path = usePathname()
return <p>{`Loading stats for ${path.split("/").at(-1)}`}</p>
}
interface SortableStatItemProps { interface SortableStatItemProps {
id: string id: string
children: React.ReactNode children: React.ReactNode
@@ -60,12 +67,6 @@ function SortableStatItem({ id, children }: SortableStatItemProps) {
) )
} }
export function PlayerPageLoadText() {
const path = usePathname()
return <p>{`Loading stats for ${path.split("/").at(-1)}`}</p>
}
export default function PlayerStats( export default function PlayerStats(
{ stats, achievements, layout }: { { stats, achievements, layout }: {
stats: NonNullable<Player["player"]["stats"]> stats: NonNullable<Player["player"]["stats"]>
@@ -108,7 +109,7 @@ export default function PlayerStats(
) )
function updateStatsOrder(arr: string[]) { function updateStatsOrder(arr: string[]) {
Cookies.set("player-stats-order", JSON.stringify(arr), { Cookies.set(COOKIE_VALUES.statsOrder, JSON.stringify(arr), {
secure: process.env.NODE_ENV === "production", secure: process.env.NODE_ENV === "production",
sameSite: "lax", sameSite: "lax",
expires: 365 expires: 365

View File

@@ -1,5 +1,6 @@
import DisplayName from "@/components/player/displayname" import DisplayName from "@/components/player/displayname"
import { Card, CardContent } from "@/components/ui/card" import { Card, CardContent } from "@/components/ui/card"
import { COOKIE_VALUES } from "@/data/general"
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"
@@ -74,7 +75,7 @@ async function SuspendedPage({ params }: Pick<PageProps<"/player/[ign]">, "param
const level = getExactLevel(player.networkExp) const level = getExactLevel(player.networkExp)
const schema = z.array(z.string()) const schema = z.array(z.string())
const { data: layout } = schema.safeParse(JSON.parse(c.get("stats-order")?.value ?? "null")) const { data: layout } = schema.safeParse(JSON.parse(c.get(COOKIE_VALUES.statsOrder)?.value ?? "null"))
return ( return (
<div className="flex flex-col items-center pb-5"> <div className="flex flex-col items-center pb-5">

5
src/data/general.ts Normal file
View File

@@ -0,0 +1,5 @@
const prefix = "local-hypstats"
export const COOKIE_VALUES = {
statsOrder: `${prefix}-player-stats-order`
} as const