import { useRef } from 'react' import type { Article } from '@/types/nostr' import { AuthorCard } from './AuthorCard' import { ErrorState, EmptyState, Skeleton } from './ui' import { t } from '@/lib/i18n' import { useArrowNavigation } from '@/hooks/useArrowNavigation' interface AuthorsListProps { authors: Article[] allAuthors: Article[] loading: boolean error: string | null } function AuthorCardSkeleton(): React.ReactElement { return (
) } function LoadingState(): React.ReactElement { return (
{Array.from({ length: 4 }, (_, index) => ( ))}
) } function AuthorsEmptyState({ hasAny }: { hasAny: boolean }): React.ReactElement { return ( ) } function AuthorsErrorState({ error }: { error: string }): React.ReactElement { const errorObj = new Error(error) return ( { window.location.reload() }} onCheckConnection={() => { if (navigator.onLine) { window.location.reload() } else { // eslint-disable-next-line no-alert alert(t('errors.network.offline')) } }} /> ) } export function AuthorsList({ authors, allAuthors, loading, error }: AuthorsListProps): React.ReactElement { const containerRef = useRef(null) useArrowNavigation({ itemCount: authors.length, containerRef, enabled: !loading && authors.length > 0 }) if (loading) { return } if (error) { return } if (authors.length === 0) { return 0} /> } return (
Showing {authors.length} of {allAuthors.length} author{allAuthors.length !== 1 ? 's' : ''}
{authors.map((author) => (
))}
) }