import { headers } from 'next/headers' import Link from 'next/link' import { CreateSceneButton } from '@/components/save-button' import type { SceneMeta } from '@/components/scene-loader' export const dynamic = 'force-dynamic' async function resolveBaseUrl(): Promise { if (process.env.NEXT_PUBLIC_APP_URL) { return process.env.NEXT_PUBLIC_APP_URL } const h = await headers() const host = h.get('x-forwarded-host') ?? h.get('host') const proto = h.get('x-forwarded-proto') ?? 'http' if (!host) { return 'http://localhost:3000' } return `${proto}://${host}` } async function fetchScenes(): Promise { const base = await resolveBaseUrl() const response = await fetch(`${base}/api/scenes?limit=50`, { cache: 'no-store', }) if (!response.ok) { return [] } const payload = (await response.json()) as { scenes?: SceneMeta[] } | SceneMeta[] if (Array.isArray(payload)) { return payload } return payload.scenes ?? [] } function formatDate(iso: string): string { try { return new Date(iso).toLocaleString() } catch { return iso } } export default async function ScenesPage() { const scenes = await fetchScenes() return (

Your scenes

{scenes.length === 0 ? 'No scenes yet. Create one to get started.' : `${scenes.length} scene${scenes.length === 1 ? '' : 's'}.`}

{scenes.length === 0 ? (

You haven't saved any scenes yet.

) : (
    {scenes.map((scene) => (
  • {scene.thumbnailUrl ? ( // eslint-disable-next-line @next/next/no-img-element {scene.name} ) : ( No thumbnail )}

    {scene.name}

    {scene.nodeCount} nodes
  • ))}
)}
) }