import { useEffect, useState } from "react"; import { useParams } from "react-router-dom"; import { Download } from "lucide-react"; import { API_BASE } from "../../api/client"; interface ShareData { output_filename: string; segment_filename: string | null; created_at: string; } export default function SharedView() { const { shareId } = useParams<{ shareId: string }>(); const [imageUrl, setImageUrl] = useState(null); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { if (!shareId) { setError("ID de sesión inválido"); setLoading(false); return; } fetch(`${API_BASE}/api/share/${shareId}`) .then((res) => { if (!res.ok) throw new Error("Sesión compartida no encontrada o expirada"); return res.json() as Promise; }) .then((data) => { setImageUrl(`${API_BASE}/seg/image/${data.output_filename}`); }) .catch((err: Error) => setError(err.message)) .finally(() => setLoading(false)); }, [shareId]); const handleDownload = async () => { if (!imageUrl) return; const res = await fetch(imageUrl); const blob = await res.blob(); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = `hyper-reality-${shareId}.jpg`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }; if (loading) { return (
Cargando diseño compartido...
); } if (error) { return (

{error}

Este enlace puede haber expirado. Los diseños compartidos se mantienen mientras el servidor esté activo.

); } return (
{/* Header */}
Hyper Reality Visualizer
{/* Image */}
{imageUrl && ( Diseño de habitación compartido )}
{/* Footer */}
Diseñado con{" "} Hyper Reality Visualizer
); }