import Link from 'next/link' import Image from 'next/image' import { useRouter } from 'next/router' import { useNostrAuth } from '@/hooks/useNostrAuth' import { useAuthorPresentation } from '@/hooks/useAuthorPresentation' import { useEffect, useState } from 'react' import { Button, Card } from './ui' import { t } from '@/lib/i18n' import type { Article } from '@/types/nostr' function CreateAuthorPageLink(): React.ReactElement { return ( ) } function AuthorProfileLink({ presentation, profile }: { presentation: Article; profile: { name?: string; picture?: string } | null }): React.ReactElement { // Extract author name from presentation title or profile // Title format: "Présentation de " or just use profile name let authorName = presentation.title.replace(/^Présentation de /, '').trim() if (!authorName || authorName === 'Présentation') { authorName = profile?.name ?? t('common.author') } // Extract picture from presentation (bannerUrl or from JSON metadata) or profile const picture = presentation.bannerUrl ?? profile?.picture const router = useRouter() const handleClick = (): void => { void router.push(`/author/${presentation.pubkey}`) } return ( {picture ? (
{authorName}
) : (
{authorName.charAt(0).toUpperCase()}
)} {authorName}
) } export function ConditionalPublishButton(): React.ReactElement { const { connected, pubkey, profile } = useNostrAuth() const { checkPresentationExists } = useAuthorPresentation(pubkey ?? null) const [presentation, setPresentation] = useState
(null) useEffect(() => { const check = async (): Promise => { if (!connected || !pubkey) { setPresentation(null) return } // Check for presentation asynchronously, but don't show loading state const pres = await checkPresentationExists() setPresentation(pres) } void check() }, [connected, pubkey, checkPresentationExists]) if (!connected || !pubkey) { return } // If presentation exists, show author profile link with image/fallback if (presentation) { return } // Otherwise, show create author page button immediately (no loading state) return }