import { useRouter } from 'next/router' import Head from 'next/head' import { useEffect, useState } from 'react' import { fetchAuthorPresentationFromPool } from '@/lib/articlePublisherHelpers' import { getSeriesByAuthor } from '@/lib/seriesQueries' import { getAuthorSponsoring } from '@/lib/sponsoring' import { nostrService } from '@/lib/nostr' import type { AuthorPresentationArticle, Series } from '@/types/nostr' import { PageHeader } from '@/components/PageHeader' import { Footer } from '@/components/Footer' import { t } from '@/lib/i18n' import Link from 'next/link' import { SeriesCard } from '@/components/SeriesCard' function AuthorPageHeader({ presentation }: { presentation: AuthorPresentationArticle | null }) { if (!presentation) { return null } return (

{presentation.title || t('author.presentation')}

{presentation.content}

) } function SponsoringSummary({ totalSponsoring }: { totalSponsoring: number }) { const totalBTC = totalSponsoring / 100_000_000 return (

{t('author.sponsoring')}

{t('author.sponsoring.total', { amount: totalBTC.toFixed(6) })}

{t('author.sponsoring.sats', { amount: totalSponsoring.toLocaleString() })}

) } function SeriesList({ series }: { series: Series[]; authorPubkey: string }) { if (series.length === 0) { return (

{t('series.empty')}

) } return (

{t('series.title')}

{series.map((s) => ( {}} /> ))}
) } export default function AuthorPage() { const router = useRouter() const { pubkey } = router.query const authorPubkey = typeof pubkey === 'string' ? pubkey : '' const [presentation, setPresentation] = useState(null) const [series, setSeries] = useState([]) const [totalSponsoring, setTotalSponsoring] = useState(0) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { if (!authorPubkey) { return } const load = async () => { setLoading(true) setError(null) try { const pool = nostrService.getPool() if (!pool) { setError('Pool not initialized') setLoading(false) return } const [pres, seriesList, sponsoring] = await Promise.all([ fetchAuthorPresentationFromPool(pool as import('@/types/nostr-tools-extended').SimplePoolWithSub, authorPubkey), getSeriesByAuthor(authorPubkey), getAuthorSponsoring(authorPubkey), ]) setPresentation(pres) setSeries(seriesList) setTotalSponsoring(sponsoring) } catch (e) { setError(e instanceof Error ? e.message : 'Erreur lors du chargement') } finally { setLoading(false) } } void load() }, [authorPubkey]) if (!authorPubkey) { return null } return ( <> {t('author.title')} - {t('home.title')}
{loading &&

{t('common.loading')}

} {error &&

{error}

} {!loading && !error && presentation && ( <> )} {!loading && !error && !presentation && (

{t('author.notFound')}

)}
) }