Updated cookie logic
This commit is contained in:
@@ -10,7 +10,7 @@ import { CSS } from "@dnd-kit/utilities"
|
|||||||
import Cookies from "js-cookie"
|
import Cookies from "js-cookie"
|
||||||
import { GripVertical } from "lucide-react"
|
import { GripVertical } from "lucide-react"
|
||||||
import { usePathname } from "next/navigation"
|
import { usePathname } from "next/navigation"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useMemo, useState } from "react"
|
||||||
|
|
||||||
import ArcadeStats from "./_stats/arcade/arcade"
|
import ArcadeStats from "./_stats/arcade/arcade"
|
||||||
import BedwarsStats from "./_stats/bedwars/bedwars"
|
import BedwarsStats from "./_stats/bedwars/bedwars"
|
||||||
@@ -108,12 +108,17 @@ export default function PlayerStats(
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
function updateStatsOrder(arr: string[]) {
|
const cookieOpts = useMemo(() => {
|
||||||
Cookies.set(COOKIE_VALUES.statsOrder, JSON.stringify(arr), {
|
const cookieOpts: Parameters<typeof Cookies.set>[2] = {
|
||||||
secure: process.env.NODE_ENV === "production",
|
secure: process.env.NODE_ENV === "production",
|
||||||
sameSite: "lax",
|
sameSite: "lax",
|
||||||
expires: 365
|
expires: 365
|
||||||
})
|
}
|
||||||
|
return cookieOpts
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
function updateStatsOrder(arr: string[]) {
|
||||||
|
Cookies.set(COOKIE_VALUES.statsOrder, JSON.stringify(arr), cookieOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDragEnd(event: DragEndEvent) {
|
function handleDragEnd(event: DragEndEvent) {
|
||||||
@@ -134,7 +139,11 @@ export default function PlayerStats(
|
|||||||
if (layout && layout.length > 0) {
|
if (layout && layout.length > 0) {
|
||||||
setStatsOrder(layout)
|
setStatsOrder(layout)
|
||||||
}
|
}
|
||||||
}, [layout])
|
const cookie = Cookies.get(COOKIE_VALUES.statsOrder)
|
||||||
|
if (cookie) {
|
||||||
|
Cookies.set(COOKIE_VALUES.statsOrder, cookie, cookieOpts)
|
||||||
|
}
|
||||||
|
}, [layout, cookieOpts])
|
||||||
|
|
||||||
if (!isClient) {
|
if (!isClient) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user