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,
|
|
|
|
}: {
|
2024-07-23 21:33:15 +00:00
|
|
|
// pass the token and playlog id as params www.www.com/generatedtoken/playlogid
|
2024-06-29 05:22:22 +00:00
|
|
|
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-07-28 05:24:54 +00:00
|
|
|
playlogIds.includes(song.id),
|
2024-06-30 18:24:33 +00:00
|
|
|
);
|
2024-06-29 21:49:55 +00:00
|
|
|
return (
|
2024-07-28 05:24:54 +00:00
|
|
|
<div className="flex flex-col items-center justify-center space-y-4 p-4 dark:text-black">
|
|
|
|
<div className="w-full rounded-sm bg-white p-4 dark:text-black">
|
2024-07-07 03:57:37 +00:00
|
|
|
{chunithm.map((song) => (
|
|
|
|
<div key={song.id} className="w-full">
|
2024-07-28 05:24:54 +00:00
|
|
|
<span className="text-center text-xl font-bold text-black">
|
2024-07-07 03:57:37 +00:00
|
|
|
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-28 05:24:54 +00:00
|
|
|
<div className="w-full rounded-sm bg-white p-4 dark:text-black">
|
2024-07-07 03:57:37 +00:00
|
|
|
{chunithm.map((song) => (
|
2024-06-30 18:24:33 +00:00
|
|
|
<div key={song.id} className="w-full">
|
2024-07-28 05:24:54 +00:00
|
|
|
<span className="text-center text-xl font-bold text-black">
|
2024-07-07 03:57:37 +00:00
|
|
|
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-28 05:24:54 +00:00
|
|
|
<div className="w-full rounded-sm bg-white p-4 dark:text-black">
|
2024-07-07 03:57:37 +00:00
|
|
|
{chunithm.map((song) => (
|
2024-06-30 18:24:33 +00:00
|
|
|
<div key={song.id} className="w-full">
|
2024-07-28 05:24:54 +00:00
|
|
|
<span className="text-center text-xl font-bold text-black">
|
2024-07-07 03:57:37 +00:00
|
|
|
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
|
|
|
|
2024-07-28 05:24:54 +00:00
|
|
|
<div className="w-full rounded-sm bg-white p-4 dark:text-black">
|
2024-07-07 03:57:37 +00:00
|
|
|
{chunithm.map((song) => (
|
|
|
|
<div key={song.id} className="w-full">
|
2024-07-28 05:24:54 +00:00
|
|
|
<span className="text-center text-xl font-bold text-black">
|
2024-07-07 03:57:37 +00:00
|
|
|
Rank: {getGrade(song.score ?? 0)}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
|
2024-07-28 05:24:54 +00:00
|
|
|
<div className="w-full rounded-sm bg-white p-4 dark:text-black">
|
2024-07-07 03:57:37 +00:00
|
|
|
{chunithm.map((song) => (
|
|
|
|
<div key={song.id} className="w-full">
|
2024-07-28 05:24:54 +00:00
|
|
|
<span className="pr-2 text-center text-xl font-bold text-black">
|
|
|
|
{song.isFullCombo && "FULL COMBO!"}
|
2024-07-07 03:57:37 +00:00
|
|
|
</span>
|
2024-07-28 05:24:54 +00:00
|
|
|
<span className="text-center text-xl font-bold text-black">
|
2024-07-07 03:57:37 +00:00
|
|
|
Max combo: {song.maxCombo}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
|
2024-07-28 05:24:54 +00:00
|
|
|
<div className="w-full rounded-sm bg-white p-4 dark:text-black">
|
2024-07-07 03:57:37 +00:00
|
|
|
{chunithm.map((song) => (
|
|
|
|
<div key={song.id} className="w-full">
|
|
|
|
<div className="flex flex-col items-center justify-center">
|
2024-07-28 05:24:54 +00:00
|
|
|
<span className="text-md w-full rounded-md bg-[#58329F] p-2 text-center font-bold text-white shadow-[inset_0px_3px_6px_0px_#1a202c]">
|
2024-06-30 18:24:33 +00:00
|
|
|
Judge Justice: {song.judgeJustice}
|
|
|
|
</span>
|
2024-07-28 05:24:54 +00:00
|
|
|
<span className="text-md m-5 w-full rounded-md bg-[#58329F] p-2 text-center font-bold text-white shadow-[inset_0px_3px_6px_0px_#1a202c]">
|
2024-06-30 18:24:33 +00:00
|
|
|
Judge Attack: {song.judgeAttack}
|
|
|
|
</span>
|
2024-07-28 05:24:54 +00:00
|
|
|
<span className="text-md w-full rounded-md bg-[#58329F] p-2 text-center font-bold text-white shadow-[inset_0px_3px_6px_0px_#1a202c]">
|
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
|
|
|
);
|
|
|
|
}
|