feat: Scan history — shows last 20 scans with URL, date, findings count
- localStorage-based scan history (persists across sessions) - Each completed scan adds entry: URL, timestamp, findings count, docs count - 'Letzte Scans' section below results shows clickable history entries - Click loads URL into form (and shows cached result if same URL) - Max 20 entries, deduplicates by URL (latest scan wins) - History visible in 'Website-Scan' tab Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,10 @@ export default function AgentPage() {
|
||||
})
|
||||
const [scanProgress, setScanProgress] = useState<string>('')
|
||||
const [activeScanId, setActiveScanId] = useState<string>(() => typeof window !== 'undefined' ? localStorage.getItem('agent-scan-id') || '' : '')
|
||||
const [scanHistory, setScanHistory] = useState<{ url: string; date: string; findings: number; docs: number }[]>(() => {
|
||||
if (typeof window === 'undefined') return []
|
||||
try { return JSON.parse(localStorage.getItem('agent-scan-history') || '[]') } catch { return [] }
|
||||
})
|
||||
const { analyze, answerFollowUp, loading, error, result, history } = useAgentAnalysis()
|
||||
|
||||
// Persist state to localStorage
|
||||
@@ -62,6 +66,7 @@ export default function AgentPage() {
|
||||
localStorage.setItem('agent-scan-result', JSON.stringify(data.result))
|
||||
localStorage.removeItem('agent-scan-id')
|
||||
setActiveScanId('')
|
||||
_addToHistory(data.result)
|
||||
return
|
||||
}
|
||||
if (data.status === 'failed') {
|
||||
@@ -86,6 +91,33 @@ export default function AgentPage() {
|
||||
return () => { cancelled = true }
|
||||
}, []) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
const _addToHistory = (result: any) => {
|
||||
const entry = {
|
||||
url: url || result.url || '',
|
||||
date: new Date().toISOString(),
|
||||
findings: result.findings?.length || 0,
|
||||
docs: result.discovered_documents?.length || 0,
|
||||
}
|
||||
const updated = [entry, ...scanHistory.filter(h => h.url !== entry.url)].slice(0, 20)
|
||||
setScanHistory(updated)
|
||||
localStorage.setItem('agent-scan-history', JSON.stringify(updated))
|
||||
}
|
||||
|
||||
const _loadFromHistory = (entry: { url: string }) => {
|
||||
setUrl(entry.url)
|
||||
setTab('scan')
|
||||
// Load saved result if same URL
|
||||
try {
|
||||
const saved = localStorage.getItem('agent-scan-result')
|
||||
if (saved) {
|
||||
const parsed = JSON.parse(saved)
|
||||
if (parsed.url === entry.url) {
|
||||
setScanData(parsed)
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!url.trim()) return
|
||||
@@ -129,6 +161,7 @@ export default function AgentPage() {
|
||||
localStorage.setItem('agent-scan-result', JSON.stringify(pollData.result))
|
||||
localStorage.removeItem('agent-scan-id')
|
||||
setActiveScanId('')
|
||||
_addToHistory(pollData.result)
|
||||
break
|
||||
}
|
||||
if (pollData.status === 'failed') {
|
||||
@@ -242,6 +275,32 @@ export default function AgentPage() {
|
||||
{tab === 'quick' && (
|
||||
<AnalysisHistory history={history} onSelect={r => { setUrl(r.url); analyze(r.url, mode) }} />
|
||||
)}
|
||||
|
||||
{/* Scan History */}
|
||||
{tab === 'scan' && scanHistory.length > 0 && (
|
||||
<div className="border border-gray-200 rounded-xl p-4">
|
||||
<h4 className="text-sm font-medium text-gray-700 mb-3">Letzte Scans</h4>
|
||||
<div className="space-y-2">
|
||||
{scanHistory.map((h, i) => (
|
||||
<button key={i} onClick={() => _loadFromHistory(h)}
|
||||
className="w-full flex items-center justify-between p-3 rounded-lg border border-gray-100 hover:border-purple-200 hover:bg-purple-50/30 transition-all text-left">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="text-sm font-medium text-gray-900 truncate">{h.url}</div>
|
||||
<div className="text-xs text-gray-500">
|
||||
{new Date(h.date).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' })}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 shrink-0 ml-3">
|
||||
{h.docs > 0 && <span className="text-xs text-purple-600">{h.docs} Dok.</span>}
|
||||
<span className={`text-xs font-medium ${h.findings > 0 ? 'text-red-600' : 'text-green-600'}`}>
|
||||
{h.findings} Findings
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user