import { useState, useCallback } from 'react' import { useNostrAuth } from '@/hooks/useNostrAuth' import { useAuthorPresentation } from '@/hooks/useAuthorPresentation' import { ArticleField } from './ArticleField' import { ArticleFormButtons } from './ArticleFormButtons' import { ConnectButton } from './ConnectButton' import { ImageUploadField } from './ImageUploadField' import { t } from '@/lib/i18n' interface AuthorPresentationDraft { presentation: string contentDescription: string mainnetAddress: string pictureUrl?: string } const ADDRESS_PATTERN = /^(1|3|bc1)[a-zA-Z0-9]{25,62}$/ function NotConnected() { return (

{t('presentation.notConnected')}

) } function SuccessNotice() { return (

{t('presentation.success')}

{t('presentation.successMessage')}

) } function ValidationError({ message }: { message: string | null }) { if (!message) { return null } return (

{message}

) } function PresentationField({ draft, onChange, }: { draft: AuthorPresentationDraft onChange: (next: AuthorPresentationDraft) => void }) { return ( onChange({ ...draft, presentation: value as string })} required type="textarea" rows={6} placeholder="Présentez-vous : qui êtes-vous, votre parcours, vos intérêts..." helpText="Cette présentation sera visible par tous les lecteurs" /> ) } function ContentDescriptionField({ draft, onChange, }: { draft: AuthorPresentationDraft onChange: (next: AuthorPresentationDraft) => void }) { return ( onChange({ ...draft, contentDescription: value as string })} required type="textarea" rows={6} placeholder="Décrivez le type de contenu que vous publiez : science-fiction, recherche scientifique, thèmes abordés..." helpText="Aidez les lecteurs à comprendre le type d'articles que vous publiez" /> ) } function MainnetAddressField({ draft, onChange, }: { draft: AuthorPresentationDraft onChange: (next: AuthorPresentationDraft) => void }) { return ( onChange({ ...draft, mainnetAddress: value as string })} required type="text" placeholder="1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa" helpText="Adresse Bitcoin mainnet où vous recevrez les paiements de sponsoring (0.046 BTC par sponsoring)" /> ) } function PictureField({ draft, onChange, }: { draft: AuthorPresentationDraft onChange: (next: AuthorPresentationDraft) => void }) { return ( onChange({ ...draft, pictureUrl: url })} helpText="Image de profil pour votre page auteur (max 5Mo, formats: PNG, JPG, WebP)" /> ) } const PresentationFields = ({ draft, onChange, }: { draft: AuthorPresentationDraft onChange: (next: AuthorPresentationDraft) => void }) => (
) function PresentationForm({ draft, setDraft, validationError, error, loading, handleSubmit, userName, }: { draft: AuthorPresentationDraft setDraft: (next: AuthorPresentationDraft) => void validationError: string | null error: string | null loading: boolean handleSubmit: (e: React.FormEvent) => Promise userName: string }) { return (
{ void handleSubmit(e) }} className="border border-neon-cyan/20 rounded-lg p-6 bg-cyber-dark space-y-4" >

{userName}

{t('presentation.description')}

{t('presentation.profileNote')}

) } function useAuthorPresentationState(pubkey: string | null) { const { loading, error, success, publishPresentation } = useAuthorPresentation(pubkey) const [draft, setDraft] = useState({ presentation: '', contentDescription: '', mainnetAddress: '', }) const [validationError, setValidationError] = useState(null) const handleSubmit = useCallback( async (e: React.FormEvent) => { e.preventDefault() const address = draft.mainnetAddress.trim() if (!ADDRESS_PATTERN.test(address)) { setValidationError('Adresse Bitcoin invalide (doit commencer par 1, 3 ou bc1)') return } setValidationError(null) await publishPresentation(draft) }, [draft, publishPresentation] ) return { loading, error, success, draft, setDraft, validationError, handleSubmit } } function AuthorPresentationFormView({ pubkey, connected, profile, }: { pubkey: string | null connected: boolean profile: { name?: string; pubkey: string } | null }) { const state = useAuthorPresentationState(pubkey) if (!connected || !pubkey) { return } if (state.success) { return } // Get user name or fallback to shortened pubkey const userName = profile?.name ?? (pubkey ? `${pubkey.substring(0, 16)}...` : 'Utilisateur') return ( ) } export function AuthorPresentationEditor() { const { connected, pubkey, profile } = useNostrAuth() return }