"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 { getGrade } from "@/lib/helpers"; 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"); 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; if (highScore < lowScore) return 1; if (highScore > lowScore) return -1; // TODO: FIGURE OUT DEFAULT SORT return 0; }, }, { 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}
, }, { accessorKey: "FC / AJ", header: ({ column }) => { return ( ); }, 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 song = row.original; const [error, setError] = useState(""); 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}`, "_blank"); if (newTab) { newTab.focus(); } else { // Handle popup blocker or inability to open new tab router.push(`/${token}/${row.original.id}`); } } }; return ( Actions song.title && navigator.clipboard.writeText(song.title) } > Copy song title Share Song ); }, }, ];