|
1 | 1 | <script lang="ts">
|
2 |
| - import { goto } from "$app/navigation"; |
3 |
| - import { Hero, IdentityCard } from "$lib/fragments"; |
4 |
| - import type { GlobalState } from "$lib/global"; |
5 |
| - import { Drawer } from "$lib/ui"; |
6 |
| - import * as Button from "$lib/ui/Button"; |
7 |
| - import { QrCodeIcon, Settings02Icon } from "@hugeicons/core-free-icons"; |
8 |
| - import { HugeiconsIcon } from "@hugeicons/svelte"; |
9 |
| - import { type Snippet, getContext, onMount } from "svelte"; |
10 |
| - import { onDestroy } from "svelte"; |
11 |
| - import { Shadow } from "svelte-loading-spinners"; |
12 |
| - import QrCode from "svelte-qrcode"; |
13 |
| -
|
14 |
| - let userData: Record<string, unknown> | undefined = $state(undefined); |
15 |
| - let greeting: string | undefined = $state(undefined); |
16 |
| - let ename: string | undefined = $state(undefined); |
17 |
| - let profileCreationStatus: "idle" | "loading" | "success" | "failed" = |
18 |
| - $state("idle"); |
19 |
| -
|
20 |
| - let shareQRdrawerOpen = $state(false); |
21 |
| - let statusInterval: ReturnType<typeof setInterval> | undefined = |
22 |
| - $state(undefined); |
23 |
| -
|
24 |
| - function shareQR() { |
25 |
| - alert("QR Code shared!"); |
26 |
| - shareQRdrawerOpen = false; |
| 2 | +import { goto } from "$app/navigation"; |
| 3 | +import { Hero, IdentityCard } from "$lib/fragments"; |
| 4 | +import type { GlobalState } from "$lib/global"; |
| 5 | +import { Drawer } from "$lib/ui"; |
| 6 | +import * as Button from "$lib/ui/Button"; |
| 7 | +import { QrCodeIcon, Settings02Icon } from "@hugeicons/core-free-icons"; |
| 8 | +import { HugeiconsIcon } from "@hugeicons/svelte"; |
| 9 | +import { type Snippet, getContext, onMount } from "svelte"; |
| 10 | +import { onDestroy } from "svelte"; |
| 11 | +import { Shadow } from "svelte-loading-spinners"; |
| 12 | +import QrCode from "svelte-qrcode"; |
| 13 | +
|
| 14 | +let userData: Record<string, unknown> | undefined = $state(undefined); |
| 15 | +let greeting: string | undefined = $state(undefined); |
| 16 | +let ename: string | undefined = $state(undefined); |
| 17 | +let profileCreationStatus: "idle" | "loading" | "success" | "failed" = |
| 18 | + $state("idle"); |
| 19 | +
|
| 20 | +let shareQRdrawerOpen = $state(false); |
| 21 | +let statusInterval: ReturnType<typeof setInterval> | undefined = |
| 22 | + $state(undefined); |
| 23 | +
|
| 24 | +function shareQR() { |
| 25 | + alert("QR Code shared!"); |
| 26 | + shareQRdrawerOpen = false; |
| 27 | +} |
| 28 | +
|
| 29 | +async function retryProfileCreation() { |
| 30 | + try { |
| 31 | + await globalState.vaultController.retryProfileCreation(); |
| 32 | + } catch (error) { |
| 33 | + console.error("Retry failed:", error); |
27 | 34 | }
|
| 35 | +} |
28 | 36 |
|
29 |
| - async function retryProfileCreation() { |
30 |
| - try { |
31 |
| - await globalState.vaultController.retryProfileCreation(); |
32 |
| - } catch (error) { |
33 |
| - console.error("Retry failed:", error); |
34 |
| - } |
35 |
| - } |
| 37 | +const globalState = getContext<() => GlobalState>("globalState")(); |
36 | 38 |
|
37 |
| - const globalState = getContext<() => GlobalState>("globalState")(); |
| 39 | +onMount(() => { |
| 40 | + // Load initial data |
| 41 | + (async () => { |
| 42 | + const userInfo = await globalState.userController.user; |
| 43 | + const isFake = await globalState.userController.isFake; |
| 44 | + userData = { ...userInfo, isFake }; |
| 45 | + const vaultData = await globalState.vaultController.vault; |
| 46 | + ename = vaultData?.ename; |
| 47 | + })(); |
38 | 48 |
|
39 |
| - onMount(() => { |
40 |
| - // Load initial data |
41 |
| - (async () => { |
42 |
| - const userInfo = await globalState.userController.user; |
43 |
| - const isFake = await globalState.userController.isFake; |
44 |
| - userData = { ...userInfo, isFake }; |
45 |
| - const vaultData = await globalState.vaultController.vault; |
46 |
| - ename = vaultData?.ename; |
47 |
| - })(); |
| 49 | + // Get initial profile creation status |
| 50 | + profileCreationStatus = globalState.vaultController.profileCreationStatus; |
48 | 51 |
|
49 |
| - // Get initial profile creation status |
| 52 | + // Set up a watcher for profile creation status changes |
| 53 | + const checkStatus = () => { |
50 | 54 | profileCreationStatus =
|
51 | 55 | globalState.vaultController.profileCreationStatus;
|
52 |
| -
|
53 |
| - // Set up a watcher for profile creation status changes |
54 |
| - const checkStatus = () => { |
55 |
| - profileCreationStatus = |
56 |
| - globalState.vaultController.profileCreationStatus; |
57 |
| - }; |
58 |
| -
|
59 |
| - // Check status periodically |
60 |
| - statusInterval = setInterval(checkStatus, 1000); |
61 |
| -
|
62 |
| - const currentHour = new Date().getHours(); |
63 |
| - greeting = |
64 |
| - currentHour > 17 |
65 |
| - ? "Good Evening" |
66 |
| - : currentHour > 12 |
67 |
| - ? "Good Afternoon" |
68 |
| - : "Good Morning"; |
69 |
| - }); |
70 |
| -
|
71 |
| - onDestroy(() => { |
72 |
| - if (statusInterval) { |
73 |
| - clearInterval(statusInterval); |
74 |
| - } |
75 |
| - }); |
| 56 | + }; |
| 57 | +
|
| 58 | + // Check status periodically |
| 59 | + statusInterval = setInterval(checkStatus, 1000); |
| 60 | +
|
| 61 | + const currentHour = new Date().getHours(); |
| 62 | + greeting = |
| 63 | + currentHour > 17 |
| 64 | + ? "Good Evening" |
| 65 | + : currentHour > 12 |
| 66 | + ? "Good Afternoon" |
| 67 | + : "Good Morning"; |
| 68 | +}); |
| 69 | +
|
| 70 | +onDestroy(() => { |
| 71 | + if (statusInterval) { |
| 72 | + clearInterval(statusInterval); |
| 73 | + } |
| 74 | +}); |
76 | 75 | </script>
|
77 | 76 |
|
78 | 77 | {#if profileCreationStatus === "loading"}
|
|
0 commit comments