import React, { useRef, type MouseEvent } from 'react'; import { useTranslation } from 'react-i18next'; import { Tooltip, Space, App } from 'antd'; import { EyeOutlined } from '@ant-design/icons'; import type { HistoryQuery, HistoryItem, PromptDetailRef } from './types'; import RbCard from '@/components/RbCard/Card' import { getPromptReleaseListUrl, deletePrompt } from '@/api/prompt' import Markdown from '@/components/Markdown'; import { formatDateTime } from '@/utils/format' import PromptDetail from './components/PromptDetail' import PageScrollList, { type PageScrollListRef } from '@/components/PageScrollList' const History: React.FC<{ query: HistoryQuery; edit: (item: HistoryItem) => void; }> = ({ query, edit }) => { const { t } = useTranslation(); const scrollListRef = useRef(null) const detailRef = useRef(null) const { message, modal } = App.useApp() const handleView = (item: HistoryItem) => { detailRef.current?.handleOpen(item) } const handleDelete = (item: HistoryItem, e?: MouseEvent) => { e?.preventDefault(); e?.stopPropagation(); modal.confirm({ title: t('common.confirmDeleteDesc', { name: item.title }), okText: t('common.delete'), cancelText: t('common.cancel'), okType: 'danger', onOk: () => { deletePrompt(item.id).then(() => { message.success(t('common.deleteSuccess')) scrollListRef.current?.refresh() detailRef.current?.handleClose() }) } }) } const handleEdit = (item: HistoryItem) => { edit(item) } return ( <> { const historyItem = item as unknown as HistoryItem; return ( {historyItem.title}} extra={
{formatDateTime(historyItem.created_at, 'YYYY/MM/DD HH:mm')}
} onClick={() => handleView(historyItem)} >
handleView(historyItem)} />
handleEdit(historyItem)} >
handleDelete(historyItem, e)} >
); }} /> ); }; export default History;