import { useRef } from 'react' import type { Article } from '@/types/nostr' import { ArticleCard } from './ArticleCard' import { ErrorState, EmptyState, Skeleton } from './ui' import { t } from '@/lib/i18n' import { useArrowNavigation } from '@/hooks/useArrowNavigation' interface ArticlesListProps { articles: Article[] allArticles: Article[] loading: boolean error: string | null onUnlock: (article: Article) => void unlockedArticles: Set } function ArticleCardSkeleton(): React.ReactElement { return (
) } function LoadingState(): React.ReactElement { return (
{Array.from({ length: 3 }, (_, index) => ( ))}
) } function ArticlesEmptyState({ hasAny }: { hasAny: boolean }): React.ReactElement { return ( ) } function ArticlesErrorState({ 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')) } }} /> ) } function ArticlesContent({ articles, allArticles, onUnlock, unlockedArticles, containerRef, }: { articles: Article[] allArticles: Article[] onUnlock: (article: Article) => void unlockedArticles: Set containerRef: React.RefObject }): React.ReactElement { return (
Showing {articles.length} of {allArticles.length} article{allArticles.length !== 1 ? 's' : ''}
{articles.map((article) => (
))}
) } export function ArticlesList({ articles, allArticles, loading, error, onUnlock, unlockedArticles, }: ArticlesListProps): React.ReactElement { const containerRef = useRef(null) useArrowNavigation({ itemCount: articles.length, containerRef, enabled: !loading && articles.length > 0 }) if (loading) { return } if (error) { return } if (articles.length === 0) { return 0} /> } return ( ) }