|
|
|
|
@ -27,6 +27,7 @@ import PostOptions from './PostOptions'
@@ -27,6 +27,7 @@ import PostOptions from './PostOptions'
|
|
|
|
|
import PostRelaySelector from './PostRelaySelector' |
|
|
|
|
import PostTextarea, { TPostTextareaHandle } from './PostTextarea' |
|
|
|
|
import Uploader from './Uploader' |
|
|
|
|
import RelayStatusDisplay from '@/components/RelayStatusDisplay' |
|
|
|
|
|
|
|
|
|
export default function PostContent({ |
|
|
|
|
defaultContent = '', |
|
|
|
|
@ -64,6 +65,14 @@ export default function PostContent({
@@ -64,6 +65,14 @@ export default function PostContent({
|
|
|
|
|
relays: [] |
|
|
|
|
}) |
|
|
|
|
const [minPow, setMinPow] = useState(0) |
|
|
|
|
const [relayStatuses, setRelayStatuses] = useState<Array<{ |
|
|
|
|
url: string |
|
|
|
|
success: boolean |
|
|
|
|
error?: string |
|
|
|
|
authAttempted?: boolean |
|
|
|
|
}>>([]) |
|
|
|
|
const [showRelayStatus, setShowRelayStatus] = useState(false) |
|
|
|
|
const [lastPublishedEvent, setLastPublishedEvent] = useState<Event | null>(null) |
|
|
|
|
const isFirstRender = useRef(true) |
|
|
|
|
const canPost = useMemo(() => { |
|
|
|
|
const result = ( |
|
|
|
|
@ -239,24 +248,86 @@ export default function PostContent({
@@ -239,24 +248,86 @@ export default function PostContent({
|
|
|
|
|
minPow |
|
|
|
|
}) |
|
|
|
|
// console.log('Published event:', newEvent)
|
|
|
|
|
|
|
|
|
|
// Check if we have relay status information
|
|
|
|
|
console.log('Published event:', newEvent) |
|
|
|
|
console.log('Relay statuses:', (newEvent as any).relayStatuses) |
|
|
|
|
|
|
|
|
|
if ((newEvent as any).relayStatuses) { |
|
|
|
|
setRelayStatuses((newEvent as any).relayStatuses) |
|
|
|
|
setLastPublishedEvent(newEvent) |
|
|
|
|
setShowRelayStatus(true) |
|
|
|
|
|
|
|
|
|
// Show success message with relay count
|
|
|
|
|
const successCount = (newEvent as any).relayStatuses.filter((s: any) => s.success).length |
|
|
|
|
const totalCount = (newEvent as any).relayStatuses.length |
|
|
|
|
toast.success(t('Post successful - published to {{count}} of {{total}} relays', {
|
|
|
|
|
count: successCount,
|
|
|
|
|
total: totalCount
|
|
|
|
|
}), { duration: 4000 }) |
|
|
|
|
|
|
|
|
|
// Don't close immediately if we have relay status to show
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
postEditorCache.clearPostCache({ defaultContent, parentEvent }) |
|
|
|
|
deleteDraftEventCache(draftEvent) |
|
|
|
|
addReplies([newEvent]) |
|
|
|
|
close() |
|
|
|
|
}, 8000) // Give user more time to see the relay status
|
|
|
|
|
} else { |
|
|
|
|
toast.success(t('Post successful'), { duration: 2000 }) |
|
|
|
|
postEditorCache.clearPostCache({ defaultContent, parentEvent }) |
|
|
|
|
deleteDraftEventCache(draftEvent) |
|
|
|
|
addReplies([newEvent]) |
|
|
|
|
close() |
|
|
|
|
} |
|
|
|
|
} catch (error) { |
|
|
|
|
const errors = error instanceof AggregateError ? error.errors : [error] |
|
|
|
|
errors.forEach((err) => { |
|
|
|
|
toast.error( |
|
|
|
|
`${t('Failed to post')}: ${err instanceof Error ? err.message : String(err)}`, |
|
|
|
|
{ duration: 10_000 } |
|
|
|
|
console.error('Publishing error:', error) |
|
|
|
|
|
|
|
|
|
// Handle different types of errors with user-friendly messages
|
|
|
|
|
let errorMessage = t('Failed to post') |
|
|
|
|
|
|
|
|
|
if (error instanceof Error) { |
|
|
|
|
if (error.message.includes('timeout')) { |
|
|
|
|
errorMessage = t('Posting timed out. Your post may have been published to some relays.') |
|
|
|
|
} else if (error.message.includes('auth-required') || error.message.includes('auth required')) { |
|
|
|
|
errorMessage = t('Some relays require authentication. Please try again or use different relays.') |
|
|
|
|
} else if (error.message.includes('blocked')) { |
|
|
|
|
errorMessage = t('You are blocked from posting to some relays.') |
|
|
|
|
} else if (error.message.includes('rate limit')) { |
|
|
|
|
errorMessage = t('Rate limited. Please wait before trying again.') |
|
|
|
|
} else if (error.message.includes('writes disabled')) { |
|
|
|
|
errorMessage = t('Some relays have temporarily disabled writes.') |
|
|
|
|
} else { |
|
|
|
|
errorMessage = `${t('Failed to post')}: ${error.message}` |
|
|
|
|
} |
|
|
|
|
} else if (error instanceof AggregateError) { |
|
|
|
|
// Handle multiple relay failures
|
|
|
|
|
const hasAuthErrors = error.errors.some(err =>
|
|
|
|
|
err instanceof Error && err.message.includes('auth-required') |
|
|
|
|
) |
|
|
|
|
console.error(err) |
|
|
|
|
}) |
|
|
|
|
const hasBlockedErrors = error.errors.some(err =>
|
|
|
|
|
err instanceof Error && err.message.includes('blocked') |
|
|
|
|
) |
|
|
|
|
const hasWriteDisabledErrors = error.errors.some(err =>
|
|
|
|
|
err instanceof Error && err.message.includes('writes disabled') |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if (hasAuthErrors) { |
|
|
|
|
errorMessage = t('Some relays require authentication. Your post may have been published to other relays.') |
|
|
|
|
} else if (hasBlockedErrors) { |
|
|
|
|
errorMessage = t('You are blocked from some relays. Your post may have been published to other relays.') |
|
|
|
|
} else if (hasWriteDisabledErrors) { |
|
|
|
|
errorMessage = t('Some relays have disabled writes. Your post may have been published to other relays.') |
|
|
|
|
} else { |
|
|
|
|
errorMessage = t('Failed to publish to some relays. Your post may have been published to other relays.') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
toast.error(errorMessage, { duration: 8000 }) |
|
|
|
|
return |
|
|
|
|
} finally { |
|
|
|
|
setPosting(false) |
|
|
|
|
} |
|
|
|
|
toast.success(t('Post successful'), { duration: 2000 }) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -507,6 +578,44 @@ export default function PostContent({
@@ -507,6 +578,44 @@ export default function PostContent({
|
|
|
|
|
{parentEvent ? t('Reply') : t('Post')} |
|
|
|
|
</Button> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
{showRelayStatus && relayStatuses.length > 0 && ( |
|
|
|
|
<div className="mt-4 p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg border-2 border-blue-200 dark:border-blue-800"> |
|
|
|
|
<div className="mb-3"> |
|
|
|
|
<h3 className="text-sm font-semibold text-blue-800 dark:text-blue-200 mb-1"> |
|
|
|
|
📡 Publishing Results |
|
|
|
|
</h3> |
|
|
|
|
<p className="text-xs text-blue-600 dark:text-blue-300"> |
|
|
|
|
Your post has been published. Here's the status for each relay: |
|
|
|
|
</p> |
|
|
|
|
</div> |
|
|
|
|
<RelayStatusDisplay |
|
|
|
|
relayStatuses={relayStatuses} |
|
|
|
|
successCount={relayStatuses.filter(s => s.success).length} |
|
|
|
|
totalCount={relayStatuses.length} |
|
|
|
|
/> |
|
|
|
|
<div className="mt-3 flex justify-between items-center"> |
|
|
|
|
<div className="text-xs text-blue-600 dark:text-blue-300"> |
|
|
|
|
This dialog will close automatically in a few seconds |
|
|
|
|
</div> |
|
|
|
|
<Button |
|
|
|
|
variant="ghost" |
|
|
|
|
size="sm" |
|
|
|
|
onClick={() => { |
|
|
|
|
setShowRelayStatus(false) |
|
|
|
|
if (lastPublishedEvent) { |
|
|
|
|
postEditorCache.clearPostCache({ defaultContent, parentEvent }) |
|
|
|
|
// Note: draftEvent is not available here, but that's okay since the event is already published
|
|
|
|
|
addReplies([lastPublishedEvent]) |
|
|
|
|
} |
|
|
|
|
close() |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{t('Close')} |
|
|
|
|
</Button> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
)} |
|
|
|
|
</div> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|