From 5cf11cee87fb3b8780af78ff8b1b725df6fdaafe Mon Sep 17 00:00:00 2001 From: Kiril Videlov Date: Tue, 27 Jun 2023 16:41:04 +0200 Subject: [PATCH] move set_target_branch to VirtualBranchesStore --- src/routes/projects_new/[projectId]/+page.svelte | 11 +++-------- src/routes/projects_new/[projectId]/vbranches.ts | 11 ++++++++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/routes/projects_new/[projectId]/+page.svelte b/src/routes/projects_new/[projectId]/+page.svelte index f77becbd3..d3d5b5796 100644 --- a/src/routes/projects_new/[projectId]/+page.svelte +++ b/src/routes/projects_new/[projectId]/+page.svelte @@ -17,13 +17,6 @@ : []; let targetChoice = 'origin/master'; // prob should check if it exists - async function setTarget() { - return invoke('set_target_branch', { - projectId: projectId, - branch: targetChoice - }); - } - async function createBranch(params: { projectId: string; name: string; path: string }) { return invoke('create_virtual_branch', params); } @@ -60,7 +53,9 @@ {/if} {/each} - + {/if} {/if} diff --git a/src/routes/projects_new/[projectId]/vbranches.ts b/src/routes/projects_new/[projectId]/vbranches.ts index 97829ce61..62a4fc4e2 100644 --- a/src/routes/projects_new/[projectId]/vbranches.ts +++ b/src/routes/projects_new/[projectId]/vbranches.ts @@ -10,6 +10,7 @@ const cache: Map = new Map(); export interface VirtualBranchStore { subscribe: (branches: Subscriber>) => Unsubscriber; refresh: () => void; + setTarget: (branch: string) => Promise; } export function getStore(projectId: string): VirtualBranchStore { @@ -22,7 +23,15 @@ export function getStore(projectId: string): VirtualBranchStore { const store: VirtualBranchStore = { subscribe: writeable.subscribe, refresh: () => - list(projectId).then((newBranches) => writeable.set({ isLoading: false, value: newBranches })) + list(projectId).then((newBranches) => + writeable.set({ isLoading: false, value: newBranches }) + ), + setTarget(branch) { + return invoke('set_target_branch', { + projectId: projectId, + branch: branch + }); + } }; cache.set(projectId, store); return store;