2026-01-14 00:34:36 +01:00

67 lines
1.7 KiB
TypeScript

import type { Article } from '@/types/nostr'
import { ArticleCard } from './ArticleCard'
import { ErrorState, EmptyState } from './ui'
import { t } from '@/lib/i18n'
interface ArticlesListProps {
articles: Article[]
allArticles: Article[]
loading: boolean
error: string | null
onUnlock: (article: Article) => void
unlockedArticles: Set<string>
}
function LoadingState(): React.ReactElement {
// Use generic loading message at startup, then specific message once we know what we're loading
return (
<div className="text-center py-12">
<p className="text-cyber-accent/70">{t('common.loading.articles')}</p>
</div>
)
}
function ArticlesEmptyState({ hasAny }: { hasAny: boolean }): React.ReactElement {
return (
<EmptyState
title={hasAny ? t('common.empty.articles.filtered') : t('common.empty.articles')}
/>
)
}
export function ArticlesList({
articles,
allArticles,
loading,
error,
onUnlock,
unlockedArticles,
}: ArticlesListProps): React.ReactElement {
if (loading) {
return <LoadingState />
}
if (error) {
return <ErrorState message={error} />
}
if (articles.length === 0) {
return <ArticlesEmptyState hasAny={allArticles.length > 0} />
}
return (
<>
<div className="mb-4 text-sm text-cyber-accent/70">
Showing {articles.length} of {allArticles.length} article{allArticles.length !== 1 ? 's' : ''}
</div>
<div className="space-y-6">
{articles.map((article) => (
<ArticleCard
key={article.id}
article={{ ...article, paid: unlockedArticles.has(article.id) || article.paid }}
onUnlock={onUnlock}
/>
))}
</div>
</>
)
}