diff --git a/gui/src-frontend/src/components/HistoryList.tsx b/gui/src-frontend/src/components/HistoryList.tsx index c5a7309..39e921c 100644 --- a/gui/src-frontend/src/components/HistoryList.tsx +++ b/gui/src-frontend/src/components/HistoryList.tsx @@ -1,8 +1,73 @@ +import { useQrState } from '../store/qrContext'; +import { MODE_LABELS, type HistoryEntry } from '../types'; + export default function HistoryList() { + const { state, dispatch } = useQrState(); + + const handleClick = (entry: HistoryEntry) => { + dispatch({ type: 'SET_MODE', payload: entry.mode as any }); + try { + const formData = JSON.parse(entry.content); + dispatch({ type: 'SET_FORM_DATA', payload: formData }); + } catch { + dispatch({ type: 'SET_FORM_DATA', payload: { text: entry.content } }); + } + }; + + const handleDelete = (e: React.MouseEvent, id: string) => { + e.stopPropagation(); + dispatch({ type: 'REMOVE_HISTORY', payload: id }); + }; + + const handleClear = () => { + dispatch({ type: 'SET_HISTORY', payload: [] }); + }; + + const formatTime = (ts: number) => { + const d = new Date(ts); + return `${d.getHours().toString().padStart(2, '0')}:${d.getMinutes().toString().padStart(2, '0')}`; + }; + return (
-
📋 历史记录
-

暂无记录

+
+ + 📋 历史记录 + + {state.history.length > 0 && ( + + )} +
+ +
+ {state.history.length === 0 && ( +

暂无记录

+ )} + {state.history.map(entry => ( +
handleClick(entry)} + className="group flex items-center justify-between px-2 py-1.5 rounded-lg text-xs cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition-all"> +
+
+ + {MODE_LABELS[entry.mode as keyof typeof MODE_LABELS] || entry.mode} + + {formatTime(entry.timestamp)} +
+ + {entry.content.length > 20 ? entry.content.slice(0, 20) + '...' : entry.content} + +
+ +
+ ))} +
); }