added clear lamps and fixed score grid size problems

This commit is contained in:
Polaris
2024-08-23 10:51:47 -04:00
parent 620874905e
commit d13fa0f2da
10 changed files with 312 additions and 131 deletions

View File

@ -1,11 +1,150 @@
"use server";
import { artemis } from "@/lib/prisma";
import { chuni_score_best } from "@/prisma/schemas/artemis/generated/artemis";
import type * as Prisma from "@prisma/client";
type ChuniScorePlaylog = Prisma.PrismaClient;
type ChuniStaticMusic = Prisma.PrismaClient;
export async function getSongsWithTitles(userId: number) {
try {
const songs: ChuniScorePlaylog[] =
await artemis.chuni_score_playlog.findMany({
where: {
user: userId,
},
orderBy: {
userPlayDate: "desc",
},
select: {
id: true,
maxCombo: true,
userPlayDate: true,
isFullCombo: true,
playerRating: true,
isAllJustice: true,
score: true,
judgeHeaven: true,
judgeGuilty: true,
judgeJustice: true,
judgeAttack: true,
judgeCritical: true,
isClear: true,
skillId: true,
skillEffect: true,
skillLevel: true,
isNewRecord: true,
musicId: true,
level: true,
rateAir: true,
rateHold: true,
rateFlick: true,
rateSlide: true,
rateTap: true,
romVersion: true,
eventId: true,
characterId: true,
charaIllustId: true,
track: true,
isContinue: true,
isFreeToPlay: true,
playKind: true,
playDate: true,
orderId: true,
sortNumber: true,
user: true,
placeId: true,
ticketId: true,
},
});
const chuniScorePlaylogMusicId = songs
.map((song) => song.musicId)
.filter((id): id is number => id !== null);
const staticMusicInfo: ChuniStaticMusic[] =
await artemis.chuni_static_music.findMany({
where: {
songId: {
in: chuniScorePlaylogMusicId,
},
},
select: {
songId: true,
title: true,
artist: true,
chartId: true,
level: true,
genre: true,
worldsEndTag: true,
jacketPath: true,
},
});
const chuniScoreBest: chuni_score_best[] =
await artemis.chuni_score_best.findMany({
where: {
musicId: {
in: chuniScorePlaylogMusicId,
},
},
select: {
id: true,
user: true,
musicId: true,
level: true,
playCount: true,
scoreMax: true,
resRequestCount: true,
resAcceptCount: true,
resSuccessCount: true,
missCount: true,
maxComboCount: true,
isFullCombo: true,
isAllJustice: true,
isSuccess: true,
fullChain: true,
maxChain: true,
scoreRank: true,
isLock: true,
ext1: true,
theoryCount: true,
},
});
const songsWithTitles = songs.map((song) => {
const staticInfo = staticMusicInfo.find(
(chuniStaticMusic) =>
chuniStaticMusic.songId === song.musicId &&
chuniStaticMusic.chartId === song.level,
);
const bestScore = chuniScoreBest.find(
(score) => score.musicId === song.musicId,
);
return {
...song,
title: staticInfo?.title || "Unknown Title",
artist: staticInfo?.artist || "Unknown Artist",
genre: staticInfo?.genre || "Unknown Genre",
chartId: staticInfo?.chartId || "Unknown chartId",
level: staticInfo?.level || "Unknown Level",
chartlevel: song.level || "Unknown Level",
playCount: bestScore?.playCount || 0,
isSuccess: bestScore?.isSuccess || 0,
jacketPath: staticInfo?.jacketPath || "",
};
});
return songsWithTitles;
} catch (error) {
console.error("Error fetching songs with titles:", error);
throw error;
}
}
export async function searchSongWithTitle(
userId: number,
searchQuery: string = "",
@ -39,32 +178,41 @@ export async function searchSongWithTitle(
},
},
select: {
songId: true,
title: true,
},
});
const playCounts = await artemis.chuni_score_playlog.groupBy({
by: ["musicId"],
_count: {
musicId: true,
},
where: {
user: userId,
musicId: {
in: chuniScorePlaylogMusicId,
const chuniScoreBest: chuni_score_best[] =
await artemis.chuni_score_best.findMany({
where: {
musicId: {
in: chuniScorePlaylogMusicId,
},
},
},
});
const playCountMap = playCounts.reduce(
(map, item) => {
if (item.musicId !== null) {
map[item.musicId] = item._count.musicId;
}
return map;
},
{} as Record<number, number>,
);
select: {
id: true,
user: true,
musicId: true,
level: true,
playCount: true,
scoreMax: true,
resRequestCount: true,
resAcceptCount: true,
resSuccessCount: true,
missCount: true,
maxComboCount: true,
isFullCombo: true,
isAllJustice: true,
isSuccess: true,
fullChain: true,
maxChain: true,
scoreRank: true,
isLock: true,
ext1: true,
theoryCount: true,
},
});
const songsWithTitles = songs.map((song) => {
const staticInfo = staticMusicInfo.find(
@ -73,9 +221,14 @@ export async function searchSongWithTitle(
chuniStaticMusic.chartId === song.level,
);
const bestScore = chuniScoreBest.find(
(score) => score.musicId === song.musicId,
);
return {
...song,
title: staticInfo?.title || "Unknown Title",
playCount: bestScore?.playCount || 0,
};
});

View File

@ -18,11 +18,11 @@ 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 { chuni_score_best } 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 };
type chunithm = chuni_score_playlog & chuni_static_music & chuni_score_best;
export const columns: ColumnDef<chunithm>[] = [
{
@ -31,7 +31,7 @@ export const columns: ColumnDef<chunithm>[] = [
cell: ({ row }) => {
const jacketPath = row.original.jacketPath?.replace(".dds", ".png");
const [isLoading, setIsLoading] = useState(true);
return (
<div className="flex w-[300px] items-center truncate font-medium">
{!jacketPath ? (
@ -40,7 +40,7 @@ export const columns: ColumnDef<chunithm>[] = [
<img
src={`/jacketArts/${jacketPath}`}
alt="Jacket"
className="mr-2 inline-block h-[40px] w-[40px]"
className="mr-2 inline-block h-[70px] w-[70px]"
/>
)}
<span className="truncate">{row.original.title}</span>
@ -53,32 +53,61 @@ export const columns: ColumnDef<chunithm>[] = [
accessorKey: "score",
header: ({ column }) => {
return (
<Button
variant="ghost"
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
>
<Button variant="ghost">
Score
<ArrowUpDown className="ml-2 h-4 w-4" />
</Button>
);
},
cell: ({ row }) => <div>{row.original.score?.toLocaleString()}</div>,
sortingFn: (a, b) => {
const highScore = a.original.score ?? 0;
const lowScore = b.original.score ?? 0;
cell: ({ row }) => {
const isSuccess = row.original.isSuccess;
const skillId = row.original.skillId;
let isSuccessText = "";
return lowScore - highScore;
switch (isSuccess) {
case 0:
isSuccessText = "Not Clear";
break;
case 1:
isSuccessText = "Clear";
break;
case 2:
isSuccessText = "Hard";
break;
case 3:
isSuccessText = "Absolute";
break;
case 4:
isSuccessText = "Absolute+";
break;
case 6:
isSuccessText = "Catastrophe";
break;
default:
isSuccessText = isSuccess?.toString() ?? "";
break;
}
return (
<div>
{row.original.score?.toLocaleString()}
<div className="mt-2 w-24 rounded-sm bg-primary pl-2 text-primary-foreground">
{isSuccessText}
</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>
);
},
},
{
accessorKey: "isNew",
header: "New",
cell: ({ row }) => (
<div className="font-medium">
{row.original.isNewRecord && <span>New!!</span>}
</div>
),
},
{
accessorKey: "grade",
header: "Grade",
@ -122,14 +151,6 @@ export const columns: ColumnDef<chunithm>[] = [
{row.original.isAllJustice && <span>All Justice</span>}
</div>
),
// 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;
// },
},
{
@ -173,13 +194,7 @@ export const columns: ColumnDef<chunithm>[] = [
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Actions</DropdownMenuLabel>
{/* <DropdownMenuItem
onClick={() =>
song.title && navigator.clipboard.writeText(song.title)
}
>
Copy song title
</DropdownMenuItem> */}
<DropdownMenuSeparator />
<DropdownMenuItem onClick={handleGenerateShareToken}>
Share Song

View File

@ -84,7 +84,7 @@ export function DataTable<TData, TValue>({
data-state={row.getIsSelected() && "selected"}
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id} className="p-5">
<TableCell key={cell.id} className="pb-2 pl-4 pt-2">
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
))}
@ -99,7 +99,7 @@ export function DataTable<TData, TValue>({
)}
</TableBody>
</Table>
<div className="py- flex items-center justify-end space-x-2 p-4">
<div className="flex items-center justify-end space-x-2 p-4">
<Button
variant="outline"
size="sm"

View File

@ -2,7 +2,7 @@ import { DataTable } from "./data-table";
import { getAuth } from "@/auth/queries/getauth";
import { z } from "zod";
import { columns } from "./colums";
import { getSongsWithTitles } from "@/app/(sharing)/[token]/[id]/actions";
import { getSongsWithTitles } from "./action";
const userSchema = z.object({
UserId: z.number(),