import { getAuth } from "@/auth/queries/getauth"; import { shareScore } from "../token"; import { getDifficultyClass, getDifficultyText, getGrade } from "@/lib/helpers"; import { type chuni_score_playlog, chuni_static_music, } from "@/prisma/schemas/artemis/generated/artemis"; import { generatePlaylogId, getSongsWithTitles } from "./actions"; type chunithm = chuni_score_playlog & chuni_static_music & { playCount: number }; export default async function Share({ params, }: { // pass the token and playlog id as params params: { token: string; id: string }; }) { const { token, id } = params; // Verify the token const tokenResult = await shareScore(token); if (tokenResult.error) { return

{tokenResult.error}

; } const { user } = await getAuth(); if (!user?.UserId) { return

Error: No user ID found.

; } const userId = user?.UserId; const playlogId = parseInt(id); const songsData = await getSongsWithTitles(userId); const playlogIds = await generatePlaylogId(playlogId); // Filter songsData to match the playlogIds const chunithm: chunithm[] = songsData.filter((song) => playlogIds.includes(song.id) ); return (
{chunithm.map((song) => (
{song.isNewRecord && "NEW RECORD!!"} Song: {song.title}
))}
{chunithm.map((song) => (
Artist: {song.artist}
))}
{chunithm.map((song) => (
Score: {song.score?.toLocaleString()}
))}
{chunithm.map((song) => (
Rank: {getGrade(song.score ?? 0)}
))}
{chunithm.map((song) => (
{song.isFullCombo && "FULL COMBO"} Max combo: {song.maxCombo}
))}
{chunithm.map((song) => (
Judge Justice: {song.judgeJustice} Judge Attack: {song.judgeAttack} Miss: {song.judgeGuilty}
))}
); }