refactor(ui): retire article feed and legacy jobs surfaces
Remove obsolete article and scrape-job screens and APIs, preserve reports, and clear legacy API caches from the service worker. Refs #8 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -1,115 +0,0 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { ExternalLink, RefreshCw, Search } from 'lucide-react'
|
||||
import { articlesApi, type Article } from '@/api/articles'
|
||||
import { assetsApi, type Asset } from '@/api/assets'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Select } from '@/components/ui/select'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
|
||||
function fmtDate(a: Article) {
|
||||
const d = a.published_at?.Valid ? new Date(a.published_at.Time) : new Date(a.created_at)
|
||||
const now = Date.now()
|
||||
const diff = now - d.getTime()
|
||||
if (diff < 3600000) return `Il y a ${Math.floor(diff / 60000)} min`
|
||||
if (diff < 86400000) return `Il y a ${Math.floor(diff / 3600000)} h`
|
||||
return d.toLocaleDateString('fr-FR')
|
||||
}
|
||||
|
||||
export function Feed() {
|
||||
const [articles, setArticles] = useState<Article[]>([])
|
||||
const [assets, setAssets] = useState<Asset[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [search, setSearch] = useState('')
|
||||
const [filterSymbol, setFilterSymbol] = useState('')
|
||||
const [offset, setOffset] = useState(0)
|
||||
const limit = 30
|
||||
|
||||
useEffect(() => {
|
||||
assetsApi.list().then(a => setAssets(a ?? []))
|
||||
}, [])
|
||||
|
||||
const load = useCallback(async (newOffset = 0) => {
|
||||
try {
|
||||
const data = await articlesApi.list({ symbol: filterSymbol || undefined, limit, offset: newOffset })
|
||||
if (newOffset === 0) setArticles(data ?? [])
|
||||
else setArticles(prev => [...prev, ...(data ?? [])])
|
||||
setOffset(newOffset + limit)
|
||||
} finally { setLoading(false) }
|
||||
}, [filterSymbol])
|
||||
|
||||
useEffect(() => { void load(0) }, [load])
|
||||
|
||||
const filtered = search
|
||||
? articles.filter(a => a.title.toLowerCase().includes(search.toLowerCase()) || a.source_name?.toLowerCase().includes(search.toLowerCase()))
|
||||
: articles
|
||||
|
||||
return (
|
||||
<div className="p-4 md:p-6 space-y-4">
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
<h1 className="text-2xl font-bold flex-1">Actualités</h1>
|
||||
<Button variant="outline" size="icon" onClick={() => { setLoading(true); void load(0) }}><RefreshCw className="h-4 w-4" /></Button>
|
||||
</div>
|
||||
|
||||
{/* Filtres */}
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<div className="relative flex-1 min-w-48">
|
||||
<Search className="absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input className="pl-8" placeholder="Rechercher…" value={search} onChange={e => setSearch(e.target.value)} />
|
||||
</div>
|
||||
<Select value={filterSymbol} onChange={e => { setLoading(true); setFilterSymbol(e.target.value) }} className="w-40">
|
||||
<option value="">Tous les symboles</option>
|
||||
{assets.map(a => <option key={a.id} value={a.symbol}>{a.symbol}</option>)}
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{loading && articles.length === 0 ? (
|
||||
<div className="flex justify-center py-20"><Spinner /></div>
|
||||
) : (
|
||||
<>
|
||||
<div className="space-y-3">
|
||||
{filtered.map(a => (
|
||||
<Card key={a.id} className="hover:border-border/80 transition-colors">
|
||||
<CardContent className="py-4">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 flex-wrap mb-1">
|
||||
<Badge variant="outline" className="text-xs">{a.source_name}</Badge>
|
||||
<span className="text-xs text-muted-foreground">{fmtDate(a)}</span>
|
||||
</div>
|
||||
<h3 className="font-medium leading-snug mb-2">{a.title}</h3>
|
||||
{a.content && (
|
||||
<p className="text-sm text-muted-foreground line-clamp-2">{a.content}</p>
|
||||
)}
|
||||
</div>
|
||||
<a
|
||||
href={a.url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="shrink-0 text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<ExternalLink className="h-4 w-4" />
|
||||
</a>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
{filtered.length === 0 && (
|
||||
<Card><CardContent className="py-12 text-center text-muted-foreground">Aucun article</CardContent></Card>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{filtered.length >= limit && (
|
||||
<div className="flex justify-center pt-2">
|
||||
<Button variant="outline" onClick={() => { setLoading(true); void load(offset) }} disabled={loading}>
|
||||
{loading ? <Spinner className="h-4 w-4" /> : 'Charger plus'}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@ -1,13 +1,12 @@
|
||||
import { NavLink, Outlet, Navigate } from 'react-router-dom'
|
||||
import { Cpu, Key, Database, ClipboardList, Users, CalendarDays, Settings } from 'lucide-react'
|
||||
import { Cpu, Key, Database, Users, CalendarDays, Settings } from 'lucide-react'
|
||||
import { useAuth } from '@/lib/auth'
|
||||
import { cn } from '@/lib/cn'
|
||||
|
||||
const adminItems = [
|
||||
{ to: '/admin/ai', icon: Cpu, label: 'Fournisseurs IA' },
|
||||
{ to: '/admin/credentials', icon: Key, label: 'Identifiants' },
|
||||
{ to: '/admin/credentials', icon: Key, label: 'Accès aux sources' },
|
||||
{ to: '/admin/sources', icon: Database, label: 'Sources et plafonds' },
|
||||
{ to: '/admin/jobs', icon: ClipboardList,label: 'Jobs' },
|
||||
{ to: '/admin/users', icon: Users, label: 'Utilisateurs' },
|
||||
{ to: '/admin/schedule', icon: CalendarDays, label: 'Planning' },
|
||||
{ to: '/admin/settings', icon: Settings, label: 'Paramètres' },
|
||||
|
||||
@ -98,7 +98,7 @@ export function AdminSettings() {
|
||||
<div className="space-y-1">
|
||||
<Label>Timezone (IANA)</Label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Utilisé pour le planning de scraping et l'horodatage des résumés
|
||||
Utilisé pour le planning de génération et l’horodatage des synthèses
|
||||
</p>
|
||||
<div className="flex gap-2 max-w-sm">
|
||||
<Input
|
||||
|
||||
@ -52,8 +52,8 @@ export function Credentials() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">Identifiants de scraping</h1>
|
||||
<p className="text-muted-foreground text-sm">Les mots de passe sont chiffrés en AES-256-GCM côté serveur</p>
|
||||
<h1 className="text-2xl font-bold">Accès aux sources</h1>
|
||||
<p className="text-muted-foreground text-sm">Ces accès sont utilisés par le mécanisme de récupération existant. Les enregistrer ne lance aucune récupération. Les mots de passe sont chiffrés côté serveur.</p>
|
||||
</div>
|
||||
|
||||
{creds.length === 0 && (
|
||||
|
||||
@ -1,109 +0,0 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Play, RefreshCw } from 'lucide-react'
|
||||
import { adminApi, type ScrapeJob, type Source } from '@/api/admin'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Select } from '@/components/ui/select'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
|
||||
function jobStatusVariant(status: string) {
|
||||
if (status === 'done') return 'bullish'
|
||||
if (status === 'error') return 'bearish'
|
||||
if (status === 'running') return 'default'
|
||||
return 'outline'
|
||||
}
|
||||
|
||||
function fmtDate(t: { Time: string; Valid: boolean } | null) {
|
||||
if (!t?.Valid) return '—'
|
||||
return new Date(t.Time).toLocaleString('fr-FR')
|
||||
}
|
||||
|
||||
export function Jobs() {
|
||||
const [jobs, setJobs] = useState<ScrapeJob[]>([])
|
||||
const [sources, setSources] = useState<Source[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [triggering, setTriggering] = useState(false)
|
||||
const [selectedSource, setSelectedSource] = useState('')
|
||||
|
||||
useEffect(() => { load() }, [])
|
||||
|
||||
async function load() {
|
||||
setLoading(true)
|
||||
try {
|
||||
const [j, s] = await Promise.all([adminApi.listJobs(), adminApi.listSources()])
|
||||
setJobs(j ?? [])
|
||||
setSources(s ?? [])
|
||||
if (s?.[0]) setSelectedSource(s[0].id)
|
||||
} finally { setLoading(false) }
|
||||
}
|
||||
|
||||
async function trigger() {
|
||||
if (!selectedSource) return
|
||||
setTriggering(true)
|
||||
await adminApi.triggerJob(selectedSource)
|
||||
setTimeout(() => { load(); setTriggering(false) }, 1000)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-wrap items-center justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">Jobs de scraping</h1>
|
||||
<p className="text-muted-foreground text-sm">Historique et déclenchement manuel</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Select value={selectedSource} onChange={e => setSelectedSource(e.target.value)} className="w-40">
|
||||
{sources.map(s => <option key={s.id} value={s.id}>{s.name}</option>)}
|
||||
</Select>
|
||||
<Button onClick={trigger} disabled={triggering || !selectedSource}>
|
||||
{triggering ? <Spinner className="h-4 w-4" /> : <Play className="h-4 w-4" />}
|
||||
Lancer
|
||||
</Button>
|
||||
<Button variant="outline" size="icon" onClick={load}><RefreshCw className="h-4 w-4" /></Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div className="flex justify-center py-12"><Spinner /></div>
|
||||
) : (
|
||||
<Card>
|
||||
<CardHeader><CardTitle>Historique</CardTitle></CardHeader>
|
||||
<CardContent className="p-0">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="border-b">
|
||||
<tr className="text-left text-muted-foreground">
|
||||
<th className="px-4 py-3">Source</th>
|
||||
<th className="px-4 py-3">Statut</th>
|
||||
<th className="px-4 py-3">Début</th>
|
||||
<th className="px-4 py-3">Fin</th>
|
||||
<th className="px-4 py-3">Articles</th>
|
||||
<th className="px-4 py-3">Erreur</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{jobs.map(j => (
|
||||
<tr key={j.id} className="border-b last:border-0 hover:bg-muted/30">
|
||||
<td className="px-4 py-3 font-medium">{j.source_name}</td>
|
||||
<td className="px-4 py-3">
|
||||
<Badge variant={jobStatusVariant(j.status) as 'bullish' | 'bearish' | 'default' | 'outline'}>{j.status}</Badge>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-muted-foreground">{fmtDate(j.started_at)}</td>
|
||||
<td className="px-4 py-3 text-muted-foreground">{fmtDate(j.finished_at)}</td>
|
||||
<td className="px-4 py-3">{j.articles_found}</td>
|
||||
<td className="px-4 py-3 text-destructive max-w-xs truncate">{j.error_msg || '—'}</td>
|
||||
</tr>
|
||||
))}
|
||||
{jobs.length === 0 && (
|
||||
<tr><td colSpan={6} className="px-4 py-8 text-center text-muted-foreground">Aucun job</td></tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@ -68,11 +68,11 @@ export function Schedule() {
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">Planning hebdomadaire</h1>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
Définissez les créneaux de scraping + résumé IA pour chaque jour
|
||||
Définissez les créneaux de génération des synthèses pour chaque jour.
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={save} disabled={saving}>
|
||||
@ -137,7 +137,7 @@ export function Schedule() {
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-muted-foreground">
|
||||
À chaque créneau, le service lance le scraping de toutes les sources actives puis génère les résumés IA.
|
||||
Le planning est utilisé par le service de génération existant. Enregistrer ces créneaux ne lance aucune récupération ni génération immédiate.
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
|
||||
@ -95,6 +95,7 @@ export function Sources() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-2xl font-bold">Sources et plafonds</h1>
|
||||
<p className="text-sm text-muted-foreground">Choisissez les sources utilisées pour les synthèses et leurs plafonds. Modifier ces réglages ne lance aucune récupération d’articles.</p>
|
||||
{loading ? <p role="status">Chargement des sources et plafonds…</p> : loadError ? (
|
||||
<div className="space-y-3"><p role="alert">{loadError}</p><Button onClick={() => void load()}>Réessayer</Button></div>
|
||||
) : <>
|
||||
|
||||
Reference in New Issue
Block a user