blob: afdcbe4592a92848e4ae90a7c3d610d35930916a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<script>
import LogOut from '$lib/components/LogOut.svelte';
import Invites from '$lib/components/Invites.svelte';
import ChangePassword from '$lib/components/ChangePassword.svelte';
import PushSubscription from '$lib/components/PushSubscription.svelte';
import { goto } from '$app/navigation';
import * as api from '$lib/apiServer.js';
const { data } = $props();
const { session } = data;
const subscription = $derived(session.push.subscription);
const vapid = $derived(session.push.vapidKey);
let invites = $state([]);
async function logOut() {
const response = await api.logOut();
if (200 <= response.status && response.status < 300) {
await session.push.unsubscribe();
await goto('/login');
}
}
async function changePassword(currentPassword, newPassword) {
await api.changePassword(currentPassword, newPassword);
await session.push.unsubscribe();
await session.push.resubscribe();
}
async function createInvite() {
let response = await api.createInvite();
if (response.status === 200) {
invites.push(response.data);
}
}
async function subscribe() {
await session.push.subscribe();
}
async function ping() {
await api.sendPing();
}
</script>
<ChangePassword {changePassword} />
<hr />
<PushSubscription {subscription} {vapid} {subscribe} {ping} />
<hr />
<Invites {invites} {createInvite} />
<hr />
<LogOut {logOut} />
|