import { useEffect, useState } from 'react' import MagicCard from './MagicCard' import { fetchPersonalizedFeed } from '../services/feedService' import type { Article } from '../types/article' type FeedContentProps = { sentimentFilter?: string | null topicsFilter?: string | null } function FeedContent({ sentimentFilter = null, topicsFilter = null }: FeedContentProps) { const [articles, setArticles] = useState([]) const [status, setStatus] = useState<'loading' | 'ok' | 'error'>('loading') // Prende il fetch del feed personalizzato e popola la variabile di stato con i dati useEffect(() => {fetchPersonalizedFeed().then((data) => { setArticles(data) setStatus('ok') }) .catch(() => setStatus('error')) }, []) return (

BriefAI Notizie

Il tuo flusso di intelligenza

Notizie personalizzate con approfondimenti AI

{/* Gestione degli stati*/} {status === 'loading' &&

Caricamento feed...

} {status === 'error' &&

Errore nel caricamento del feed.

} {/*Render della lista di articoli se il caricamento รจ andato a buon fine*/} {status === 'ok' && ( <> {/* Client-side filtering */} {(() => { const matchesTopic = (a: Article) => { if (!topicsFilter || topicsFilter === 'All Topics') return true const topic = topicsFilter.toLowerCase() const catMatch = (a.category || '').toLowerCase() === topic const trending = (a.trendingTopics || []).some((t) => String(t || '').toLowerCase() === topic ) const macroTopicMatch = (a.macroTopics || []).some((t) => String(t || '').toLowerCase() === topic ) return catMatch || trending || macroTopicMatch } const matchesSentiment = (a: Article) => { if (!sentimentFilter || sentimentFilter === 'All Sentiment') return true return a.sentiment === sentimentFilter } const filtered = articles.filter((a) => matchesSentiment(a) && matchesTopic(a)) return (
{filtered.length > 0 ? ( <>
{filtered.map((a) => ( ))}

Mostrando {filtered.length} di {articles.length} articoli {(sentimentFilter && sentimentFilter !== 'All Sentiment') || (topicsFilter && topicsFilter !== 'All Topics') ? ` con${sentimentFilter && sentimentFilter !== 'All Sentiment' ? ` sentiment ${sentimentFilter}` : ''}${ sentimentFilter && topicsFilter ? ' e' : '' }${topicsFilter && topicsFilter !== 'All Topics' ? ` topic ${topicsFilter}` : ''}` : ''}

) : (

Nessun articolo trovato con i filtri selezionati

)}
) })()} )}
) } export default FeedContent