Skip to content

Commit 6a19465

Browse files
committed
create share code dialog
1 parent 1a70556 commit 6a19465

8 files changed

Lines changed: 77 additions & 21 deletions

src/routes/(authenticated)/shares/user/+page.svelte

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
import type { V2UserShares, V2UserSharesListItem } from '$lib/api/internal/v2';
44
import * as Table from '$lib/components/ui/table';
55
import { onMount } from 'svelte';
6-
import UserShareItem from './UserShareItem.svelte';
6+
import UserShareItem from './user-share-item.svelte';
77
import { Button } from '$lib/components/ui/button';
88
import { Plus, RectangleEllipsis, User } from '@lucide/svelte';
99
import * as DropdownMenu from '$lib/components/ui/dropdown-menu';
1010
import DialogShareCodeCreate from './dialog-share-code-create.svelte';
1111
import { OwnHubsStore, refreshOwnHubs } from '$lib/stores/HubsStore';
1212
import EditShare from './edit-share.svelte';
13+
import DialogShareCodeCreated from './dialog-share-code-created.svelte';
1314
1415
let createDialogOpen = $state(false);
1516
let userShares = $state<V2UserShares>({ outgoing: [], incoming: [] });
1617
let editShareDrawerOpen = $state(false);
1718
let editShareDrawerOpenCount = $state(0);
1819
let editIndex = $state(0);
1920
21+
let createdCode = $state<string | null>(null);
22+
2023
function refreshUserShares() {
2124
shockerSharesV2Api
2225
.sharesGetSharesByUsers()
@@ -28,6 +31,11 @@
2831
});
2932
}
3033
34+
function onCreatedCode(code: string) {
35+
createdCode = code;
36+
refreshUserShares();
37+
}
38+
3139
onMount(() => {
3240
refreshUserShares()
3341
refreshOwnHubs()
@@ -40,7 +48,8 @@
4048
}
4149
</script>
4250

43-
<DialogShareCodeCreate bind:open={createDialogOpen} onCreated={refreshUserShares} />
51+
<DialogShareCodeCreate bind:open={createDialogOpen} onCreated={onCreatedCode} />
52+
<DialogShareCodeCreated bind:code={createdCode} />
4453

4554
{#key editShareDrawerOpenCount}
4655
{#if userShares.outgoing[editIndex] !== undefined}

src/routes/(authenticated)/shares/user/dialog-share-code-create.svelte

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import MultiSelectCombobox from '$lib/components/ui/multi-select-combobox/multi-select-combobox.svelte';
77
import { handleApiError } from '$lib/errorhandling/apiErrorHandling';
88
import { OwnHubsStore } from '$lib/stores/HubsStore';
9+
import RestrictionsSelector from './restrictions-selector.svelte';
910
1011
let availableShockers = $derived(
1112
Array.from($OwnHubsStore)
@@ -23,20 +24,33 @@
2324
2425
let { open = $bindable(), onCreated }: Props = $props();
2526
27+
interface ShockerPermLimitPairButNotNull {
28+
permissions: {
29+
shock: boolean;
30+
vibrate: boolean;
31+
sound: boolean;
32+
live: boolean;
33+
};
34+
limits: {
35+
intensity: number;
36+
duration: number;
37+
};
38+
}
39+
2640
let shockerIds = $state<string[]>([]);
27-
let restrictions = $state<ShockerPermLimitPair>(getDefaultRestrictions());
41+
let restrictions = $state<ShockerPermLimitPairButNotNull>(getDefaultRestrictions());
2842
29-
function getDefaultRestrictions(): ShockerPermLimitPair {
43+
function getDefaultRestrictions(): ShockerPermLimitPairButNotNull {
3044
return {
3145
limits: {
32-
duration: 30_000,
33-
intensity: 100,
46+
duration: 10_000,
47+
intensity: 25,
3448
},
3549
permissions: {
36-
shock: false,
37-
vibrate: false,
38-
sound: false,
39-
live: false,
50+
shock: true,
51+
vibrate: true,
52+
sound: true,
53+
live: true,
4054
},
4155
};
4256
}
@@ -53,10 +67,10 @@
5367
try {
5468
const createdCode = await shockerSharesV2Api.sharesCreateShareInvite({
5569
shockers: shockerIds.map((id) => ({
56-
shockerId: id,
57-
permissions: restrictions.permissions,
58-
limits: restrictions.limits,
59-
})),
70+
id: id,
71+
permissions: { ...restrictions.permissions },
72+
limits: { ...restrictions.limits },
73+
}))
6074
});
6175
onCreated(createdCode);
6276
open = false;
@@ -81,6 +95,8 @@
8195
placeholder="Select shockers to share..."
8296
noMatchText="Not matching shockers"
8397
></MultiSelectCombobox>
98+
99+
<RestrictionsSelector bind:permissions={restrictions.permissions} bind:limits={restrictions.limits} />
84100
</form>
85101
<Button onclick={onFormSubmit}>Create</Button>
86102
</Dialog.Content>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script lang="ts">
2+
import KeyRound from '@lucide/svelte/icons/key-round';
3+
import CopyInput from '$lib/components/CopyInput.svelte';
4+
import * as Dialog from '$lib/components/ui/dialog';
5+
6+
interface Props {
7+
code: string | null;
8+
}
9+
10+
let { code = $bindable() }: Props = $props();
11+
12+
function onOpenChanged(open: boolean) {
13+
if (!open) {
14+
code = null;
15+
}
16+
}
17+
</script>
18+
19+
<Dialog.Root bind:open={() => code !== null, onOpenChanged}>
20+
<Dialog.Content>
21+
<Dialog.Header>
22+
<Dialog.Title>Share Code Generated</Dialog.Title>
23+
<Dialog.Description>
24+
Please copy share code!
25+
</Dialog.Description>
26+
</Dialog.Header>
27+
<div class="flex flex-col items-center space-y-4">
28+
<div class="flex w-full items-center justify-between rounded-md p-2">
29+
<CopyInput value={code!}>
30+
{#snippet icon()}
31+
<KeyRound size="20" />
32+
{/snippet}
33+
</CopyInput>
34+
</div>
35+
</div>
36+
</Dialog.Content>
37+
</Dialog.Root>

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts">
2-
import { Volume2, Waves, Zap } from '@lucide/svelte';
32
import { shockersV1Api } from '$lib/api';
43
import type { V2UserSharesListItem } from '$lib/api/internal/v2';
54
import { ComparePermissionsAndLimits } from '$lib/comparers/UserShareComparer';
@@ -8,14 +7,11 @@
87
import { Badge } from '$lib/components/ui/badge';
98
import { Button } from '$lib/components/ui/button';
109
import * as Drawer from '$lib/components/ui/drawer';
11-
import Label from '$lib/components/ui/label/label.svelte';
12-
import Slider from '$lib/components/ui/slider/slider.svelte';
1310
import * as Tabs from '$lib/components/ui/tabs';
1411
import MultiPauseToggle from '$lib/components/utils/MultiPauseToggle.svelte';
1512
import PauseToggle from '$lib/components/utils/PauseToggle.svelte';
1613
import { onMount } from 'svelte';
1714
import { toast } from 'svelte-sonner';
18-
import PermissionSwitch from './PermissionSwitch.svelte';
1915
import RestrictionsSelector from './restrictions-selector.svelte';
2016
2117
interface Props {

src/routes/(authenticated)/shares/user/PermissionSwitch.svelte renamed to src/routes/(authenticated)/shares/user/permission-switch.svelte

File renamed without changes.

src/routes/(authenticated)/shares/user/restrictions-selector.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import { ChartNoAxesGantt, Volume2, Waves, Zap } from '@lucide/svelte';
33
import Label from '$lib/components/ui/label/label.svelte';
44
import { Slider } from '$lib/components/ui/slider';
5-
import MultiPauseToggle from '$lib/components/utils/MultiPauseToggle.svelte';
6-
import PermissionSwitch from './PermissionSwitch.svelte';
5+
import PermissionSwitch from './permission-switch.svelte';
76
87
interface Props {
98
permissions: {

src/routes/(authenticated)/shares/user/user-selector.svelte

Whitespace-only changes.

src/routes/(authenticated)/shares/user/UserShareItem.svelte renamed to src/routes/(authenticated)/shares/user/user-share-item.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import * as Tooltip from '$lib/components/ui/tooltip';
99
import MultiPauseToggle from '$lib/components/utils/MultiPauseToggle.svelte';
1010
import { Zap } from '@lucide/svelte';
11-
import EditShare from './edit-share.svelte';
1211
1312
interface Props {
1413
userShare: V2UserSharesListItem;

0 commit comments

Comments
 (0)