import React, { useState, useEffect } from 'react'; import { api } from '../../api/client'; interface EmbedProps { url: string; } interface Metadata { title?: string; description?: string; image?: string; siteName?: string; } export function Embed({ url }: EmbedProps) { const [metadata, setMetadata] = useState(null); const [isLoading, setIsLoading] = useState(true); useEffect(() => { let isMounted = true; // Simple fetch from our new API fetch(`/api/utils/metadata?url=${encodeURIComponent(url)}`, { headers: { 'Authorization': `Bearer ${localStorage.getItem('backspace_token')}` } }) .then(res => res.json()) .then(data => { if (isMounted && data.title) { setMetadata(data); } setIsLoading(false); }) .catch(() => { if (isMounted) setIsLoading(false); }); return () => { isMounted = false; }; }, [url]); if (isLoading || !metadata) return null; return (
{metadata.siteName && (
{metadata.siteName}
)} {metadata.title && ( {metadata.title} )} {metadata.description && (
{metadata.description}
)}
{metadata.image && (
)}
); }