daphnis/app/(sharing)/[token]/[id]/page.tsx
2024-06-30 00:31:58 -04:00

64 lines
2.1 KiB
TypeScript

import { getAuth } from "@/auth/queries/getauth";
import { generatePlaylogId, getSongsWithTitles } from "@/lib/api";
import { shareScore } from "../token";
import { getDifficultyClass, getDifficultyText } from "@/lib/helpers";
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>;
}
const { user } = await getAuth();
if (!user?.UserId) {
return <p>Error: No user ID found.</p>;
}
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 matchedSongs = songsData.filter((song) => playlogIds.includes(song.id));
return (
<div className=" h-screen grid w-full gap-4 bg-red-200 grid-cols-8 grid-rows-9 rounded-lg shadow-md">
<div className="col-span-2 row-span-1 row-start-2 col-start-2 bg-pink-200 rounded-lg shadow-md flex items-center justify-center">
{matchedSongs.map((song) => (
<div key={song.id} className=" flex justify-center items-center">
<div className="text-white text-lg">
<p>Score: {song.score}</p>
</div>
</div>
))}
</div>
<div className="col-span-4 row-span-4 row-start-2 bg-lime-200 rounded-lg shadow-md flex items-center justify-center">
<p>Broccoli</p>
</div>
<div className="col-span-2 col-start-2 row-span-3 row-start-3 bg-yellow-200 rounded-lg shadow-md flex items-center justify-center">
<p>Tamago</p>
</div>
<div className="col-span-2 col-start-2 row-span-2 bg-yellow-200 rounded-lg shadow-md flex items-center justify-center">
<p>Pork</p>
</div>
<div className="col-span-4 col-start-4 row-span-1 bg-green-200 rounded-lg shadow-md flex items-center justify-center">
<p>Edamame</p>
</div>
</div>
);
}