update_virtual_branch to VirtualBranchesStore

This commit is contained in:
Kiril Videlov 2023-06-27 17:54:28 +02:00 committed by Kiril Videlov
parent 59ddd5cf39
commit 52839c2306
2 changed files with 16 additions and 6 deletions

View File

@ -37,11 +37,6 @@
return invoke<object>('move_virtual_branch_files', params);
}
const update_branch = async (params: {
projectId: string;
branch: { id: string; name: string };
}) => invoke('update_virtual_branch', params);
function handleDndEvent(e: CustomEvent<DndEvent<File | Hunk>>) {
const newItems = e.detail.items;
const fileItems = newItems.filter((item) => item instanceof File) as File[];
@ -123,7 +118,7 @@
function handleBranchNameChange() {
console.log('branch name change:', name);
update_branch({ projectId: projectId, branch: { id: branchId, name: name } });
virtualBranches.updateBranchName(branchId, name);
}
</script>

View File

@ -15,6 +15,7 @@ export interface VirtualBranchStore {
createBranch: (name: string, path: string) => Promise<void | object>;
commitBranch: (branch: string, message: string) => Promise<void | object>;
updateBranchTarget: () => Promise<void | object>;
updateBranchName: (branchId: string, name: string) => Promise<void | object>;
}
export function getStore(projectId: string): VirtualBranchStore {
@ -66,6 +67,20 @@ export function getStore(projectId: string): VirtualBranchStore {
console.log(err);
error('Unable to update target!');
});
},
updateBranchName(branchId, name) {
return invoke<object>('update_virtual_branch', {
projectId: projectId,
branch: { id: branchId, name: name }
})
.then((res) => {
console.log(res);
refresh(projectId, writeable);
})
.catch((err) => {
console.log(err);
error('Unable to update branch!');
});
}
};
cache.set(projectId, store);