feat: HistoryPage + SettingsPage — white + blue theme
Browse files
frontend/src/pages/HistoryPage.tsx
CHANGED
|
@@ -1,66 +1,63 @@
|
|
| 1 |
-
import
|
| 2 |
|
| 3 |
export function HistoryPage() {
|
| 4 |
const [history, setHistory] = useState<any[]>([]);
|
| 5 |
const [selected, setSelected] = useState<any>(null);
|
| 6 |
|
| 7 |
-
useEffect(() => {
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
if (d < 3600000) return `${Math.floor(d/60000)}m ago`;
|
| 13 |
-
if (d < 86400000) return `${Math.floor(d/3600000)}h ago`;
|
| 14 |
-
return `${Math.floor(d/86400000)}d ago`;
|
| 15 |
-
};
|
| 16 |
|
| 17 |
return (
|
| 18 |
-
<div className="max-w-
|
| 19 |
-
<div className="
|
| 20 |
-
<
|
| 21 |
-
|
| 22 |
</div>
|
| 23 |
|
| 24 |
{history.length === 0 ? (
|
| 25 |
-
<div className="
|
|
|
|
|
|
|
|
|
|
| 26 |
) : (
|
| 27 |
-
<div className="grid lg:grid-cols-[280px_1fr] gap-
|
| 28 |
-
|
|
|
|
| 29 |
{history.map((item, i) => (
|
| 30 |
<button key={i} onClick={() => setSelected(item)}
|
| 31 |
-
className={`w-full text-left p-3 rounded-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
</div>
|
| 36 |
-
<div className="
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
</div>
|
| 42 |
</button>
|
| 43 |
))}
|
| 44 |
</div>
|
| 45 |
|
| 46 |
-
|
|
|
|
| 47 |
{selected ? (
|
| 48 |
<>
|
| 49 |
-
<div className="
|
| 50 |
-
<
|
| 51 |
-
{selected.quality && <span className={`text-xs font-bold px-2 py-0.5 rounded ${selected.quality.grade === 'A' ? 'bg-emerald-500/10 text-emerald-300' : 'bg-blue-500/10 text-blue-300'}`}>Grade {selected.quality.grade}</span>}
|
| 52 |
-
<span className="text-[11px] text-gray-500">{selected.processing_time_ms?.toFixed(0)}ms</span>
|
| 53 |
-
{selected.iterations_performed > 0 && <span className="text-[11px] text-purple-400">🔄 {selected.iterations_performed} iterations</span>}
|
| 54 |
-
</div>
|
| 55 |
<button onClick={() => navigator.clipboard.writeText(selected.test_files?.[0]?.code || selected.test_code || '')}
|
| 56 |
-
className="px-3 py-1
|
| 57 |
</div>
|
| 58 |
-
<pre className="flex-1 overflow-auto p-
|
| 59 |
-
{selected.test_files?.[0]?.code || selected.test_code || 'No code
|
| 60 |
</pre>
|
| 61 |
</>
|
| 62 |
) : (
|
| 63 |
-
<div className="flex-1 flex items-center justify-center text-
|
| 64 |
)}
|
| 65 |
</div>
|
| 66 |
</div>
|
|
|
|
| 1 |
+
import { useState, useEffect } from 'react';
|
| 2 |
|
| 3 |
export function HistoryPage() {
|
| 4 |
const [history, setHistory] = useState<any[]>([]);
|
| 5 |
const [selected, setSelected] = useState<any>(null);
|
| 6 |
|
| 7 |
+
useEffect(() => {
|
| 8 |
+
const h = JSON.parse(localStorage.getItem('tg_history') || '[]');
|
| 9 |
+
setHistory(h);
|
| 10 |
+
if (h.length) setSelected(h[0]);
|
| 11 |
+
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
return (
|
| 14 |
+
<div className="max-w-7xl mx-auto px-6 py-8">
|
| 15 |
+
<div className="mb-6">
|
| 16 |
+
<h1 className="text-2xl font-bold text-slate-900">Generation History</h1>
|
| 17 |
+
<p className="text-slate-500 text-sm mt-1">Previous test generation runs (stored locally)</p>
|
| 18 |
</div>
|
| 19 |
|
| 20 |
{history.length === 0 ? (
|
| 21 |
+
<div className="card p-12 text-center">
|
| 22 |
+
<div className="text-4xl mb-4 opacity-30">📋</div>
|
| 23 |
+
<p className="text-slate-500">No history yet. Generate some tests first!</p>
|
| 24 |
+
</div>
|
| 25 |
) : (
|
| 26 |
+
<div className="grid lg:grid-cols-[280px_1fr] gap-6">
|
| 27 |
+
{/* List */}
|
| 28 |
+
<div className="space-y-2 max-h-[600px] overflow-y-auto">
|
| 29 |
{history.map((item, i) => (
|
| 30 |
<button key={i} onClick={() => setSelected(item)}
|
| 31 |
+
className={`w-full text-left p-3 rounded-lg border transition-all ${
|
| 32 |
+
selected === item ? 'bg-blue-50 border-blue-200' : 'bg-white border-slate-200 hover:border-slate-300'
|
| 33 |
+
}`}>
|
| 34 |
+
<div className="text-sm font-medium text-slate-900 truncate">{item.run_id || `Run ${i + 1}`}</div>
|
| 35 |
+
<div className="text-xs text-slate-500 mt-1">{item._input?.slice(0, 60) || 'No description'}</div>
|
| 36 |
+
<div className="flex items-center gap-2 mt-2">
|
| 37 |
+
{item.quality && <span className={`text-[10px] px-2 py-0.5 rounded-full font-semibold ${
|
| 38 |
+
item.quality.grade === 'A' ? 'bg-green-50 text-green-700' : 'bg-blue-50 text-blue-700'
|
| 39 |
+
}`}>Grade {item.quality.grade}</span>}
|
| 40 |
+
<span className="text-[10px] text-slate-400">{item.processing_time_ms?.toFixed(0)}ms</span>
|
| 41 |
</div>
|
| 42 |
</button>
|
| 43 |
))}
|
| 44 |
</div>
|
| 45 |
|
| 46 |
+
{/* Detail */}
|
| 47 |
+
<div className="card overflow-hidden flex flex-col">
|
| 48 |
{selected ? (
|
| 49 |
<>
|
| 50 |
+
<div className="px-5 py-3 border-b border-slate-100 bg-slate-50/50 flex items-center justify-between">
|
| 51 |
+
<span className="text-sm font-medium text-slate-900">{selected.run_id}</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
<button onClick={() => navigator.clipboard.writeText(selected.test_files?.[0]?.code || selected.test_code || '')}
|
| 53 |
+
className="px-3 py-1 rounded-lg bg-blue-50 text-blue-700 text-xs font-medium hover:bg-blue-100">Copy Code</button>
|
| 54 |
</div>
|
| 55 |
+
<pre className="flex-1 overflow-auto p-5 text-sm text-slate-800 font-mono leading-[1.7]">
|
| 56 |
+
{selected.test_files?.[0]?.code || selected.test_code || 'No code'}
|
| 57 |
</pre>
|
| 58 |
</>
|
| 59 |
) : (
|
| 60 |
+
<div className="flex-1 flex items-center justify-center text-slate-500 text-sm">Select a run to view</div>
|
| 61 |
)}
|
| 62 |
</div>
|
| 63 |
</div>
|