Skip to content

Commit 7f09f09

Browse files
committed
Add share remove button
1 parent 90cbb23 commit 7f09f09

3 files changed

Lines changed: 51 additions & 20 deletions

File tree

src/lib/components/confirm-dialog/dialog-confirm.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
{/if}
4141
</Dialog.Description>
4242
</Dialog.Header>
43-
<Button disabled={promiseRunning} variant="destructive" onclick={click}>{#if promiseRunning}<LoaderCircle class="animate-spin" />{/if}{confirmButtonText}</Button>
43+
<Button disabled={promiseRunning} variant="destructive" onclick={click}>{#if promiseRunning}<LoaderCircle class="animate-spin" />{/if}{confirmButtonText ? confirmButtonText : 'Confirm'}</Button>
4444
</Dialog.Content>
4545
</Dialog.Root>

src/lib/stores/ConfirmDialogStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface ConfirmDialogContext<T> {
66
onConfirm: (value: T) => void;
77
title: string;
88
desc?: string;
9-
confirmButtonText: string;
9+
confirmButtonText?: string;
1010
descSnippet?: Snippet<[T]>;
1111
}
1212

src/routes/(authenticated)/shares/user/outgoing/edit-share.svelte

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
2-
import { shockersV1Api } from '$lib/api';
2+
import { Trash } from '@lucide/svelte';
3+
import { shockerSharesV2Api, shockersV1Api } from '$lib/api';
34
import type { V2UserSharesListItem } from '$lib/api/internal/v2';
45
import { ComparePermissionsAndLimits } from '$lib/comparers/UserShareComparer';
56
import LoadingCircle from '$lib/components/svg/LoadingCircle.svelte';
@@ -10,6 +11,8 @@
1011
import * as Tabs from '$lib/components/ui/tabs';
1112
import MultiPauseToggle from '$lib/components/utils/MultiPauseToggle.svelte';
1213
import PauseToggle from '$lib/components/utils/PauseToggle.svelte';
14+
import { handleApiError } from '$lib/errorhandling/apiErrorHandling';
15+
import { ConfirmDialogStore, openConfirmDialog } from '$lib/stores/ConfirmDialogStore';
1316
import { UserShares } from '$lib/stores/UserSharesStore';
1417
import { onMount } from 'svelte';
1518
import { toast } from 'svelte-sonner';
@@ -18,6 +21,7 @@
1821
1922
interface Props {
2023
storeIndex: number;
24+
sharedWithUserId: string;
2125
editDrawer: boolean;
2226
}
2327
@@ -148,6 +152,26 @@
148152
});
149153
}
150154
155+
async function deleteShockerShare(shockerId: EditableShare) {
156+
try {
157+
await shockersV1Api.shockerShockerShareCodeRemove(shockerId.id, $userShare.id);
158+
toast.success(`Successfully removed shocker share ${shockerId}`);
159+
} catch (error) {
160+
handleApiError(error);
161+
throw error;
162+
}
163+
}
164+
165+
function handleDeleteClick(shocker: EditableShare) {
166+
openConfirmDialog({
167+
title: 'Confirm Deletion',
168+
descSnippet: deleteConfirmDesc,
169+
data: shocker,
170+
onConfirm: deleteShockerShare,
171+
confirmButtonText: 'Remove'
172+
});
173+
}
174+
151175
function onTabChanged(value: string) {
152176
isUniformRestrictions = value === 'uniform';
153177
}
@@ -161,11 +185,13 @@
161185
});
162186
}
163187
});
164-
165-
function onOpenChange(open: boolean) {}
166188
</script>
167189

168-
<Drawer.Root bind:open={editDrawer} {onOpenChange} direction="right">
190+
{#snippet deleteConfirmDesc (shocker: EditableShare)}
191+
<p>Are you sure you want to remove the shocker share <strong>{shocker.name}</strong> for <strong>{$userShare.name}</strong>?</p>
192+
{/snippet}
193+
194+
<Drawer.Root bind:open={editDrawer} direction="right">
169195
<Drawer.Content>
170196
<div class="mx-auto w-full max-h-[100vh] flex flex-col">
171197
<Drawer.Header class="shrink-0">
@@ -244,21 +270,26 @@
244270
<span>
245271
<Badge>{shares[i].name}</Badge>
246272
</span>
247-
<PauseToggle
248-
shockerId={shares[i].id}
249-
bind:paused={shares[i].paused}
250-
userShareUserId={$userShare.id}
251-
onPausedChange={(paused) => {
252-
UserShares.update((current) => {
253-
current.outgoing[storeIndex].shares.forEach((s) => {
254-
if (s.id === share.id) {
255-
s.paused = paused; // Update the store shares list
256-
}
273+
<span>
274+
<PauseToggle
275+
shockerId={shares[i].id}
276+
bind:paused={shares[i].paused}
277+
userShareUserId={$userShare.id}
278+
onPausedChange={(paused) => {
279+
UserShares.update((current) => {
280+
current.outgoing[storeIndex].shares.forEach((s) => {
281+
if (s.id === share.id) {
282+
s.paused = paused; // Update the store shares list
283+
}
284+
});
285+
return current;
257286
});
258-
return current;
259-
});
260-
}}
261-
/>
287+
}}
288+
/>
289+
<Button variant="destructive" onclick={() => handleDeleteClick(shares[i])} class="ml-4">
290+
<Trash />
291+
</Button>
292+
</span>
262293
</div>
263294
<RestrictionsSelector
264295
bind:permissions={shares[i].permissions}

0 commit comments

Comments
 (0)