daphnis/components/scoreplaylog/colums.tsx

144 lines
3.7 KiB
TypeScript
Raw Normal View History

2024-06-29 05:22:22 +00:00
"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";
2024-07-07 15:07:23 +00:00
import { ArrowUpDown, MoreHorizontalIcon } from "lucide-react";
2024-06-30 18:24:33 +00:00
import { chuni_score_playlog } from "@/prisma/schemas/artemis/generated/artemis";
import { chuni_static_music } from "@/prisma/schemas/artemis/generated/artemis";
import { chuni_score_best } from "@/prisma/schemas/artemis/generated/artemis";
import { getDifficultyText, getGrade } from "@/lib/helpers";
import { Skeleton } from "../ui/skeleton";
import ActionsCell from "./moreAction";
2024-08-25 04:08:45 +00:00
type chunithm = chuni_score_playlog &
chuni_static_music & { playCount: number };
2024-07-01 17:42:57 +00:00
export const columns: ColumnDef<chunithm>[] = [
2024-06-29 05:22:22 +00:00
{
accessorKey: "title",
header: "Title",
2024-07-07 14:24:04 +00:00
2024-07-01 18:19:20 +00:00
cell: ({ row }) => {
const jacketPath = row.original.jacketPath?.replace(".dds", ".png");
2024-07-01 18:19:20 +00:00
return (
<div className="flex w-[300px] items-center truncate font-medium">
2024-07-21 17:24:31 +00:00
{!jacketPath ? (
<Skeleton className="mr-2 inline-block h-8 w-8" />
) : (
2024-07-01 18:19:20 +00:00
<img
src={`/jacketArts/${jacketPath}`}
2024-07-01 18:19:20 +00:00
alt="Jacket"
className="mr-2 inline-block h-[70px] w-[70px]"
2024-07-01 18:19:20 +00:00
/>
)}
2024-07-21 15:35:22 +00:00
<span className="truncate">{row.original.title}</span>
2024-07-01 18:19:20 +00:00
</div>
);
},
2024-07-01 16:47:02 +00:00
},
2024-07-01 18:19:20 +00:00
2024-07-01 16:47:02 +00:00
{
accessorKey: "score",
2024-07-07 15:07:23 +00:00
header: ({ column }) => {
return (
<Button variant="ghost">
2024-07-07 15:07:23 +00:00
Score
<ArrowUpDown className="ml-2 h-4 w-4" />
</Button>
);
},
cell: ({ row }) => {
return (
<div>
{row.original.score?.toLocaleString()}
<div className="mt-2 w-24 rounded-sm bg-primary pl-2 text-primary-foreground">
2024-08-25 04:08:45 +00:00
e
</div>
<div
className={`mt-2 w-24 rounded-sm pl-2 ${
row.original.isNewRecord
? "bg-primary text-primary-foreground"
: "invisible"
}`}
>
<span>New!!</span>
</div>
</div>
);
2024-07-07 15:46:39 +00:00
},
2024-07-07 14:24:04 +00:00
},
2024-07-07 14:24:04 +00:00
{
accessorKey: "grade",
header: "Grade",
cell: ({ row }) => (
<div className="font-medium"> {getGrade(row.original.score ?? 0)}</div>
),
},
2024-07-01 16:47:02 +00:00
{
accessorKey: "userPlayDate",
2024-07-07 15:07:23 +00:00
header: ({ column }) => {
return (
<Button
variant="ghost"
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
>
Date
<ArrowUpDown className="ml-2 h-4 w-4" />
</Button>
);
},
2024-07-01 16:47:02 +00:00
},
2024-07-07 14:24:04 +00:00
{
accessorKey: "difficulty",
header: "Difficulty",
cell: ({ row }) => (
<div className="font-medium">
2024-08-16 19:25:14 +00:00
{row.original.level}
<br />
{getDifficultyText(row.original.chartId)}
</div>
),
2024-07-07 14:24:04 +00:00
},
2024-07-01 16:47:02 +00:00
{
accessorKey: "FC / AJ",
header: "FC / AJ",
2024-06-29 05:22:22 +00:00
cell: ({ row }) => (
2024-07-07 15:46:39 +00:00
<div className="font-medium">
{!row.original.isAllJustice && row.original.isFullCombo && (
<span>Full Combo</span>
)}
{row.original.isAllJustice && <span>All Justice</span>}
2024-06-29 05:22:22 +00:00
</div>
),
},
2024-07-07 14:24:04 +00:00
2024-06-29 05:22:22 +00:00
{
2024-07-01 16:47:02 +00:00
accessorKey: "Attempts",
header: "Attempts",
2024-07-07 15:07:23 +00:00
2024-07-01 17:42:57 +00:00
cell: ({ row }) => (
<div className="font-medium">{row.original.playCount}</div>
),
2024-06-29 05:22:22 +00:00
},
// for fixing react-hooks/rules-of-hooks
2024-06-29 05:22:22 +00:00
{
id: "actions",
header: () => <div className="pl-2 text-left">More</div>,
cell: ({ row }) => <ActionsCell row={row} />,
2024-06-29 05:22:22 +00:00
},
];