'use client'; import { useEffect, useState } from 'react'; import { useRouter, useParams } from 'next/navigation'; import Header from '../../components/Header'; import Sidebar from '../../components/Sidebar'; import AppIframeViewer from '../../components/AppIframeViewer'; import type { User, GeneratedApp } from '@/types'; export default function AppDetailPage() { const [user, setUser] = useState(null); const [app, setApp] = useState(null); const [isLoading, setIsLoading] = useState(true); const router = useRouter(); const params = useParams(); const id = params?.id as string; useEffect(() => { // Fetch current user fetch('/api/auth/me') .then(res => { if (!res.ok) { router.push('/login'); return null; } return res.json(); }) .then(data => { if (data) setUser(data); }) .catch(() => router.push('/login')); // Fetch app if (id) { fetch(`/api/apps/${id}`) .then(res => { if (!res.ok) throw new Error('App not found'); return res.json(); }) .then(data => { setApp(data); }) .catch(() => router.push('/apps')) .finally(() => setIsLoading(false)); } }, [id, router]); const handleLoadComplete = () => { console.log('App iframe loaded'); }; if (isLoading || !app) { return (
); } return (

{app.title}

{app.description && (

{app.description}

)}
{app.appType && ( {app.appType} )} {app.status}
{app.status === 'completed' && ( )} {app.status === 'generating' && (

Generating app...

)} {app.status === 'failed' && (

App generation failed

)}
); }