import { useState } from 'react'; import { Tag, Space, Popconfirm } from 'antd'; import { HistoryOutlined } from '@ant-design/icons'; import { shell, path } from '@tauri-apps/api'; import { Link } from 'react-router-dom'; import useInit from '@/hooks/useInit'; import { chatRoot, fmtDate } from '@/utils'; export const syncColumns = () => [ { title: 'Name', dataIndex: 'name', key: 'name', width: 100, }, { title: 'Protocol', dataIndex: 'protocol', key: 'protocol', width: 80, render: (v: string) => {v}, }, { title: 'PATH', dataIndex: 'path', key: 'path', width: 180, render: (_: string, row: any) => }, { title: 'Last updated', dataIndex: 'last_updated', key: 'last_updated', width: 140, render: (v: number) => (
{ v ? fmtDate(v) : ''}
), }, { title: 'Action', fixed: 'right', width: 150, render: (_: any, row: any, actions: any) => { return ( actions.setRecord(row, 'sync')} okText="Yes" cancelText="No" > Sync {row.last_updated && View} actions.setRecord(row, 'edit')}>Edit 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) => { if (!/^http/.test(row.protocol)) { return await path.join(await chatRoot(), row.path) + `.${row.ext}`; } else { return `${row.protocol}://${row.path}.${row.ext}`; } }