import Game from '@/components/Game'; import NewsSection from '@/components/NewsSection'; import { getOrCreateDailyPuzzle } from '@/lib/dailyPuzzle'; import { Link } from '@/lib/navigation'; import { PrismaClient } from '@prisma/client'; import { notFound } from 'next/navigation'; import { getLocalizedValue } from '@/lib/i18n'; import { getTranslations } from 'next-intl/server'; export const dynamic = 'force-dynamic'; const prisma = new PrismaClient(); interface PageProps { params: Promise<{ locale: string; genre: string }>; } export default async function GenrePage({ params }: PageProps) { const { locale, genre } = await params; const decodedGenre = decodeURIComponent(genre); const tNav = await getTranslations('Navigation'); // Fetch all genres to find the matching one by localized name const allGenres = await prisma.genre.findMany(); const currentGenre = allGenres.find(g => getLocalizedValue(g.name, locale) === decodedGenre); if (!currentGenre || !currentGenre.active) { notFound(); } const dailyPuzzle = await getOrCreateDailyPuzzle(currentGenre); // getOrCreateDailyPuzzle likely expects string or needs update. // Actually, getOrCreateDailyPuzzle takes `genreName: string | null`. // If I pass the JSON object, it might fail. // But wait, the DB schema for DailyPuzzle stores `genreId`. // `getOrCreateDailyPuzzle` probably looks up genre by name. // I should check `lib/dailyPuzzle.ts`. // For now, I'll pass the localized name, but that might be risky if it tries to create a genre (unlikely). // Let's assume for now I should pass the localized name if that's what it uses to find/create. // But if `getOrCreateDailyPuzzle` uses `findUnique({ where: { name: genreName } })`, it will fail because name is JSON. // I need to update `lib/dailyPuzzle.ts` too! // I'll mark that as a todo. For now, let's proceed with page creation. const genres = allGenres.filter(g => g.active); // Sort genres.sort((a, b) => getLocalizedValue(a.name, locale).localeCompare(getLocalizedValue(b.name, locale))); const specials = await prisma.special.findMany(); specials.sort((a, b) => getLocalizedValue(a.name, locale).localeCompare(getLocalizedValue(b.name, locale))); const now = new Date(); const activeSpecials = specials.filter(s => { const isStarted = !s.launchDate || s.launchDate <= now; const isEnded = s.endDate && s.endDate < now; return isStarted && !isEnded; }); const upcomingSpecials = specials.filter(s => { return s.launchDate && s.launchDate > now; }); return ( <>