Skip to content

Commit 0f48b53

Browse files
authored
feat: add <form /> to Modal implementation (#4780)
1 parent b03ba56 commit 0f48b53

File tree

12 files changed

+134
-146
lines changed

12 files changed

+134
-146
lines changed

apps/desktop/src/lib/branch/BranchLaneContextMenu.svelte

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -166,39 +166,36 @@
166166
</ContextMenuSection>
167167
</ContextMenu>
168168

169-
<Modal width="small" bind:this={renameRemoteModal}>
169+
<Modal
170+
width="small"
171+
bind:this={renameRemoteModal}
172+
onSubmit={(close) => {
173+
branchController.updateBranchRemoteName(branch.id, newRemoteName);
174+
close();
175+
}}
176+
>
170177
<TextBox label="Remote branch name" id="newRemoteName" bind:value={newRemoteName} focus />
171178

172179
{#snippet controls(close)}
173180
<Button style="ghost" outline type="reset" onclick={close}>Cancel</Button>
174-
<Button
175-
style="pop"
176-
kind="solid"
177-
onclick={() => {
178-
branchController.updateBranchRemoteName(branch.id, newRemoteName);
179-
close();
180-
}}
181-
>
182-
Rename
183-
</Button>
181+
<Button style="pop" kind="solid" type="submit">Rename</Button>
184182
{/snippet}
185183
</Modal>
186184

187-
<Modal width="small" title="Delete branch" bind:this={deleteBranchModal}>
185+
<Modal
186+
width="small"
187+
title="Delete branch"
188+
bind:this={deleteBranchModal}
189+
onSubmit={async (close) => {
190+
await branchController.deleteBranch(branch.id);
191+
close();
192+
}}
193+
>
188194
{#snippet children(branch)}
189195
Are you sure you want to delete <code class="code-string">{branch.name}</code>?
190196
{/snippet}
191197
{#snippet controls(close)}
192198
<Button style="ghost" outline onclick={close}>Cancel</Button>
193-
<Button
194-
style="error"
195-
kind="solid"
196-
onclick={async () => {
197-
await branchController.deleteBranch(branch.id);
198-
close();
199-
}}
200-
>
201-
Delete
202-
</Button>
199+
<Button style="error" kind="solid" type="submit">Delete</Button>
203200
{/snippet}
204201
</Modal>

apps/desktop/src/lib/branch/BranchPreviewHeader.svelte

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -139,31 +139,30 @@
139139
<div class="header__top-overlay" data-tauri-drag-region></div>
140140
</div>
141141

142-
<Modal width="small" title="Delete branch" bind:this={deleteBranchModal}>
142+
<Modal
143+
width="small"
144+
title="Delete branch"
145+
bind:this={deleteBranchModal}
146+
onSubmit={async (close) => {
147+
try {
148+
await branchController.deleteLocalBranch(branch.name, branch.givenName);
149+
} catch (e) {
150+
const err = 'Failed to delete local branch';
151+
error(err);
152+
console.error(err, e);
153+
} finally {
154+
isDeleting = false;
155+
close();
156+
}
157+
goto(`/${project.id}/board`);
158+
}}
159+
>
143160
{#snippet children(branch)}
144161
Are you sure you want to delete <code class="code-string">{branch.name}</code>?
145162
{/snippet}
146163
{#snippet controls(close)}
147164
<Button style="ghost" outline onclick={close}>Cancel</Button>
148-
<Button
149-
style="error"
150-
kind="solid"
151-
onclick={async () => {
152-
try {
153-
await branchController.deleteLocalBranch(branch.name, branch.givenName);
154-
} catch (e) {
155-
const err = 'Failed to delete local branch';
156-
error(err);
157-
console.error(err, e);
158-
} finally {
159-
isDeleting = false;
160-
close();
161-
}
162-
goto(`/${project.id}/board`);
163-
}}
164-
>
165-
Delete
166-
</Button>
165+
<Button style="error" type="submit" kind="solid">Delete</Button>
167166
{/snippet}
168167
</Modal>
169168

apps/desktop/src/lib/commit/CommitCard.svelte

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,15 @@
154154
$: conflicted = commit instanceof DetailedCommit && commit.conflicted;
155155
</script>
156156

157-
<Modal bind:this={commitMessageModal} width="small">
157+
<Modal bind:this={commitMessageModal} width="small" onSubmit={submitCommitMessageModal}>
158158
<CommitMessageInput
159159
bind:commitMessage={description}
160160
bind:valid={commitMessageValid}
161161
isExpanded={true}
162162
/>
163163
{#snippet controls(close)}
164164
<Button style="ghost" outline onclick={close}>Cancel</Button>
165-
<Button
166-
style="neutral"
167-
kind="solid"
168-
grow
169-
disabled={!commitMessageValid}
170-
onclick={submitCommitMessageModal}
171-
>
165+
<Button style="neutral" type="submit" kind="solid" grow disabled={!commitMessageValid}>
172166
Submit
173167
</Button>
174168
{/snippet}

apps/desktop/src/lib/components/BaseBranch.svelte

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,18 @@
9696
</div>
9797
</div>
9898

99-
<Modal width="small" bind:this={updateTargetModal} title="Merge Upstream Work">
99+
<Modal
100+
width="small"
101+
bind:this={updateTargetModal}
102+
title="Merge Upstream Work"
103+
onSubmit={(close) => {
104+
updateBaseBranch();
105+
if (mergeUpstreamWarningDismissedCheckbox) {
106+
mergeUpstreamWarningDismissed.set(true);
107+
}
108+
close();
109+
}}
110+
>
100111
<div class="modal-content">
101112
<p class="text-14 text-body">You are about to merge upstream work from your base branch.</p>
102113
</div>
@@ -122,19 +133,7 @@
122133

123134
{#snippet controls(close)}
124135
<Button style="ghost" outline onclick={close}>Cancel</Button>
125-
<Button
126-
style="pop"
127-
kind="solid"
128-
onclick={() => {
129-
updateBaseBranch();
130-
if (mergeUpstreamWarningDismissedCheckbox) {
131-
mergeUpstreamWarningDismissed.set(true);
132-
}
133-
close();
134-
}}
135-
>
136-
Merge Upstream
137-
</Button>
136+
<Button style="pop" kind="solid" type="submit">Merge Upstream</Button>
138137
{/snippet}
139138
</Modal>
140139

apps/desktop/src/lib/components/PromptModal.svelte

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
bind:this={modal}
5555
width="small"
5656
title="Git fetch requires input"
57-
onclose={async () => await cancel()}
57+
onClose={async () => await cancel()}
58+
onSubmit={async () => await submit()}
5859
>
5960
<div class="message">
6061
{#if $error}
@@ -66,15 +67,8 @@
6667
<TextBox focus type="password" bind:value disabled={!!$error || loading} />
6768

6869
{#snippet controls()}
69-
<Button style="ghost" outline type="reset" disabled={loading} onclick={cancel}>Cancel</Button>
70-
<Button
71-
style="pop"
72-
kind="solid"
73-
grow
74-
disabled={!!$error || loading}
75-
{loading}
76-
onclick={async () => await submit()}
77-
>
70+
<Button style="ghost" type="reset" outline disabled={loading} onclick={cancel}>Cancel</Button>
71+
<Button style="pop" type="submit" kind="solid" grow disabled={!!$error || loading} {loading}>
7872
Submit
7973
</Button>
8074
{/snippet}

apps/desktop/src/lib/components/PullRequestPreview.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@
8383
}
8484
</script>
8585

86-
<Modal width="small" bind:this={createRemoteModal}>
86+
<Modal width="small" bind:this={createRemoteModal} onSubmit={createRemoteAndBranch}>
8787
<p class="text-15 fork-notice">
8888
In order to apply a branch from a fork, GitButler must first add a remote.
8989
</p>
9090
<TextBox label="Choose a remote name" bind:value={remoteName}></TextBox>
9191
{#snippet controls(close)}
9292
<Button style="ghost" outline onclick={() => closeModal(close)}>Cancel</Button>
93-
<Button style="pop" kind="solid" grow onclick={createRemoteAndBranch} {loading}>Confirm</Button>
93+
<Button style="pop" kind="solid" type="submit" grow {loading}>Confirm</Button>
9494
{/snippet}
9595
</Modal>
9696

apps/desktop/src/lib/components/RemoveProjectButton.svelte

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@
2828
Remove project…
2929
</Button>
3030

31-
<Modal bind:this={modal} width="small">
31+
<Modal
32+
bind:this={modal}
33+
width="small"
34+
onSubmit={(close) => {
35+
onDeleteClicked().then(close);
36+
}}
37+
>
3238
<div class="remove-project-description">
3339
<p class="text-14 text-body">
3440
Are you sure you want to remove
@@ -41,16 +47,14 @@
4147
</p>
4248
</div>
4349

44-
{#snippet controls(close)}
50+
{#snippet controls()}
4551
<Button
4652
style="error"
4753
kind="solid"
4854
reversedDirection
4955
loading={isDeleting}
5056
icon="bin-small"
51-
onclick={() => {
52-
onDeleteClicked().then(close);
53-
}}
57+
type="submit"
5458
>
5559
Remove
5660
</Button>

apps/desktop/src/lib/components/ShareIssueModal.svelte

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@
155155
});
156156
</script>
157157

158-
<Modal bind:this={modal} title="Share debug data with GitButler team for review">
158+
<Modal
159+
bind:this={modal}
160+
title="Share debug data with GitButler team for review"
161+
onSubmit={async () => await submit()}
162+
>
159163
<div class="content-wrapper">
160164
<p class="content-wrapper__help-text text-13 text-body">
161165
If you are having trouble, please share your project and logs with the GitButler team. We will
@@ -172,6 +176,7 @@
172176
autocomplete={false}
173177
autocorrect={false}
174178
spellcheck
179+
focus
175180
/>
176181
{/if}
177182

@@ -216,11 +221,9 @@
216221
</div>
217222

218223
<!-- Use our own close function -->
219-
{#snippet controls(_close)}
224+
{#snippet controls()}
220225
<Button style="ghost" outline type="reset" onclick={close}>Close</Button>
221-
<Button style="pop" kind="solid" type="submit" onclick={async () => await submit()}>
222-
Share with GitButler
223-
</Button>
226+
<Button style="pop" kind="solid" type="submit">Share with GitButler</Button>
224227
{/snippet}
225228
</Modal>
226229

apps/desktop/src/lib/select/Select.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import TextBox from '../shared/TextBox.svelte';
1414
import { KeyName } from '$lib/utils/hotkeys';
1515
import { resizeObserver } from '$lib/utils/resizeObserver';
16-
import { portal } from '@gitbutler/ui/utils/portal';
1716
import { type Snippet } from 'svelte';
1817
1918
interface SelectProps {
@@ -168,7 +167,6 @@
168167
role="presentation"
169168
class="overlay-wrapper"
170169
onclick={clickOutside}
171-
use:portal={'body'}
172170
use:resizeObserver={() => {
173171
getInputBoundingRect();
174172
setMaxHeight();

apps/desktop/src/lib/settings/GithubIntegration.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
bind:this={gitHubOauthModal}
127127
width="small"
128128
title="Authorize with GitHub"
129-
onclose={() => {
129+
onClose={() => {
130130
codeCopied = false;
131131
GhActivationLinkPressed = false;
132132
GhActivationPageOpened = false;

0 commit comments

Comments
 (0)