test tank
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { Fragment, Suspense, useEffect, useState } from 'react';
|
||||
import { useContainerStore } from '../store';
|
||||
import { useShallow } from 'zustand/react/shallow';
|
||||
// import copy from 'copy-to-clipboard';
|
||||
import { useNewNavigate } from '@/modules';
|
||||
import { message } from '@/modules/message';
|
||||
@@ -26,45 +25,37 @@ const DrawEdit = React.lazy(() => import('../module/DrawEdit'));
|
||||
|
||||
const FormModal = () => {
|
||||
const { control, handleSubmit, reset, setValue } = useForm();
|
||||
const containerStore = useContainerStore(
|
||||
useShallow((state) => {
|
||||
return {
|
||||
showEdit: state.showEdit,
|
||||
setShowEdit: state.setShowEdit,
|
||||
formData: state.formData,
|
||||
updateData: state.updateData,
|
||||
};
|
||||
}),
|
||||
);
|
||||
const containerStore = useContainerStore();
|
||||
const { showEdit, setShowEdit, formData, updateData } = containerStore;
|
||||
|
||||
useEffect(() => {
|
||||
const open = containerStore.showEdit;
|
||||
const open = showEdit;
|
||||
if (open) {
|
||||
const isNull = isObjectNull(containerStore.formData);
|
||||
const isNull = isObjectNull(formData);
|
||||
if (isNull) {
|
||||
reset({});
|
||||
} else {
|
||||
Object.keys(containerStore.formData).forEach((key) => {
|
||||
setValue(key, containerStore.formData[key]);
|
||||
Object.keys(formData).forEach((key) => {
|
||||
setValue(key, formData[key]);
|
||||
});
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
reset({});
|
||||
};
|
||||
}, [containerStore.showEdit]);
|
||||
}, [showEdit]);
|
||||
|
||||
const onFinish = async (values: any) => {
|
||||
const pickValues = pick(values, ['id', 'title', 'description', 'tags', 'code']);
|
||||
containerStore.updateData(pickValues);
|
||||
updateData(pickValues);
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
containerStore.setShowEdit(false);
|
||||
setShowEdit(false);
|
||||
reset();
|
||||
};
|
||||
|
||||
const isEdit = containerStore.formData.id;
|
||||
const isEdit = formData.id;
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Dialog open={containerStore.showEdit} onClose={onClose}>
|
||||
@@ -105,35 +96,27 @@ const FormModal = () => {
|
||||
const PublishFormModal = () => {
|
||||
const { control, handleSubmit, reset, setValue, getValues } = useForm();
|
||||
const { t } = useTranslation();
|
||||
const containerStore = useContainerStore(
|
||||
useShallow((state) => {
|
||||
return {
|
||||
showEdit: state.showPublish,
|
||||
setShowEdit: state.setShowPublish,
|
||||
formData: state.formData,
|
||||
updateData: state.updateData,
|
||||
};
|
||||
}),
|
||||
);
|
||||
const containerStore = useContainerStore();
|
||||
const { showPublish, setShowPublish, formData, updateData } = containerStore;
|
||||
|
||||
useEffect(() => {
|
||||
const open = containerStore.showEdit;
|
||||
const open = showPublish;
|
||||
if (open) {
|
||||
const isNull = isObjectNull(containerStore.formData);
|
||||
const isNull = isObjectNull(formData);
|
||||
if (isNull) {
|
||||
reset({});
|
||||
} else {
|
||||
Object.keys(containerStore.formData).forEach((key) => {
|
||||
setValue(key, containerStore.formData[key]);
|
||||
Object.keys(formData).forEach((key) => {
|
||||
setValue(key, formData[key]);
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [containerStore.showEdit]);
|
||||
}, [showPublish]);
|
||||
|
||||
const onFinish = async () => {
|
||||
const values = getValues();
|
||||
const pickValues = pick(values, ['id', 'publish.key', 'publish.version', 'publish.fileName', 'publish.description']);
|
||||
const containerRes = await containerStore.updateData(pickValues, { closePublish: false });
|
||||
const containerRes = await updateData(pickValues, { closePublish: false });
|
||||
if (containerRes.code === 200) {
|
||||
const code = containerRes.data?.code || '-';
|
||||
const fileName = values['publish']?.['fileName'];
|
||||
@@ -167,16 +150,16 @@ const PublishFormModal = () => {
|
||||
|
||||
const onUpdate = async () => {
|
||||
const values = getValues();
|
||||
containerStore.updateData(values);
|
||||
updateData(values);
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
containerStore.setShowEdit(false);
|
||||
setShowPublish(false);
|
||||
reset();
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={containerStore.showEdit} onClose={onClose}>
|
||||
<Dialog open={showPublish} onClose={onClose}>
|
||||
<DialogTitle>Publish</DialogTitle>
|
||||
<DialogContent sx={{ padding: '10px', minWidth: '600px' }}>
|
||||
<form className='flex flex-col gap-6 pt-2' onSubmit={handleSubmit(onFinish)}>
|
||||
@@ -224,28 +207,11 @@ const PublishFormModal = () => {
|
||||
};
|
||||
export const ContainerList = () => {
|
||||
const [modal, contextHolder] = useModal();
|
||||
const containerStore = useContainerStore(
|
||||
useShallow((state) => {
|
||||
return {
|
||||
setFormData: state.setFormData,
|
||||
setShowEdit: state.setShowEdit,
|
||||
list: state.list,
|
||||
deleteData: state.deleteData,
|
||||
getList: state.getList,
|
||||
loading: state.loading,
|
||||
// publishData: state.publishData,
|
||||
setShowPublish: state.setShowPublish,
|
||||
updateData: state.updateData,
|
||||
formData: state.formData,
|
||||
getOne: state.getOne,
|
||||
setOpenDrawEdit: state.setOpenDrawEdit,
|
||||
openDrawEdit: state.openDrawEdit,
|
||||
};
|
||||
}),
|
||||
);
|
||||
const containerStore = useContainerStore();
|
||||
const { setFormData, setShowEdit, list, deleteData, getList, loading, setShowPublish, updateData, formData, getOne, setOpenDrawEdit, openDrawEdit } = containerStore;
|
||||
|
||||
useEffect(() => {
|
||||
containerStore.getList();
|
||||
getList();
|
||||
}, []);
|
||||
|
||||
const onAdd = () => {
|
||||
@@ -302,9 +268,9 @@ export const ContainerList = () => {
|
||||
<Tooltip title='编辑代码'>
|
||||
<Button
|
||||
onClick={(e) => {
|
||||
containerStore.getOne(item.id);
|
||||
containerStore.setFormData(item);
|
||||
containerStore.setOpenDrawEdit(true);
|
||||
getOne(item.id);
|
||||
setFormData(item);
|
||||
setOpenDrawEdit(true);
|
||||
e.stopPropagation();
|
||||
}}>
|
||||
<Settings size={16} />
|
||||
@@ -313,8 +279,8 @@ export const ContainerList = () => {
|
||||
<Tooltip title='编辑'>
|
||||
<Button
|
||||
onClick={(e) => {
|
||||
containerStore.setFormData(item);
|
||||
containerStore.setShowEdit(true);
|
||||
setFormData(item);
|
||||
setShowEdit(true);
|
||||
e.stopPropagation();
|
||||
}}>
|
||||
<EditOutlined />
|
||||
@@ -323,9 +289,8 @@ export const ContainerList = () => {
|
||||
<Tooltip title='添加到 user app当中'>
|
||||
<Button
|
||||
onClick={(e) => {
|
||||
// containerStore.publishData(item);
|
||||
containerStore.setFormData(item);
|
||||
containerStore.setShowPublish(true);
|
||||
setFormData(item);
|
||||
setShowPublish(true);
|
||||
e.stopPropagation();
|
||||
}}>
|
||||
<CloudUploadOutlined />
|
||||
@@ -340,7 +305,7 @@ export const ContainerList = () => {
|
||||
title: 'Delete',
|
||||
content: 'Are you sure delete this data?',
|
||||
onOk: () => {
|
||||
containerStore.deleteData(item.id);
|
||||
deleteData(item.id);
|
||||
},
|
||||
});
|
||||
e.stopPropagation();
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
import { Route, Routes } from 'react-router-dom';
|
||||
import { ContainerList } from './edit/List';
|
||||
import { Main } from './layouts';
|
||||
import { Preview, PreviewWrapper } from './preview';
|
||||
import { Redirect } from '@/modules/Redirect';
|
||||
|
||||
export const App = () => {
|
||||
return (
|
||||
<Routes>
|
||||
<Route element={<Main />}>
|
||||
<Route path='/' element={<Redirect to='/container/edit/list' />}></Route>
|
||||
<Route path='edit/list' element={<ContainerList />} />
|
||||
<Route path='preview/:id/wrapper' element={<PreviewWrapper />} />
|
||||
</Route>
|
||||
<Route path='preview/:id' element={<Preview />} />
|
||||
</Routes>
|
||||
);
|
||||
return <Main />;
|
||||
};
|
||||
|
||||
export default App;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { lazy, useEffect, useRef, useState } from 'react';
|
||||
import { Box, Drawer } from '@mui/material';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import { useContainerStore } from '../store';
|
||||
import { Tooltip } from '@mui/material';
|
||||
import { IconButton } from '@kevisual/components/button/index.tsx';
|
||||
@@ -12,17 +11,8 @@ import { BaseEditor } from '@kevisual/codemirror/editor/editor.ts';
|
||||
export const DrawEdit = () => {
|
||||
const editorElRef = useRef<HTMLDivElement>(null);
|
||||
const editorRef = useRef<BaseEditor>(null);
|
||||
const containerStore = useContainerStore(
|
||||
useShallow((state) => {
|
||||
return {
|
||||
openDrawEdit: state.openDrawEdit,
|
||||
setOpenDrawEdit: state.setOpenDrawEdit,
|
||||
data: state.data,
|
||||
updateData: state.updateData,
|
||||
};
|
||||
}),
|
||||
);
|
||||
const { openDrawEdit, setOpenDrawEdit } = containerStore;
|
||||
const containerStore = useContainerStore();
|
||||
const { openDrawEdit, setOpenDrawEdit, data, updateData } = containerStore;
|
||||
const [mount, setMount] = useState(false);
|
||||
useEffect(() => {
|
||||
if (openDrawEdit && editorElRef.current && !mount) {
|
||||
@@ -95,7 +85,7 @@ export const DrawEdit = () => {
|
||||
}}
|
||||
onClick={() => {
|
||||
const code = editorRef.current?.getContent();
|
||||
containerStore.updateData({ id: containerStore.data.id, code }, { refresh: false });
|
||||
updateData({ id: data.id, code }, { refresh: false });
|
||||
}}>
|
||||
<SaveOutlined />
|
||||
</IconButton>
|
||||
@@ -114,7 +104,7 @@ export const DrawEdit = () => {
|
||||
</IconButton>
|
||||
</Tooltip> */}
|
||||
</div>
|
||||
<div className='flex-1 ml-2 flex items-center'>{containerStore.data?.title}</div>
|
||||
<div className='flex-1 ml-2 flex items-center'>{data?.title}</div>
|
||||
</div>
|
||||
</div>
|
||||
<Box
|
||||
|
||||
Reference in New Issue
Block a user