|
1 | 1 | <script lang="ts"> |
2 | | - import { shockersV1Api } from '$lib/api'; |
| 2 | + import { Trash } from '@lucide/svelte'; |
| 3 | + import { shockerSharesV2Api, shockersV1Api } from '$lib/api'; |
3 | 4 | import type { V2UserSharesListItem } from '$lib/api/internal/v2'; |
4 | 5 | import { ComparePermissionsAndLimits } from '$lib/comparers/UserShareComparer'; |
5 | 6 | import LoadingCircle from '$lib/components/svg/LoadingCircle.svelte'; |
|
10 | 11 | import * as Tabs from '$lib/components/ui/tabs'; |
11 | 12 | import MultiPauseToggle from '$lib/components/utils/MultiPauseToggle.svelte'; |
12 | 13 | import PauseToggle from '$lib/components/utils/PauseToggle.svelte'; |
| 14 | + import { handleApiError } from '$lib/errorhandling/apiErrorHandling'; |
| 15 | + import { ConfirmDialogStore, openConfirmDialog } from '$lib/stores/ConfirmDialogStore'; |
13 | 16 | import { UserShares } from '$lib/stores/UserSharesStore'; |
14 | 17 | import { onMount } from 'svelte'; |
15 | 18 | import { toast } from 'svelte-sonner'; |
|
18 | 21 |
|
19 | 22 | interface Props { |
20 | 23 | storeIndex: number; |
| 24 | + sharedWithUserId: string; |
21 | 25 | editDrawer: boolean; |
22 | 26 | } |
23 | 27 |
|
|
148 | 152 | }); |
149 | 153 | } |
150 | 154 |
|
| 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 | +
|
151 | 175 | function onTabChanged(value: string) { |
152 | 176 | isUniformRestrictions = value === 'uniform'; |
153 | 177 | } |
|
161 | 185 | }); |
162 | 186 | } |
163 | 187 | }); |
164 | | -
|
165 | | - function onOpenChange(open: boolean) {} |
166 | 188 | </script> |
167 | 189 |
|
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"> |
169 | 195 | <Drawer.Content> |
170 | 196 | <div class="mx-auto w-full max-h-[100vh] flex flex-col"> |
171 | 197 | <Drawer.Header class="shrink-0"> |
|
244 | 270 | <span> |
245 | 271 | <Badge>{shares[i].name}</Badge> |
246 | 272 | </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; |
257 | 286 | }); |
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> |
262 | 293 | </div> |
263 | 294 | <RestrictionsSelector |
264 | 295 | bind:permissions={shares[i].permissions} |
|
0 commit comments