import { auth } from "@/lib/auth" import { redirect } from "next/navigation" import { prisma } from "@/lib/prisma" import GuessForm from "@/components/GuessForm" import PhotoImage from "@/components/PhotoImage" import DeletePhotoButton from "@/components/DeletePhotoButton" // Enable caching for this page export const revalidate = 60 // Revalidate every 60 seconds export default async function PhotoPage({ params }: { params: Promise<{ id: string }> }) { const session = await auth() if (!session) { redirect("/login") } const { id } = await params const photo = await prisma.photo.findUnique({ where: { id }, include: { uploader: { select: { name: true, }, }, guesses: { where: { userId: session.user.id, }, orderBy: { createdAt: "desc", }, }, }, }) if (!photo) { return (
Photo not found
Uploaded by {photo.uploader.name} on{" "} {new Date(photo.createdAt).toLocaleDateString()}
✅ Correct! You guessed it right!
The answer was: {photo.answerName}
You earned {photo.points} {photo.points === 1 ? "point" : "points"}!
❌ Wrong guess. Try again!
Your last guess: {userGuess.guessText}
{photoWithFields.penaltyEnabled && photoWithFields.penaltyPoints > 0 && (You lost {photoWithFields.penaltyPoints} {photoWithFields.penaltyPoints === 1 ? "point" : "points"} for this wrong guess.
)}Remaining attempts: {remainingAttempts} of {maxAttempts}
⚠️ Maximum attempts reached
You have used all {maxAttempts} {maxAttempts === 1 ? "attempt" : "attempts"} for this photo.
📸 This is your photo
You cannot guess on photos you uploaded. The answer is: {photo.answerName}