import { useState } from 'react'; import { Tag, Space, Popconfirm } from 'antd'; import { path, shell } from '@tauri-apps/api'; import { EditRow } from '@/hooks/useColumns'; import useInit from '@/hooks/useInit'; import { fmtDate, chatRoot } from '@/utils'; const colorMap: any = { pdf: 'blue', png: 'orange', }; export const downloadColumns = () => [ { title: 'Name', dataIndex: 'name', fixed: 'left', key: 'name', width: 240, render: (_: string, row: any, actions: any) => ( ), }, { title: 'Extension', dataIndex: 'ext', key: 'ext', width: 120, render: (v: string) => {v}, }, { title: 'Path', dataIndex: 'path', key: 'path', width: 200, render: (_: string, row: any) => , }, { title: 'Created', dataIndex: 'created', key: 'created', width: 150, render: fmtDate, }, { title: 'Action', fixed: 'right', width: 150, render: (_: any, row: any, actions: any) => { return ( actions.setRecord(row, 'preview')}>Preview actions.setRecord(row, 'delete')} okText="Yes" cancelText="No" > Delete ); }, }, ]; const RenderPath = ({ row }: any) => { const [filePath, setFilePath] = useState(''); useInit(async () => { setFilePath(await getPath(row)); }); return shell.open(filePath)}>{filePath}; }; export const getPath = async (row: any) => { const isImg = ['png'].includes(row?.ext); return ( (await path.join(await chatRoot(), 'download', isImg ? 'img' : row.ext, row.id)) + `.${row.ext}` ); };