Skip to content

Commit 15cc30a

Browse files
committed
Fix some issues with commit goes here
test4 Fix clicking on commit goes here
1 parent 21e2f7e commit 15cc30a

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@
5959
isVerticalMode: boolean;
6060
projectId: string;
6161
stackId: string;
62+
active: boolean;
6263
};
6364
64-
const { isVerticalMode, projectId, stackId }: Props = $props();
65+
const { isVerticalMode, projectId, stackId, active }: Props = $props();
6566
const [stackService, uiState, baseBranchService, forge, modeService] = inject(
6667
StackService,
6768
UiState,
@@ -172,6 +173,7 @@
172173
{@const isNewBranch =
173174
upstreamOnlyCommits.length === 0 && localAndRemoteCommits.length === 0}
174175
{@const selected =
176+
active &&
175177
selection?.current?.branchName === branchName &&
176178
selection?.current.commitId === undefined}
177179
<BranchCard
@@ -214,6 +216,7 @@
214216
branchName,
215217
commitId: headCommit
216218
});
219+
projectState.stackId.set(stackId);
217220
} else {
218221
uiState.stack(stackId).selection.set({ branchName });
219222
uiState.project(projectId).drawerPage.set('branch');
@@ -251,14 +254,17 @@
251254
{#snippet empty()}
252255
{#if isCommitting}
253256
<CommitGoesHere
254-
selected={branchName === selectedBranchName}
257+
selected={active && branchName === selectedBranchName}
255258
first
256259
last
257-
onclick={() =>
260+
onclick={() => {
258261
uiState.stack(stackId).selection.set({
259262
branchName,
260263
commitId: branchDetails.baseCommit
261-
})}
264+
});
265+
projectState.stackId.set(stackId);
266+
goto(stackPath(projectId, stackId));
267+
}}
262268
/>
263269
{/if}
264270
{/snippet}
@@ -300,10 +306,13 @@
300306
})}
301307
{@const commitId = commit.id}
302308
{@const selected =
303-
commit.id === selectedCommitId && branchName === selectedBranchName}
309+
active &&
310+
commit.id === selectedCommitId &&
311+
branchName === selectedBranchName}
304312
{#if isCommitting}
305313
{@const nothingSelectedButFirst = selectedCommitId === undefined && first}
306314
{@const selectedForCommit =
315+
active &&
307316
(nothingSelectedButFirst || commit.id === selectedCommitId) &&
308317
((first && selectedBranchName === undefined) ||
309318
branchName === selectedBranchName)}
@@ -313,8 +322,9 @@
313322
{first}
314323
last={false}
315324
onclick={() => {
316-
uiState.stack(stackId).selection.set({ branchName, commitId });
317325
projectState.stackId.set(stackId);
326+
uiState.stack(stackId).selection.set({ branchName, commitId });
327+
goto(stackPath(projectId, stackId));
318328
}}
319329
/>
320330
{/if}
@@ -452,13 +462,15 @@
452462
<CommitGoesHere
453463
{first}
454464
{last}
455-
selected={selectedCommitId === baseSha &&
465+
selected={active &&
466+
selectedCommitId === baseSha &&
456467
branchName === selectedBranchName}
457468
onclick={() => {
458469
uiState
459470
.stack(stackId)
460471
.selection.set({ branchName, commitId: baseSha });
461472
projectState.stackId.set(stackId);
473+
goto(stackPath(projectId, stackId));
462474
}}
463475
/>
464476
{/if}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
projectId: string;
3434
stackId: string;
3535
commitKey: CommitKey;
36+
onerror: (err: unknown) => void;
3637
};
3738
38-
const { projectId, stackId, commitKey }: Props = $props();
39+
const { projectId, stackId, commitKey, onerror }: Props = $props();
3940
4041
const [stackService, uiState] = inject(StackService, UiState);
4142
@@ -126,7 +127,7 @@
126127
}
127128
</script>
128129

