Skip to content

Commit

Permalink
fix: remote tool local edit
Browse files Browse the repository at this point in the history
  • Loading branch information
KeJunMao committed Mar 16, 2023
1 parent afc09a1 commit 580364a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 2 additions & 7 deletions components/create/CreateForms.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<script lang="ts" setup>
const { step, maxStep, nextStep, prevStep, tool, isCreate, formEl } =
useCreateTool();
const { create, update } = useLocalTools();
const { create, createOrUpdate } = useLocalTools();
const localePath = useLocalePath();
const { isRemoteTool } = useTools();
const handleSave = () => {
formEl.value?.validate((isValid) => {
if (isValid) {
Expand All @@ -15,11 +14,7 @@ const handleSave = () => {
create(tool.value);
ElMessage.success("Create Success");
} else {
if (isRemoteTool(tool.value.id!)) {
create(tool.value);
} else {
update(tool.value);
}
createOrUpdate(tool.value);
ElMessage.success("Update Success");
}
}
Expand Down
9 changes: 9 additions & 0 deletions composables/useLocalTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@ export const useLocalTools = () => {
tools.value = tools.value.filter((v) => v.id?.includes("-"));
}

function createOrUpdate(tool: ToolItem) {
if (get(tool.id!)) {
update(tool);
} else {
create(tool);
}
}

return {
tools,
create,
get,
remove,
update,
clearRemoteCache,
createOrUpdate,
};
};

0 comments on commit 580364a

Please sign in to comment.