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.map(entry => ( +