Skip to content

Commit dd8a82c

Browse files
committed
fix store reactivity
1 parent 1d32743 commit dd8a82c

11 files changed

Lines changed: 261 additions & 86 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"volta": {
7777
"node": "24.7.0"
7878
},
79-
"packageManager": "pnpm@10.5.0",
79+
"packageManager": "pnpm@10.15.1",
8080
"pnpm": {
8181
"onlyBuiltDependencies": [
8282
"@tailwindcss/oxide",

pnpm-lock.yaml

Lines changed: 106 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
<script lang="ts" generics="T">
22
import Button from '$lib/components/ui/button/button.svelte';
33
import * as Dialog from '$lib/components/ui/dialog';
4+
import { LoaderCircle } from '@lucide/svelte';
45
import type { Snippet } from 'svelte';
56
67
interface Props {
78
open: boolean;
89
data: T;
9-
onConfirm: (value: T) => void;
10+
onConfirm: (value: T) => Promise<void> | void;
1011
title: string;
1112
desc?: string;
1213
confirmButtonText: string;
1314
descSnippet?: Snippet<[T]>;
1415
}
1516
1617
let { open = $bindable(), data, onConfirm, title, desc, confirmButtonText, descSnippet }: Props = $props();
18+
let promiseRunning = $state(false);
19+
20+
function click() {
21+
promiseRunning = true;
22+
23+
Promise.resolve(onConfirm(data))
24+
.finally(() => {
25+
open = false;
26+
promiseRunning = false;
27+
});
28+
}
1729
1830
</script>
1931

@@ -28,6 +40,6 @@
2840
{/if}
2941
</Dialog.Description>
3042
</Dialog.Header>
31-
<Button variant="destructive" onclick={() => onConfirm(data)}>{confirmButtonText}</Button>
43+
<Button disabled={promiseRunning} variant="destructive" onclick={click}>{#if promiseRunning}<LoaderCircle class="animate-spin" />{/if}{confirmButtonText}</Button>
3244
</Dialog.Content>
3345
</Dialog.Root>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
let dialogOpen = $state(false);
99
1010
onMount(()=> {
11-
ConfirmDialogStore.subscribe((value) => {
11+
const sub = ConfirmDialogStore.subscribe((value) => {
1212
dialogData = value;
1313
dialogCounter += 1;
1414
dialogOpen = true;
1515
})
16+
return () => sub();
1617
});
1718
1819
</script>

src/lib/stores/UserSharesStore.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { shockerSharesV2Api } from '$lib/api';
2+
import type { ShareInviteBaseDetails, V2UserShares } from '$lib/api/internal/v2';
3+
import { handleApiError } from '$lib/errorhandling/apiErrorHandling';
4+
import { writable } from 'svelte/store';
5+
6+
7+
export const UserShares = writable<V2UserShares>({ outgoing: [], incoming: [] });
8+
export const OutgoingOutstandingInvites = writable<ShareInviteBaseDetails[]>([]);
9+
10+
export async function refreshUserShares() {
11+
try {
12+
UserShares.set(await shockerSharesV2Api.sharesGetSharesByUsers());
13+
} catch (error) {
14+
handleApiError(error);
15+
throw error;
16+
}
17+
}
18+
19+
export async function refreshOutgoingInvites() {
20+
try {
21+
OutgoingOutstandingInvites.set(await shockerSharesV2Api.sharesGetOutgoingInvitesList());
22+
} catch (error) {
23+
handleApiError(error);
24+
throw error;
25+
}
26+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { Code, User } from '@lucide/svelte';
1010
import RestrictionsSelector from './restrictions-selector.svelte';
1111
import UserSelector from './user-selector.svelte';
12+
import { refreshOutgoingInvites } from '$lib/stores/UserSharesStore';
1213
1314
let availableShockers = $derived(
1415
Array.from($OwnHubsStore)
@@ -63,6 +64,7 @@
6364
if (!o) {
6465
shockerIds = [];
6566
restrictions = getDefaultRestrictions();
67+
fetchedUser = null;
6668
}
6769
open = o;
6870
}
@@ -86,6 +88,8 @@
8688
open = false;
8789
} catch (error) {
8890
await handleApiError(error);
91+
} finally {
92+
refreshOutgoingInvites();
8993
}
9094
}
9195
</script>

0 commit comments

Comments
 (0)