Skip to content

Commit acd5ac8

Browse files
Merge pull request #6001 from gitbutlerapp/disabling-gitbutler-cloud
Add button for disabling cloud functionality
2 parents 3775266 + 4ab57e5 commit acd5ac8

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

apps/desktop/src/components/CloudProjectSettings.svelte

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
import { RepositoryIdLookupService } from '@gitbutler/shared/organizations/repositoryIdLookupService';
1717
import { AppState } from '@gitbutler/shared/redux/store.svelte';
1818
import { WebRoutesService } from '@gitbutler/shared/routing/webRoutes';
19-
import Button from '@gitbutler/ui/Button.svelte';
19+
import AsyncButton from '@gitbutler/ui/AsyncButton.svelte';
2020
import SectionCard from '@gitbutler/ui/SectionCard.svelte';
2121
import Toggle from '@gitbutler/ui/Toggle.svelte';
22+
import type { Project as BackendProject } from '$lib/project/project';
2223
import type { Project } from '@gitbutler/shared/organizations/types';
2324
2425
const appState = getContext(AppState);
@@ -94,6 +95,17 @@
9495
await projectsService.updateProject(mutableProject);
9596
}
9697
98+
async function detachProject() {
99+
if (!$project) {
100+
return;
101+
}
102+
103+
const mutableProject: BackendProject & { unset_api?: boolean } = structuredClone($project);
104+
mutableProject.api = undefined;
105+
mutableProject.unset_api = true;
106+
await projectsService.updateProject(mutableProject);
107+
}
108+
97109
async function onSyncChange(sync: boolean) {
98110
if (!$project?.api) return;
99111
@@ -199,9 +211,13 @@
199211
{/if}
200212
{/snippet}
201213
</Loading>
214+
215+
<div>
216+
<AsyncButton kind="outline" action={detachProject}>Disable cloud functionality</AsyncButton>
217+
</div>
202218
{:else if !$project?.api?.repository_id}
203219
<Section>
204-
<Button onclick={createProject}>Enable cloud functionality</Button>
220+
<AsyncButton action={createProject}>Enable cloud functionality</AsyncButton>
205221
</Section>
206222
{:else}
207223
<p>Loading...</p>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<script lang="ts">
2+
import Button from '$lib/Button.svelte';
3+
import type { TooltipPosition, TooltipAlign } from '$lib/Tooltip.svelte';
4+
import type iconsJson from '$lib/data/icons.json';
5+
import type { ComponentColorType, ComponentKindType } from '$lib/utils/colorTypes';
6+
import type { Snippet } from 'svelte';
7+
8+
type ButtonPropsSubset = {
9+
id?: string | undefined;
10+
el?: HTMLElement;
11+
// Interaction props
12+
disabled?: boolean;
13+
activated?: boolean;
14+
tabindex?: number | undefined;
15+
type?: 'submit' | 'reset' | 'button' | undefined;
16+
// Layout props
17+
shrinkable?: boolean;
18+
reversedDirection?: boolean;
19+
width?: number | undefined;
20+
maxWidth?: number | undefined;
21+
size?: 'tag' | 'button' | 'cta';
22+
wide?: boolean;
23+
grow?: boolean;
24+
align?: 'flex-start' | 'center' | 'flex-end' | 'stretch' | 'baseline' | 'auto';
25+
dropdownChild?: boolean;
26+
// Style props
27+
style?: ComponentColorType;
28+
kind?: ComponentKindType;
29+
solidBackground?: boolean;
30+
// Additional elements
31+
icon?: keyof typeof iconsJson | undefined;
32+
tooltip?: string;
33+
tooltipPosition?: TooltipPosition;
34+
tooltipAlign?: TooltipAlign;
35+
helpShowDelay?: number;
36+
testId?: string;
37+
// Snippets
38+
children?: Snippet;
39+
};
40+
41+
type Props = ButtonPropsSubset & { action: () => Promise<void> };
42+
const { action, ...rest }: Props = $props();
43+
44+
let state = $state<'inert' | 'loading' | 'complete'>('inert');
45+
46+
async function performAction() {
47+
state = 'loading';
48+
49+
try {
50+
await action();
51+
} finally {
52+
state = 'complete';
53+
}
54+
}
55+
</script>
56+
57+
<Button onclick={performAction} {...rest}></Button>

0 commit comments

Comments
 (0)