81 lines
2.9 KiB
TypeScript
81 lines
2.9 KiB
TypeScript
import { useEffect } from 'react'
|
|
import { useNostrAuth } from '@/hooks/useNostrAuth'
|
|
import { useAuthorPresentation } from '@/hooks/useAuthorPresentation'
|
|
import { t } from '@/lib/i18n'
|
|
import { NoAccountView } from './NoAccountView'
|
|
import { PresentationForm } from './PresentationForm'
|
|
import { useExistingPresentation } from './useExistingPresentation'
|
|
import { useAuthorPresentationState } from './useAuthorPresentationState'
|
|
|
|
function SuccessNotice(params: { pubkey: string | null }): React.ReactElement {
|
|
return (
|
|
<div className="border border-neon-green/50 rounded-lg p-6 bg-neon-green/10">
|
|
<h3 className="text-lg font-semibold text-neon-green mb-2">{t('presentation.success')}</h3>
|
|
<p className="text-cyber-accent mb-4">{t('presentation.successMessage')}</p>
|
|
{params.pubkey ? (
|
|
<div className="mt-4">
|
|
<a
|
|
href={`/author/${params.pubkey}`}
|
|
className="inline-block px-4 py-2 bg-neon-cyan/20 hover:bg-neon-cyan/30 text-neon-cyan rounded-lg font-medium transition-all border border-neon-cyan/50 hover:shadow-glow-cyan"
|
|
>
|
|
{t('presentation.manageSeries')}
|
|
</a>
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function LoadingNotice(): React.ReactElement {
|
|
return (
|
|
<div className="text-center py-12">
|
|
<p className="text-cyber-accent/70">{t('common.loading')}</p>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function AuthorPresentationFormView(props: { pubkey: string | null; profile: { name?: string; pubkey: string } | null }): React.ReactElement {
|
|
const { checkPresentationExists } = useAuthorPresentation(props.pubkey)
|
|
const presentation = useExistingPresentation({ pubkey: props.pubkey, checkPresentationExists })
|
|
const state = useAuthorPresentationState(props.pubkey, props.profile?.name, presentation.existingPresentation)
|
|
|
|
if (!props.pubkey) {
|
|
return <NoAccountView />
|
|
}
|
|
if (presentation.loadingPresentation) {
|
|
return <LoadingNotice />
|
|
}
|
|
if (state.success) {
|
|
return <SuccessNotice pubkey={props.pubkey} />
|
|
}
|
|
return (
|
|
<PresentationForm
|
|
draft={state.draft}
|
|
setDraft={state.setDraft}
|
|
validationError={state.validationError}
|
|
error={state.error}
|
|
loading={state.loading}
|
|
handleSubmit={state.handleSubmit}
|
|
deleting={state.deleting}
|
|
handleDelete={() => {
|
|
void state.handleDelete()
|
|
}}
|
|
hasExistingPresentation={presentation.existingPresentation !== null}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function useAutoLoadPubkey(accountExists: boolean | null, pubkey: string | null, connect: () => Promise<void>): void {
|
|
useEffect(() => {
|
|
if (accountExists === true && !pubkey) {
|
|
void connect()
|
|
}
|
|
}, [accountExists, pubkey, connect])
|
|
}
|
|
|
|
export function AuthorPresentationEditor(): React.ReactElement {
|
|
const { pubkey, profile, accountExists, connect } = useNostrAuth()
|
|
useAutoLoadPubkey(accountExists, pubkey ?? null, connect)
|
|
return <AuthorPresentationFormView pubkey={pubkey ?? null} profile={profile} />
|
|
}
|