From d4b60d0bc38d7f92d89d3e116a9ed2ca88298c09 Mon Sep 17 00:00:00 2001 From: ndom91 Date: Wed, 23 Oct 2024 17:50:47 +0200 Subject: [PATCH] fix: simplify pushAndCreate logic --- .../src/lib/branch/BranchHeader.svelte | 2 +- .../lib/branch/StackingSeriesHeader.svelte | 2 +- apps/desktop/src/lib/pr/PrDetailsModal.svelte | 23 ++++++++----------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/apps/desktop/src/lib/branch/BranchHeader.svelte b/apps/desktop/src/lib/branch/BranchHeader.svelte index f21f05967..af5e4cdcc 100644 --- a/apps/desktop/src/lib/branch/BranchHeader.svelte +++ b/apps/desktop/src/lib/branch/BranchHeader.svelte @@ -73,7 +73,7 @@ } function handleOpenPR() { - prDetailsModal?.show({ pushAndCreatePr: false }); + prDetailsModal?.show(false); } diff --git a/apps/desktop/src/lib/branch/StackingSeriesHeader.svelte b/apps/desktop/src/lib/branch/StackingSeriesHeader.svelte index 4cad8944f..9bd69e301 100644 --- a/apps/desktop/src/lib/branch/StackingSeriesHeader.svelte +++ b/apps/desktop/src/lib/branch/StackingSeriesHeader.svelte @@ -81,7 +81,7 @@ } function handleOpenPR(pushAndCreatePr: boolean = false) { - prDetailsModal?.show({ pushAndCreatePr, name: currentSeries.name }); + prDetailsModal?.show(pushAndCreatePr); } function editTitle(title: string) { diff --git a/apps/desktop/src/lib/pr/PrDetailsModal.svelte b/apps/desktop/src/lib/pr/PrDetailsModal.svelte index 43d9d2b6a..8cedc28ad 100644 --- a/apps/desktop/src/lib/pr/PrDetailsModal.svelte +++ b/apps/desktop/src/lib/pr/PrDetailsModal.svelte @@ -3,7 +3,6 @@ title: string; body: string; draft: boolean; - seriesName?: string; } @@ -99,8 +98,7 @@ let aiConfigurationValid = $state(false); let aiDescriptionDirective = $state(undefined); let showAiBox = $state(false); - let pushAndCreate = $state(false); - let seriesName = $state(''); + let pushBeforeCreatePr = $state(false); async function handleToggleUseTemplate() { if (!templateSelector) return; @@ -157,7 +155,7 @@ try { let upstreamBranchName = upstreamName; - if (pushAndCreate || commits.some((c) => !c.isRemote)) { + if (pushBeforeCreatePr || commits.some((c) => !c.isRemote)) { const firstPush = !branch.upstream; const pushResult = await branchController.pushBranch( branch.id, @@ -165,10 +163,6 @@ props.type === 'preview-series' ); - if (pushAndCreate) { - upstreamBranchName = seriesName; - } - if (pushResult) { upstreamBranchName = getBranchNameFromRef(pushResult.refname, pushResult.remote); } @@ -309,9 +303,11 @@ }, 2000); } - export function show({ pushAndCreatePr = false, name = '' }) { - pushAndCreate = pushAndCreatePr; - seriesName = name; + /** + * @param {boolean} pushAndCreate - Whether or not the commits need pushed before opening a PR + */ + export function show(pushAndCreate = false) { + pushBeforeCreatePr = pushAndCreate; modal?.show(); } @@ -447,9 +443,8 @@ type="submit" onclick={async () => await handleCreatePR(close)} > - {isDraft - ? 'Create pull request draft' - : `${pushAndCreate ? 'Push and ' : ''}Create pull request`} + {pushBeforeCreatePr ? 'Push and ' : ''} + {isDraft ? 'Create pull request draft' : `Create pull request`} {#snippet contextMenuSlot()}