"use client"; import { useEffect, useState } from "react"; import { useAuth } from "@/lib/auth-context"; import { useRouter } from "next/navigation"; interface UploadedFile { id: string; original_name: string; file_path: string; upload_status: string; created_at: string; } export default function RendersPage() { const { isAuthenticated, user } = useAuth(); const router = useRouter(); const [files, setFiles] = useState([]); const [loading, setLoading] = useState(true); const [authInitialized, setAuthInitialized] = useState(false); const [deletingId, setDeletingId] = useState(null); useEffect(() => { const timer = setTimeout(() => setAuthInitialized(true), 100); return () => clearTimeout(timer); }, []); useEffect(() => { if (!authInitialized) return; if (!isAuthenticated || !user) { router.push("/login?redirect=/renders"); return; } fetchFiles(); // eslint-disable-next-line }, [authInitialized, isAuthenticated, user]); async function fetchFiles() { try { const res = await fetch("/api/renders/in", { headers: { "user-id": user?.id }, }); const data = await res.json(); setFiles(data.files || []); } catch { setFiles([]); } finally { setLoading(false); } } async function handleDelete(id: string) { if (!user) return; const ok = confirm("Delete this file? This cannot be undone."); if (!ok) return; setDeletingId(id); try { const res = await fetch("/api/renders/in", { method: "DELETE", headers: { "Content-Type": "application/json", "user-id": user.id, }, body: JSON.stringify({ id }), }); const data = await res.json(); if (!res.ok) throw new Error(data?.error || "Delete failed"); await fetchFiles(); } catch (e) { alert((e as any).message || "Delete failed"); } finally { setDeletingId(null); } } if (!authInitialized || !isAuthenticated) { return (
Loading...
); } return (

My Renders

Uploaded Files

{loading ? (
Loading...
) : files.length === 0 ? (
No files uploaded yet.
) : ( {files.map((f) => ( ))}
Filename Status Uploaded At Download Actions
{f.original_name} {f.upload_status} {new Date(f.created_at).toLocaleString()} Download
)}

Rendered Files (outputs)

Placeholder: Your rendered products will appear here in the future!
); }