refactor: memo editor components (#1625)

This commit is contained in:
boojack
2023-05-03 19:13:37 +08:00
committed by GitHub
parent 8911ea1619
commit e3496ac1a2
12 changed files with 217 additions and 191 deletions

View File

@ -0,0 +1,35 @@
import { useEditorStore } from "@/store/module";
import { deleteMemoResource } from "@/helpers/api";
import Icon from "../Icon";
import ResourceIcon from "../ResourceIcon";
const ResourceListView = () => {
const editorStore = useEditorStore();
const editorState = editorStore.state;
const handleDeleteResource = async (resourceId: ResourceId) => {
editorStore.setResourceList(editorState.resourceList.filter((resource) => resource.id !== resourceId));
if (editorState.editMemoId) {
await deleteMemoResource(editorState.editMemoId, resourceId);
}
};
return (
<>
{editorState.resourceList && editorState.resourceList.length > 0 && (
<div className="resource-list-wrapper">
{editorState.resourceList.map((resource) => {
return (
<div key={resource.id} className="resource-container">
<ResourceIcon resourceType="resource.type" className="icon-img" />
<span className="name-text">{resource.filename}</span>
<Icon.X className="close-icon" onClick={() => handleDeleteResource(resource.id)} />
</div>
);
})}
</div>
)}
</>
);
};
export default ResourceListView;