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' import Image from 'next/image' function AuthorPageHeader({ presentation }: { presentation: AuthorPresentationArticle | null }) { if (!presentation) { return null } return (
{presentation.bannerUrl && (
Profile picture
)}

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

{t('author.profileNote')}

{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) => ( {}} /> ))}
) } async function loadAuthorData(authorPubkey: string) { const pool = nostrService.getPool() if (!pool) { throw new Error('Pool not initialized') } const [pres, seriesList, sponsoring] = await Promise.all([ fetchAuthorPresentationFromPool(pool as import('@/types/nostr-tools-extended').SimplePoolWithSub, authorPubkey), getSeriesByAuthor(authorPubkey), getAuthorSponsoring(authorPubkey), ]) return { pres, seriesList, sponsoring } } function useAuthorData(authorPubkey: string) { 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 { pres, seriesList, sponsoring } = await loadAuthorData(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]) return { presentation, series, totalSponsoring, loading, error } } function AuthorPageContent({ presentation, series, totalSponsoring, authorPubkey, loading, error, }: { presentation: AuthorPresentationArticle | null series: Series[] totalSponsoring: number authorPubkey: string loading: boolean error: string | null }) { if (loading) { return

{t('common.loading')}

} if (error) { return

{error}

} if (presentation) { return ( <> ) } return (

{t('author.notFound')}

) } export default function AuthorPage() { const router = useRouter() const { pubkey } = router.query const authorPubkey = typeof pubkey === 'string' ? pubkey : '' const { presentation, series, totalSponsoring, loading, error } = useAuthorData(authorPubkey) if (!authorPubkey) { return null } return ( <> {t('author.title')} - {t('home.title')}
) }