import { useState } from 'react'; import { useScraperStore, ScraperJob, Session } from '../stores/scraperStore'; import { Activity, Key, Clock, CheckCircle, XCircle, StopCircle, ChevronDown, Terminal, RefreshCw } from 'lucide-react'; import { formatDistanceToNow, format } from 'date-fns'; type Tab = 'jobs' | 'sessions'; export function ScraperPanel() { const [activeTab, setActiveTab] = useState('jobs'); const { jobs, sessions, activeJobs, fetchJobs, fetchSessions } = useScraperStore(); return (
{/* Tabs */}
{/* Content */}
{activeTab === 'jobs' ? ( ) : ( )}
); } function JobsList({ jobs, onRefresh }: { jobs: ScraperJob[]; onRefresh: () => void }) { const { cancelJob, logs } = useScraperStore(); const [expandedJob, setExpandedJob] = useState(null); const getStatusIcon = (status: string) => { switch (status) { case 'running': return
; case 'completed': return ; case 'failed': return ; case 'cancelled': return ; default: return ; } }; const getStatusColor = (status: string) => { switch (status) { case 'running': return 'border-accent-cyan/30 bg-accent-cyan/5'; case 'completed': return 'border-accent-emerald/30 bg-accent-emerald/5'; case 'failed': return 'border-accent-rose/30 bg-accent-rose/5'; default: return 'border-slate-700 bg-slate-800/50'; } }; return (
{jobs.length} total jobs
{jobs.length === 0 ? (

No scraper jobs yet

) : ( jobs.slice(0, 20).map(job => { const isExpanded = expandedJob === job.id; const jobLogs = logs.get(job.id) || []; return (
{isExpanded && (
Job ID: {job.id.slice(0, 8)}...
{job.target_name && (
Target: {job.target_name}
)} {job.error && (
{job.error}
)} {job.status === 'running' && ( )} {/* Logs */} {jobLogs.length > 0 && (
Logs
{jobLogs.slice(-10).map((log, i) => (
[{format(new Date(log.timestamp), 'HH:mm:ss')}]{' '} {log.message}
))}
)}
)}
); }) )}
); } function SessionsList({ sessions, onRefresh }: { sessions: Session[]; onRefresh: () => void }) { const { deleteSession } = useScraperStore(); const getStatusIndicator = (status: string) => { switch (status) { case 'active': return
; case 'expired': return
; default: return
; } }; return (
Session Vault
{sessions.length === 0 ? (

No sessions stored

Add session cookies to enable authenticated scraping

) : ( sessions.map(session => (
{getStatusIndicator(session.status)} {session.platform}
{session.status}
Name: {session.session_name}
{session.last_validated && (
Validated: {formatDistanceToNow(new Date(session.last_validated), { addSuffix: true })}
)}
)) )}
); }