Skip to content

Commit abbf34f

Browse files
committed
Add draft mechanism for codegen
Extend the StackDraft component to also handle draft codegen sessions, using the message queue in order to facilitate sending the first message.
1 parent 9f6c5c8 commit abbf34f

14 files changed

+639
-417
lines changed

apps/desktop/src/components/ChromeHeader.svelte

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import { goto } from '$app/navigation';
3+
import CreateBranchModal from '$components/CreateBranchModal.svelte';
34
import IntegrateUpstreamModal from '$components/IntegrateUpstreamModal.svelte';
45
import SyncButton from '$components/SyncButton.svelte';
56
import { BACKEND } from '$lib/backend';
@@ -11,9 +12,13 @@
1112
import { handleAddProjectOutcome } from '$lib/project/project';
1213
import { PROJECTS_SERVICE } from '$lib/project/projectsService';
1314
import { ircPath, projectPath } from '$lib/routes/routes.svelte';
15+
import { UI_STATE } from '$lib/state/uiState.svelte';
1416
import { inject } from '@gitbutler/core/context';
1517
import {
1618
Button,
19+
ContextMenu,
20+
ContextMenuItem,
21+
ContextMenuSection,
1722
Icon,
1823
NotificationButton,
1924
OptionsGroup,
@@ -36,6 +41,7 @@
3641
const baseBranchService = inject(BASE_BRANCH_SERVICE);
3742
const ircService = inject(IRC_SERVICE);
3843
const settingsService = inject(SETTINGS_SERVICE);
44+
const uiState = inject(UI_STATE);
3945
const modeService = inject(MODE_SERVICE);
4046
const baseReponse = $derived(projectId ? baseBranchService.baseBranch(projectId) : undefined);
4147
const base = $derived(baseReponse?.response);
@@ -75,6 +81,8 @@
7581
const isHasUpstreamCommits = $derived(upstreamCommits > 0);
7682
7783
let modal = $state<ReturnType<typeof IntegrateUpstreamModal>>();
84+
let createNewContextMenu = $state<ContextMenu>();
85+
let createNewTrigger = $state<HTMLButtonElement>();
7886
7987
const projects = $derived(projectsService.projects());
8088
@@ -93,6 +101,8 @@
93101
function openModal() {
94102
modal?.show();
95103
}
104+
105+
let createBranchModal = $state<CreateBranchModal>();
96106
</script>
97107

98108
{#if projectId}
@@ -243,9 +253,38 @@
243253
}}
244254
/>
245255
{/if}
256+
<Button
257+
bind:el={createNewTrigger}
258+
kind="ghost"
259+
icon="plus-small"
260+
onclick={() => createNewContextMenu?.toggle()}
261+
>
262+
Create new
263+
</Button>
246264
</div>
247265
</div>
248266

267+
<ContextMenu bind:this={createNewContextMenu} leftClickTrigger={createNewTrigger}>
268+
<ContextMenuSection>
269+
<ContextMenuItem
270+
label="Branch"
271+
onclick={() => {
272+
createBranchModal?.show();
273+
createNewContextMenu?.close();
274+
}}
275+
/>
276+
<ContextMenuItem
277+
label="Codegen session"
278+
onclick={() => {
279+
uiState.project(projectId).exclusiveAction.set({ type: 'codegen' });
280+
createNewContextMenu?.close();
281+
}}
282+
/>
283+
</ContextMenuSection>
284+
</ContextMenu>
285+
286+
<CreateBranchModal bind:this={createBranchModal} {projectId} />
287+
249288
<style>
250289
.chrome-header {
251290
display: flex;

apps/desktop/src/components/CodegenRow.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
}
6464
6565
const handlers = $derived([
66-
new CodegenCommitDropHandler(stackId, branchName, addAttachment),
66+
new CodegenCommitDropHandler(stackId, addAttachment),
6767
new CodegenFileDropHandler(stackId, branchName, addAttachment),
68-
new CodegenHunkDropHandler(stackId, branchName, addAttachment)
68+
new CodegenHunkDropHandler(stackId, addAttachment)
6969
]);
7070
7171
function toggleSelection() {

apps/desktop/src/components/MultiStackView.svelte

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
6262
const projectState = $derived(uiState.project(projectId));
6363
const exclusiveAction = $derived(projectState.exclusiveAction.current);
64-
const isCommitting = $derived(exclusiveAction?.type === 'commit');
6564
const isDraftStackVisible = $derived(
66-
isCommitting && exclusiveAction?.type === 'commit' && exclusiveAction?.stackId === undefined
65+
(exclusiveAction?.type === 'commit' && exclusiveAction.stackId === undefined) ||
66+
exclusiveAction?.type === 'codegen'
6767
);
6868
6969
const SHOW_PAGINATION_THRESHOLD = 1;
@@ -174,7 +174,11 @@
174174
}}
175175
>
176176
<div class="lanes-scrollable">
177-
<StackDraft {projectId} visible={isDraftStackVisible} />
177+
<StackDraft
178+
{projectId}
179+
visible={isDraftStackVisible}
180+
mode={exclusiveAction?.type === 'codegen' ? 'codegen' : 'commit'}
181+
/>
178182

179183
<!--
180184
Ideally we wouldn't key on stack id, but the opacity change is done on the

apps/desktop/src/components/ReduxResult.svelte

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
result: Result<A> | undefined;
2525
children: Snippet<[A, Env<B, C>]>;
2626
loading?: Snippet<[A | undefined]>;
27+
hideError?: boolean;
2728
error?: Snippet<[unknown]>;
2829
empty?: Snippet<[]>;
2930
onerror?: (err: unknown) => void;
@@ -94,16 +95,16 @@
9495
{/snippet}
9596

9697
{#if display.result?.error}
97-
{@const error = display.result.error}
98-
{@render errorComponent(error)}
98+
{#if !props.hideError}
99+
{@const error = display.result.error}
100+
{@render errorComponent(error)}
101+
{/if}
99102
{:else if display.result?.data !== undefined}
100103
{@render props.children(display.result.data, display.env)}
101104
{:else if display.result?.status === 'pending' || display.result?.status === 'uninitialized'}
102105
{@render loadingComponent(display.result.data, display.result.status)}
103106
{:else if display.result?.status === 'fulfilled'}
104107
{@render props.empty?.()}
105-
{:else}
106-
what
107108
{/if}
108109

109110
<style>

0 commit comments

Comments
 (0)