Skip to content

Commit 80d6a18

Browse files
committed
Fix bug in draft stack branch name
This came about with a change to the `UiState` draft branch name, where we don't set it unless the user changes the default branch name.
1 parent d9e76ef commit 80d6a18

File tree

5 files changed

+36
-29
lines changed

5 files changed

+36
-29
lines changed

apps/desktop/src/components/MultiStackCreateNew.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
109109
async function showAndPrefillName() {
110110
createRefModal?.show();
111-
createRefName = await stackService.newBranchName(projectId);
111+
createRefName = await stackService.fetchNewBranchName(projectId);
112112
// Reset selected stack to default
113113
selectedStackId = undefined;
114114
}

apps/desktop/src/components/NewCommitView.svelte

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@
8181
return failed;
8282
}
8383
84-
const stackState = $derived(stackId ? uiState.stack(stackId) : undefined);
85-
const selection = $derived(stackState?.selection.current);
86-
8784
const exclusiveAction = $derived(projectState.exclusiveAction.current);
8885
const commitAction = $derived(exclusiveAction?.type === 'commit' ? exclusiveAction : undefined);
8986
@@ -92,11 +89,7 @@
9289
const topBranchName = $derived(topBranchResult?.current.data?.at(0)?.name);
9390
9491
const draftBranchName = $derived(uiState.global.draftBranchName.current);
95-
96-
const selectedBranchName = $derived(selection?.branchName || topBranchName);
97-
const canCommit = $derived(
98-
(selectedBranchName || draftBranchName || topBranchName) && selectedLines.current.length > 0
99-
);
92+
const canCommit = $derived(selectedLines.current.length > 0);
10093
10194
let input = $state<ReturnType<typeof CommitMessageEditor>>();
10295
@@ -110,13 +103,17 @@
110103
await tick();
111104
try {
112105
let finalStackId = stackId;
113-
let finalBranchName = commitAction?.branchName || topBranchName;
106+
let finalBranchName = commitAction?.branchName || draftBranchName || topBranchName;
107+
// TODO: Refactor this awkward fallback somehow.
108+
if (!finalBranchName) {
109+
finalBranchName = await stackService.fetchNewBranchName(projectId);
110+
}
114111
const parentId = commitAction?.parentCommitId;
115112
116113
if (!finalStackId) {
117114
const stack = await createNewStack({
118115
projectId,
119-
branch: { name: draftBranchName, order: 0 }
116+
branch: { name: finalBranchName, order: 0 }
120117
});
121118
finalStackId = stack.id;
122119
projectState.stackId.set(finalStackId);

apps/desktop/src/components/StackDraft.svelte

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import CommitGoesHere from '$components/CommitGoesHere.svelte';
44
import ConfigurableScrollableContainer from '$components/ConfigurableScrollableContainer.svelte';
55
import NewCommitView from '$components/NewCommitView.svelte';
6+
import ReduxResult from '$components/ReduxResult.svelte';
67
import Resizer from '$components/Resizer.svelte';
78
import { StackService } from '$lib/stacks/stackService.svelte';
89
import { UiState } from '$lib/state/uiState.svelte';
@@ -43,20 +44,22 @@
4344
<div class="new-commit-view" data-testid={TestId.NewCommitView}>
4445
<NewCommitView {projectId} />
4546
</div>
46-
{#await newNameResult then newName}
47-
{@const branchName = draftBranchName.current || newName}
48-
<BranchCard
49-
type="draft-branch"
50-
{projectId}
51-
{branchName}
52-
readonly={false}
53-
lineColor="var(--clr-commit-local)"
54-
>
55-
{#snippet branchContent()}
56-
<CommitGoesHere commitId={undefined} selected last />
57-
{/snippet}
58-
</BranchCard>
59-
{/await}
47+
<ReduxResult {projectId} result={newNameResult.current}>
48+
{#snippet children(newName)}
49+
{@const branchName = draftBranchName.current || newName}
50+
<BranchCard
51+
type="draft-branch"
52+
{projectId}
53+
{branchName}
54+
readonly={false}
55+
lineColor="var(--clr-commit-local)"
56+
>
57+
{#snippet branchContent()}
58+
<CommitGoesHere commitId={undefined} selected last />
59+
{/snippet}
60+
</BranchCard>
61+
{/snippet}
62+
</ReduxResult>
6063
<Resizer
6164
persistId="resizer-darft-panel"
6265
viewport={draftPanelEl}

apps/desktop/src/components/v3/FileContextMenu.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
const branchName = selectionId.branchName;
240240
241241
const fileNames = changes.map((change) => change.path);
242-
const newBranchName = await stackService.newBranchName(projectId);
242+
const newBranchName = await stackService.fetchNewBranchName(projectId);
243243
244244
if (!newBranchName) {
245245
toasts.error('Failed to generate a new branch name.');
@@ -269,7 +269,7 @@
269269
const branchName = selectionId.branchName;
270270
271271
const fileNames = changes.map((change) => change.path);
272-
const newBranchName = await stackService.newBranchName(projectId);
272+
const newBranchName = await stackService.fetchNewBranchName(projectId);
273273
274274
if (!newBranchName) {
275275
toasts.error('Failed to generate a new branch name.');
@@ -306,7 +306,7 @@
306306
<ContextMenuItem
307307
label="Stash into branch"
308308
onclick={() => {
309-
stackService.newBranchName(projectId).then((name) => {
309+
stackService.fetchNewBranchName(projectId).then((name) => {
310310
stashBranchName = name || '';
311311
});
312312
stashConfirmationModal?.show(item);

apps/desktop/src/lib/stacks/stackService.svelte.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,14 @@ export class StackService {
736736
});
737737
}
738738

739-
async newBranchName(projectId: string) {
739+
newBranchName(projectId: string) {
740+
const result = $derived(
741+
this.api.endpoints.newBranchName.useQuery({ projectId }, { forceRefetch: true })
742+
);
743+
return result;
744+
}
745+
746+
async fetchNewBranchName(projectId: string) {
740747
return await this.api.endpoints.newBranchName.fetch({ projectId }, { forceRefetch: true });
741748
}
742749

0 commit comments

Comments
 (0)