|
4 | 4 | import type { BooleanLegacyDataResponse } from '$lib/api/internal/v1'; |
5 | 5 | import { Button } from '$lib/components/ui/button'; |
6 | 6 | import { toast } from 'svelte-sonner'; |
| 7 | +
|
7 | 8 | interface Props { |
8 | 9 | shockers: PauseToggleProps[]; |
9 | 10 | onPausedChange: (paused: boolean) => void; |
|
19 | 20 | let requestInProgress = $state(false); |
20 | 21 |
|
21 | 22 | let pausedBooleans = $derived(() => { |
22 | | - if (shockers.every(item => item.paused)) { |
23 | | - return "allTrue"; |
| 23 | + if (shockers.every((item) => item.paused)) { |
| 24 | + return 'allTrue'; |
24 | 25 | } |
25 | | - if (shockers.every(item => !item.paused)) { |
26 | | - return "allFalse"; |
| 26 | + if (shockers.every((item) => !item.paused)) { |
| 27 | + return 'allFalse'; |
27 | 28 | } |
28 | | - return "mixed"; |
| 29 | + return 'mixed'; |
29 | 30 | }); |
30 | 31 |
|
31 | | -
|
32 | 32 | function handleClick(e: MouseEvent) { |
33 | 33 | e.stopPropagation(); |
34 | | - if(requestInProgress) return; |
| 34 | + if (requestInProgress) return; |
35 | 35 | requestInProgress = true; |
36 | 36 |
|
37 | | - const pause = pausedBooleans() !== "allTrue"; |
| 37 | + const pause = pausedBooleans() !== 'allTrue'; |
38 | 38 |
|
39 | 39 | let pauseRequests: Promise<void>[] = []; |
40 | 40 |
|
|
57 | 57 | let pauseRequest: Promise<BooleanLegacyDataResponse>; |
58 | 58 |
|
59 | 59 | if (shocker.userShareUserId) { |
60 | | - pauseRequest = shockersV1Api.shockerShockerShareCodePause(shocker.shockerId, shocker.userShareUserId, { |
61 | | - pause: pause |
62 | | - }); |
| 60 | + pauseRequest = shockersV1Api.shockerShockerShareCodePause( |
| 61 | + shocker.shockerId, |
| 62 | + shocker.userShareUserId, |
| 63 | + { |
| 64 | + pause: pause, |
| 65 | + } |
| 66 | + ); |
63 | 67 | } else { |
64 | 68 | pauseRequest = shockersV1Api.shockerPauseShocker(shocker.shockerId, { pause: pause }); |
65 | 69 | } |
66 | 70 |
|
67 | | - pauseRequest.then((newPausedState) => { |
68 | | - shocker.paused = newPausedState.data; |
69 | | - }).catch((error) => { |
70 | | - toast.error(`Failed to set shocker pause state`); |
71 | | - console.error(error); |
72 | | - }); |
| 71 | + pauseRequest |
| 72 | + .then((newPausedState) => { |
| 73 | + shocker.paused = newPausedState.data; |
| 74 | + }) |
| 75 | + .catch((error) => { |
| 76 | + toast.error(`Failed to set shocker pause state`); |
| 77 | + console.error(error); |
| 78 | + }); |
73 | 79 |
|
74 | 80 | await pauseRequest; |
75 | 81 | } |
76 | | -
|
77 | 82 | </script> |
78 | 83 |
|
79 | | -<Button disabled={requestInProgress} onclick={handleClick} class="size-9" variant={pausedBooleans() === 'allTrue' ? 'destructive' : 'default'}> |
| 84 | +<Button |
| 85 | + disabled={requestInProgress} |
| 86 | + onclick={handleClick} |
| 87 | + class="size-9" |
| 88 | + variant={pausedBooleans() === 'allTrue' ? 'destructive' : 'default'} |
| 89 | +> |
80 | 90 | {#if requestInProgress} |
81 | 91 | <LoaderCircle class="animate-spin" /> |
82 | | - {:else if pausedBooleans() === "allTrue"} |
| 92 | + {:else if pausedBooleans() === 'allTrue'} |
83 | 93 | <Play /> |
84 | | - {:else if pausedBooleans() === "allFalse"} |
| 94 | + {:else if pausedBooleans() === 'allFalse'} |
85 | 95 | <Pause /> |
86 | | - {:else if pausedBooleans() === "mixed"} |
| 96 | + {:else if pausedBooleans() === 'mixed'} |
87 | 97 | <Asterisk /> |
88 | 98 | {/if} |
89 | 99 | </Button> |
0 commit comments