|
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 { getContext, onMount, type Snippet } from "svelte"; |
10 |
| -import { Shadow } from "svelte-loading-spinners"; |
11 |
| -import { onDestroy } from "svelte"; |
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: any = $state(undefined); |
22 |
| -
|
23 |
| -function shareQR() { |
24 |
| - alert("QR Code shared!"); |
25 |
| - shareQRdrawerOpen = false; |
26 |
| -} |
27 |
| -
|
28 |
| -async function retryProfileCreation() { |
29 |
| - try { |
30 |
| - await globalState.vaultController.retryProfileCreation(); |
31 |
| - } catch (error) { |
32 |
| - console.error("Retry failed:", error); |
| 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; |
33 | 27 | }
|
34 |
| -} |
35 | 28 |
|
36 |
| -const globalState = getContext<() => GlobalState>("globalState")(); |
| 29 | + async function retryProfileCreation() { |
| 30 | + try { |
| 31 | + await globalState.vaultController.retryProfileCreation(); |
| 32 | + } catch (error) { |
| 33 | + console.error("Retry failed:", error); |
| 34 | + } |
| 35 | + } |
37 | 36 |
|
38 |
| -onMount(() => { |
39 |
| - // Load initial data |
40 |
| - (async () => { |
41 |
| - const userInfo = await globalState.userController.user; |
42 |
| - const isFake = await globalState.userController.isFake; |
43 |
| - userData = { ...userInfo, isFake }; |
44 |
| - const vaultData = await globalState.vaultController.vault; |
45 |
| - ename = vaultData?.ename; |
46 |
| - })(); |
| 37 | + const globalState = getContext<() => GlobalState>("globalState")(); |
47 | 38 |
|
48 |
| - // Get initial profile creation status |
49 |
| - profileCreationStatus = globalState.vaultController.profileCreationStatus; |
| 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 | + })(); |
50 | 48 |
|
51 |
| - // Set up a watcher for profile creation status changes |
52 |
| - const checkStatus = () => { |
| 49 | + // Get initial profile creation status |
53 | 50 | profileCreationStatus =
|
54 | 51 | globalState.vaultController.profileCreationStatus;
|
55 |
| - }; |
56 |
| -
|
57 |
| - // Check status periodically |
58 |
| - statusInterval = setInterval(checkStatus, 1000); |
59 |
| -
|
60 |
| - const currentHour = new Date().getHours(); |
61 |
| - greeting = |
62 |
| - currentHour > 17 |
63 |
| - ? "Good Evening" |
64 |
| - : currentHour > 12 |
65 |
| - ? "Good Afternoon" |
66 |
| - : "Good Morning"; |
67 |
| -}); |
68 |
| -
|
69 |
| -onDestroy(() => { |
70 |
| - if (statusInterval) { |
71 |
| - clearInterval(statusInterval); |
72 |
| - } |
73 |
| -}); |
| 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 | + }); |
74 | 76 | </script>
|
75 | 77 |
|
76 | 78 | {#if profileCreationStatus === "loading"}
|
|
0 commit comments