import { auth } from "@/lib/auth" import { redirect } from "next/navigation" import { prisma } from "@/lib/prisma" import Link from "next/link" import PhotoThumbnail from "@/components/PhotoThumbnail" import DeletePhotoButton from "@/components/DeletePhotoButton" // Enable caching for this page export const revalidate = 60 // Revalidate every 60 seconds export default async function PhotosPage() { const session = await auth() if (!session) { redirect("/login") } // Limit to 50 photos per page for performance const photos = await prisma.photo.findMany({ take: 50, orderBy: { createdAt: "desc" }, include: { uploader: { select: { name: true, }, }, }, }) return (

All Photos

{photos.length === 0 ? (

No photos yet. Be the first to upload one!

) : (
{photos.map((photo: { id: string; url: string; answerName: string; points: number; createdAt: Date; uploader: { name: string } }) => (

Uploaded by {photo.uploader.name}

{photo.points} {photo.points === 1 ? "pt" : "pts"}

{new Date(photo.createdAt).toLocaleDateString()}

{session.user.role === "ADMIN" && (
)}
))}
)}
) }