'use client' import { useState, useEffect } from 'react' import type { TrumpPost } from '@/types' import { getPosts, getPostsPage, type PostListResponse } from '@/lib/api' import { hasCached, swrFetch } from '@/lib/cache' import PostRow from '@/components/dashboard/PostCards' import PageHint from '@/components/ui/PageHint' import Pagination from '@/components/ui/Pagination' import { buildArchiveFallbackResponse } from '@/lib/postPage' const ARCHIVE_PAGE_SIZE = 30 interface ArchivePageClientProps { initialData?: PostListResponse | null } export default function ArchivePageClient({ initialData = null }: ArchivePageClientProps) { const [posts, setPosts] = useState(initialData?.items ?? []) const [totalPosts, setTotalPosts] = useState(initialData?.total ?? 0) const [sourceCounts, setSourceCounts] = useState(initialData?.source_counts ?? []) const [loading, setLoading] = useState(initialData === null) const [loadErr, setLoadErr] = useState('') const [src, setSrc] = useState('all') const [archivePage, setArchivePage] = useState(1) useEffect(() => { const key = `archive-page-${archivePage}-src-${src}` setLoadErr('') setLoading(posts.length === 0 && !hasCached(key)) swrFetch( key, 3 * 60_000, () => getPostsPage( ARCHIVE_PAGE_SIZE, archivePage, undefined, { archiveOnly: true, sourceIn: src === 'all' ? undefined : [src], }, ), fresh => { setPosts(fresh.items) setTotalPosts(fresh.total) setSourceCounts(fresh.source_counts) }, ) .then(r => { setPosts(r.items) setTotalPosts(r.total) setSourceCounts(r.source_counts) }) .catch(async e => { const detail = e instanceof Error ? e.message : 'Failed to load archive' if (!detail.includes('404')) { setLoadErr(detail) return } try { const legacyPosts = await swrFetch( 'archive-legacy-500', 3 * 60_000, () => getPosts(500, 1), ) const fallback = buildArchiveFallbackResponse(legacyPosts, archivePage, ARCHIVE_PAGE_SIZE, src) setPosts(fallback.items) setTotalPosts(fallback.total) setSourceCounts(fallback.source_counts) setLoadErr('') } catch (legacyErr) { setLoadErr(legacyErr instanceof Error ? legacyErr.message : detail) } }) .finally(() => setLoading(false)) }, [archivePage, posts.length, src]) const archiveTotalPages = Math.max(1, Math.ceil(totalPosts / ARCHIVE_PAGE_SIZE)) const archiveSafePage = Math.min(archivePage, archiveTotalPages) const allSourcesCount = sourceCounts.reduce((sum, item) => sum + item.count, 0) const sourceTabs: [string, number][] = [ ['all', allSourcesCount], ...sourceCounts.map(item => [item.source, item.count] as [string, number]), ] return (

Archive

{/* No count slot — the source tabs and pagination already show per-source and total counts. */} Signals from retired scanner experiments (rsi_reversal, sma_reclaim, breakout, test/phase1). Read-only — the bot no longer acts on any of these.
{sourceTabs.map(([s, n]) => ( ))}
{loading &&
Loading…
} {!loading && loadErr && (
⚠️ {`Couldn't load archive — ${loadErr}`}
)} {!loading && !loadErr && totalPosts === 0 && (
No archived signals.
)} {!loading && posts.length > 0 && ( <>
{posts.map(p => )}
)}
) }