daphnis/app/(sharing)/[token]/[id]/page.tsx

119 lines
4.0 KiB
TypeScript
Raw Normal View History

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";
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";
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
const chunithm: chunithm[] = songsData.filter((song) =>
playlogIds.includes(song.id),
2024-06-30 18:24:33 +00:00
);
2024-06-29 21:49:55 +00:00
return (
<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">
{chunithm.map((song) => (
<div key={song.id} className="w-full">
<span className="text-center text-xl font-bold text-black">
Song: {song.title}
</span>
2024-06-30 04:31:58 +00:00
</div>
))}
</div>
2024-06-29 05:22:22 +00:00
<div className="w-full rounded-sm bg-white p-4 dark:text-black">
{chunithm.map((song) => (
2024-06-30 18:24:33 +00:00
<div key={song.id} className="w-full">
<span className="text-center text-xl font-bold text-black">
Artist: {song.artist}
</span>
2024-06-30 18:24:33 +00:00
</div>
))}
</div>
2024-06-29 05:22:22 +00:00
<div className="w-full rounded-sm bg-white p-4 dark:text-black">
{chunithm.map((song) => (
2024-06-30 18:24:33 +00:00
<div key={song.id} className="w-full">
<span className="text-center text-xl font-bold text-black">
Score: {song.score?.toLocaleString()}
</span>
2024-06-30 18:24:33 +00:00
</div>
))}
</div>
<div className="w-full rounded-sm bg-white p-4 dark:text-black">
{chunithm.map((song) => (
<div key={song.id} className="w-full">
<span className="text-center text-xl font-bold text-black">
Rank: {getGrade(song.score ?? 0)}
</span>
</div>
))}
</div>
<div className="w-full rounded-sm bg-white p-4 dark:text-black">
{chunithm.map((song) => (
<div key={song.id} className="w-full">
<span className="pr-2 text-center text-xl font-bold text-black">
{song.isFullCombo && "FULL COMBO!"}
</span>
<span className="text-center text-xl font-bold text-black">
Max combo: {song.maxCombo}
</span>
</div>
))}
</div>
<div className="w-full rounded-sm bg-white p-4 dark:text-black">
{chunithm.map((song) => (
<div key={song.id} className="w-full">
<div className="flex flex-col items-center justify-center">
<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>
<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>
<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>
))}
</div>
2024-06-29 21:49:55 +00:00
</div>
2024-06-29 05:22:22 +00:00
);
}