129-
<ReduxResult {stackId} {projectId} result={commitResult.current}>
130+
<ReduxResult {stackId} {projectId} result={commitResult.current} {onerror}>
130131
{#snippet children(commit, env)}
131132
{@const isConflicted = isCommit(commit) && commit.hasConflicts}
132133
{#if mode === 'edit'}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
});
4747
4848
const [uiState] = inject(UiState);
49-
const drawer = $derived(uiState.project(projectId).drawerPage);
49+
const projectState = $derived(uiState.project(projectId));
50+
const drawer = $derived(projectState.drawerPage);
5051
const isCommitting = $derived(drawer.current === 'new-commit');
5152
5253
const SHOW_PAGINATION_THRESHOLD = 1;
@@ -95,6 +96,7 @@
9596

9697
{#if stacks.length > 0}
9798
{#each stacks as stack, i}
99+
{@const active = stack.id === projectState.stackId.current}
98100
<div
99101
class="lane"
100102
class:multi={$mode === 'multi' || stacks.length < SHOW_PAGINATION_THRESHOLD}
@@ -119,7 +121,12 @@
119121
}
120122
}}
121123
>
122-
<BranchList isVerticalMode={$mode === 'vertical'} {projectId} stackId={stack.id} />
124+
<BranchList
125+
isVerticalMode={$mode === 'vertical'}
126+
{projectId}
127+
stackId={stack.id}
128+
{active}
129+
/>
123130
</div>
124131
{/each}
125132
{:else if isCommitting}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
import ReviewView from '$components/v3/ReviewView.svelte';
99
import SelectionView from '$components/v3/SelectionView.svelte';
1010
import WorktreeChanges from '$components/v3/WorktreeChanges.svelte';
11+
import { isParsedError } from '$lib/error/parser';
1112
import { Focusable, FocusManager } from '$lib/focus/focusManager.svelte';
1213
import { focusable } from '$lib/focus/focusable.svelte';
1314
import { StackService } from '$lib/stacks/stackService.svelte';
1415
import { UiState } from '$lib/state/uiState.svelte';
1516
import { inject } from '@gitbutler/shared/context';
1617
18+
import { QueryStatus } from '@reduxjs/toolkit/query';
1719
import type { SelectionId } from '$lib/selection/key';
1820
1921
interface Props {
@@ -42,6 +44,17 @@
4244
const commitId = $derived(currentSelection?.commitId);
4345
const upstream = $derived(!!currentSelection?.upstream);
4446
47+
const stackResult = $derived(stackId ? stackService.stackById(projectId, stackId) : undefined);
48+
$effect(() => {
49+
if (
50+
stackResult?.current.status === QueryStatus.fulfilled &&
51+
stackResult.current.data === undefined
52+
) {
53+
projectState.stackId.set(undefined);
54+
stackSelection?.set(undefined);
55+
}
56+
});
57+
4558
const selectionId: SelectionId = $derived.by(() => {
4659
if (focusGroup.current === Focusable.ChangedFiles && currentSelection && stackId) {
4760
if (currentSelection.commitId) {
@@ -64,6 +77,14 @@
6477
6578
let leftDiv = $state<HTMLElement>();
6679
let stacksViewEl = $state<HTMLElement>();
80+
81+
function onerror(err: unknown) {
82+
// Clear selection if branch not found.
83+
if (isParsedError(err) && err.code === 'errors.branch.notfound') {
84+
stackSelection?.set(undefined);
85+
console.warn('Workspace selection cleared');
86+
}
87+
}
6788
</script>
6889

6990
<div class="workspace" use:focusable={{ id: Focusable.Workspace }}>
@@ -93,7 +114,7 @@
93114
{#if drawerPage.current === 'new-commit'}
94115
<NewCommitView {projectId} {stackId} />
95116
{:else if drawerPage.current === 'branch' && stackId && branchName}
96-
<BranchView {stackId} {projectId} {branchName} />
117+
<BranchView {stackId} {projectId} {branchName} {onerror} />
97118
{:else if drawerPage.current === 'review' && stackId && branchName}
98119
<ReviewView {stackId} {projectId} {branchName} />
99120
{:else if branchName && commitId && stackId}
@@ -106,6 +127,7 @@
106127
commitId,
107128
upstream
108129
}}
130+
{onerror}
109131
/>
110132
{/if}
111133
</div>

0 commit comments

Comments
 (0)