"use client"; import { ColumnDef } from "@tanstack/react-table"; import { MoreHorizontal } from "lucide-react"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { generateShareToken } from "@/app/(sharing)/[token]/token"; import { ArrowUpDown, MoreHorizontalIcon } from "lucide-react"; import { chuni_score_playlog } from "@/prisma/schemas/artemis/generated/artemis"; import { chuni_static_music } from "@/prisma/schemas/artemis/generated/artemis"; import { getDifficultyText, getGrade } from "@/lib/helpers"; import { Skeleton } from "../ui/skeleton"; type chunithm = chuni_score_playlog & chuni_static_music & { playCount: number }; export const columns: ColumnDef[] = [ { accessorKey: "title", header: "Title", cell: ({ row }) => { const jacketPath = row.original.jacketPath?.replace(".dds", ".png"); const [isLoading, setIsLoading] = useState(true); return (
{!jacketPath ? ( ) : ( Jacket )} {row.original.title}
); }, }, { accessorKey: "score", header: ({ column }) => { return ( ); }, cell: ({ row }) =>
{row.original.score?.toLocaleString()}
, sortingFn: (a, b) => { const highScore = a.original.score ?? 0; const lowScore = b.original.score ?? 0; return lowScore - highScore; }, }, { accessorKey: "isNew", header: "Up Score", cell: ({ row }) => (
{row.original.isNewRecord && New!!}
), }, { accessorKey: "grade", header: "Grade", cell: ({ row }) => (
{getGrade(row.original.score ?? 0)}
), }, { accessorKey: "userPlayDate", header: ({ column }) => { return ( ); }, }, { accessorKey: "difficulty", header: "Difficulty", cell: ({ row }) => (
{row.original.level}
{getDifficultyText(row.original.chartId)}
), }, { accessorKey: "FC / AJ", header: "FC / AJ", cell: ({ row }) => (
{!row.original.isAllJustice && row.original.isFullCombo && ( Full Combo )} {row.original.isAllJustice && All Justice}
), // sortingFn: (a, b) => { // const isAllJustice = a.original.isAllJustice; // const defaultSort = b.original.isAllJustice; // if (isAllJustice && !defaultSort) return -1; // if (!isAllJustice && defaultSort) return 1; // return 0; // }, }, { accessorKey: "Attempts", header: "Attempts", cell: ({ row }) => (
{row.original.playCount}
), }, { id: "actions", header: () =>
More
, cell: ({ row }) => { const [error, setError] = useState(""); // eslint-disable-next-line react-hooks/rules-of-hooks const router = useRouter(); const handleGenerateShareToken = async () => { const { token, error } = await generateShareToken(row.original.id); if (error) { setError(error); } else { const newTab = window.open(`/${token}/${row.original.id}`); if (newTab) { newTab.focus(); } else { router.push(`/${token}/${row.original.id}`); } } }; return ( Actions {/* song.title && navigator.clipboard.writeText(song.title) } > Copy song title */} Share Song ); }, }, ];