chore: optim

This commit is contained in:
lencx
2022-12-19 23:09:17 +08:00
parent 8966ebbd03
commit 47a3bace5b
9 changed files with 142 additions and 56 deletions

View File

@@ -1,4 +1,4 @@
import { Tag, Switch, Tooltip, Space } from 'antd';
import { Tag, Switch, Tooltip, Space, Popconfirm } from 'antd';
export const modelColumns = () => [
{
@@ -29,7 +29,9 @@ export const modelColumns = () => [
dataIndex: 'enable',
key: 'enable',
width: 80,
render: (v: boolean = false) => <Switch checked={v} disabled />,
render: (v: boolean = false, row: Record<string, any>, action: Record<string, any>) => (
<Switch checked={v} onChange={(v) => action.setRecord({ ...row, enable: v }, 'enable')} />
),
},
{
title: 'Prompt',
@@ -48,7 +50,14 @@ export const modelColumns = () => [
render: (_: any, row: any, actions: any) => (
<Space size="middle">
<a onClick={() => actions.setRecord(row, 'edit')}>Edit</a>
<a onClick={() => actions.setRecord(row, 'delete')}>Delete</a>
<Popconfirm
title="Are you sure to delete this model?"
onConfirm={() => actions.setRecord(row, 'delete')}
okText="Yes"
cancelText="No"
>
<a>Delete</a>
</Popconfirm>
</Space>
),
}

View File

@@ -3,9 +3,9 @@ import { Table, Button, Modal, message } from 'antd';
import { invoke } from '@tauri-apps/api';
import useInit from '@/hooks/useInit';
import useData from '@/hooks/useData';
import useChatModel from '@/hooks/useChatModel';
import useColumns from '@/hooks/useColumns';
import useData from '@/hooks/useData';
import { chatModelPath } from '@/utils';
import { modelColumns } from './config';
import LanguageModelForm from './Form';
@@ -15,10 +15,15 @@ export default function LanguageModel() {
const [isVisible, setVisible] = useState(false);
const [modelPath, setChatModelPath] = useState('');
const { modelData, modelSet } = useChatModel('user_custom');
const { opData, opAdd, opRemove, opReplace, opSafeKey } = useData(modelData);
const { opData, opInit, opAdd, opRemove, opReplace, opSafeKey } = useData([]);
const { columns, ...opInfo } = useColumns(modelColumns());
const formRef = useRef<any>(null);
useEffect(() => {
if (modelData.length <= 0) return;
opInit(modelData);
}, [modelData])
useEffect(() => {
if (!opInfo.opType) return;
if (['edit', 'new'].includes(opInfo.opType)) {
@@ -31,6 +36,13 @@ export default function LanguageModel() {
}
}, [opInfo.opType, formRef]);
useEffect(() => {
if (opInfo.opType === 'enable') {
const data = opReplace(opInfo?.opRecord?.[opSafeKey], opInfo?.opRecord);
modelSet(data);
}
}, [opInfo.opTime])
useInit(async () => {
const path = await chatModelPath();
setChatModelPath(path);