2024-06-29 18:43:11 +00:00
|
|
|
import { getAuth } from "@/auth/queries/getauth";
|
2024-06-29 05:22:22 +00:00
|
|
|
import { shareScore } from "../token";
|
2024-06-30 18:24:33 +00:00
|
|
|
import { getDifficultyClass, getDifficultyText, getGrade } from "@/lib/helpers";
|
2024-07-07 03:57:37 +00:00
|
|
|
import {
|
|
|
|
type chuni_score_playlog,
|
|
|
|
chuni_static_music,
|
|
|
|
} from "@/prisma/schemas/artemis/generated/artemis";
|
2024-07-23 20:15:27 +00:00
|
|
|
import { generatePlaylogId, getSongsWithTitles } from "./actions";
|
2024-07-07 03:57:37 +00:00
|
|
|
|
|
|
|
type chunithm = chuni_score_playlog &
|
|
|
|
chuni_static_music & { playCount: number };
|
2024-06-29 05:22:22 +00:00
|
|
|
|
|
|
|
export default async function Share({
|
|
|
|
params,
|
|
|
|
}: {
|
|
|
|
params: { token: string; id: string };
|
|
|
|
}) {
|
|
|
|
const { token, id } = params;
|
|
|
|
|
|
|
|
// Verify the token
|
|
|
|
const tokenResult = await shareScore(token);
|
|
|
|
|
|
|
|
if (tokenResult.error) {
|
|
|
|
return <p>{tokenResult.error}</p>;
|
|
|
|
}
|
|
|
|
|
2024-06-29 21:49:55 +00:00
|
|
|
const { user } = await getAuth();
|
2024-06-29 18:43:11 +00:00
|
|
|
|
2024-06-29 21:49:55 +00:00
|
|
|
if (!user?.UserId) {
|
|
|
|
return <p>Error: No user ID found.</p>;
|
2024-06-29 18:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const userId = user?.UserId;
|
2024-06-29 05:22:22 +00:00
|
|
|
const playlogId = parseInt(id);
|
|
|
|
|
|
|
|
const songsData = await getSongsWithTitles(userId);
|
2024-06-29 07:02:21 +00:00
|
|
|
const playlogIds = await generatePlaylogId(playlogId);
|
2024-06-29 05:22:22 +00:00
|
|
|
|
2024-06-29 21:49:55 +00:00
|
|
|
// Filter songsData to match the playlogIds
|
2024-07-07 03:57:37 +00:00
|
|
|
const chunithm: chunithm[] = songsData.filter((song) =>
|
2024-06-30 18:24:33 +00:00
|
|
|
playlogIds.includes(song.id)
|
|
|
|
);
|
2024-06-29 21:49:55 +00:00
|
|
|
return (
|
2024-07-07 03:57:37 +00:00
|
|
|
<div className="flex flex-col items-center justify-center space-y-4 p-4 dark:text-black">
|
|
|
|
<div className="w-full p-4 bg-white dark:text-black rounded-sm">
|
|
|
|
{chunithm.map((song) => (
|
|
|
|
<div key={song.id} className="w-full">
|
2024-07-23 20:32:43 +00:00
|
|
|
<span className="text-black text-center font-bold text-xl pr-2">
|
2024-07-07 03:57:37 +00:00
|
|
|
{song.isNewRecord && "NEW RECORD!!"}
|
|
|
|
</span>
|
|
|
|
<span className="text-black text-center font-bold text-xl">
|
|
|
|
Song: {song.title}
|
|
|
|
</span>
|
2024-06-30 04:31:58 +00:00
|
|
|
</div>
|
|
|
|
))}
|
2024-06-30 04:17:28 +00:00
|
|
|
</div>
|
2024-06-29 05:22:22 +00:00
|
|
|
|
2024-07-07 03:57:37 +00:00
|
|
|
<div className="w-full p-4 bg-white dark:text-black rounded-sm">
|
|
|
|
{chunithm.map((song) => (
|
2024-06-30 18:24:33 +00:00
|
|
|
<div key={song.id} className="w-full">
|
2024-07-07 03:57:37 +00:00
|
|
|
<span className="text-black text-center font-bold text-xl">
|
|
|
|
Artist: {song.artist}
|
|
|
|
</span>
|
2024-06-30 18:24:33 +00:00
|
|
|
</div>
|
|
|
|
))}
|
2024-06-30 04:17:28 +00:00
|
|
|
</div>
|
2024-06-29 05:22:22 +00:00
|
|
|
|
2024-07-07 03:57:37 +00:00
|
|
|
<div className="w-full p-4 bg-white dark:text-black rounded-sm">
|
|
|
|
{chunithm.map((song) => (
|
2024-06-30 18:24:33 +00:00
|
|
|
<div key={song.id} className="w-full">
|
2024-07-07 03:57:37 +00:00
|
|
|
<span className="text-black text-center font-bold text-xl">
|
|
|
|
Score: {song.score?.toLocaleString()}
|
|
|
|
</span>
|
2024-06-30 18:24:33 +00:00
|
|
|
</div>
|
|
|
|
))}
|
2024-06-30 04:17:28 +00:00
|
|
|
</div>
|
2024-07-07 03:57:37 +00:00
|
|
|
|
|
|
|
<div className="w-full p-4 bg-white dark:text-black rounded-sm">
|
|
|
|
{chunithm.map((song) => (
|
|
|
|
<div key={song.id} className="w-full">
|
|
|
|
<span className="text-black text-center font-bold text-xl">
|
|
|
|
Rank: {getGrade(song.score ?? 0)}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="w-full p-4 bg-white dark:text-black rounded-sm">
|
|
|
|
{chunithm.map((song) => (
|
|
|
|
<div key={song.id} className="w-full">
|
|
|
|
<span className="text-black text-center font-bold text-xl">
|
|
|
|
{song.isFullCombo && "FULL COMBO"}
|
|
|
|
</span>
|
|
|
|
<span className="text-black text-center font-bold text-xl">
|
|
|
|
Max combo: {song.maxCombo}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="w-full p-4 bg-white dark:text-black rounded-sm">
|
|
|
|
{chunithm.map((song) => (
|
|
|
|
<div key={song.id} className="w-full">
|
|
|
|
<div className="flex flex-col items-center justify-center">
|
|
|
|
<span className="text-white rounded-md shadow-[inset_0px_3px_6px_0px_#1a202c] bg-[#58329F] w-full text-center p-2 font-bold text-md">
|
2024-06-30 18:24:33 +00:00
|
|
|
Judge Justice: {song.judgeJustice}
|
|
|
|
</span>
|
|
|
|
<span className="text-white rounded-md shadow-[inset_0px_3px_6px_0px_#1a202c] bg-[#58329F] w-full text-center p-2 font-bold text-md m-5">
|
|
|
|
Judge Attack: {song.judgeAttack}
|
|
|
|
</span>
|
2024-07-07 03:57:37 +00:00
|
|
|
<span className="text-white rounded-md shadow-[inset_0px_3px_6px_0px_#1a202c] bg-[#58329F] w-full text-center p-2 font-bold text-md">
|
2024-06-30 18:24:33 +00:00
|
|
|
Miss: {song.judgeGuilty}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
2024-06-30 04:17:28 +00:00
|
|
|
</div>
|
2024-06-29 21:49:55 +00:00
|
|
|
</div>
|
2024-06-29 05:22:22 +00:00
|
|
|
);
|
|
|
|
}
|