import { useRouter } from 'next/router' import Head from 'next/head' import { useEffect, useState } from 'react' import { getSeriesById } from '@/lib/seriesQueries' import { getSeriesAggregates } from '@/lib/seriesAggregation' import { getArticlesBySeries } from '@/lib/articleQueries' import type { Series, Article } from '@/types/nostr' import { SeriesStats } from '@/components/SeriesStats' import { ArticleCard } from '@/components/ArticleCard' import { t } from '@/lib/i18n' import Image from 'next/image' import { ArticleReviews } from '@/components/ArticleReviews' function SeriesHeader({ series }: { series: Series }) { return (
{series.coverUrl && (
{series.title}
)}

{series.title}

{series.description}

{t('category.science-fiction')}: {series.category === 'science-fiction' ? t('category.science-fiction') : t('category.scientific-research')}

{series.preview && (

{series.preview}

)}
) } export default function SeriesPage() { const router = useRouter() const { id } = router.query const seriesId = typeof id === 'string' ? id : '' const { series, articles, aggregates, loading, error } = useSeriesPageData(seriesId) if (!seriesId) { return null } return ( <> Série - zapwall.fr
{loading &&

{t('common.loading')}

} {error &&

{error}

} {series && ( <> )}
) } function SeriesPublications({ articles }: { articles: Article[] }) { if (articles.length === 0) { return

Aucune publication pour cette série.

} return (

{t('series.publications')}

{articles.map((a) => (
{}} />
))}
) } function useSeriesPageData(seriesId: string) { const [series, setSeries] = useState(null) const [articles, setArticles] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [aggregates, setAggregates] = useState<{ sponsoring: number; purchases: number; reviewTips: number } | null>(null) useEffect(() => { if (!seriesId) { return } const load = async () => { setLoading(true) setError(null) try { const s = await getSeriesById(seriesId) if (!s) { setError('Série introuvable') setLoading(false) return } setSeries(s) const [agg, seriesArticles] = await Promise.all([ getSeriesAggregates({ authorPubkey: s.pubkey, seriesId: s.id }), getArticlesBySeries(s.id), ]) setAggregates(agg) setArticles(seriesArticles) } catch (e) { setError(e instanceof Error ? e.message : 'Erreur lors du chargement de la série') } finally { setLoading(false) } } void load() }, [seriesId]) return { series, articles, aggregates, loading, error } }