|
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, Toast } from "$lib/ui"; |
6 | | - import * as Button from "$lib/ui/Button"; |
7 | | - import { |
8 | | - CircleArrowDataTransferDiagonalFreeIcons, |
9 | | - QrCodeIcon, |
10 | | - Settings02Icon, |
11 | | - } from "@hugeicons/core-free-icons"; |
12 | | - import { HugeiconsIcon } from "@hugeicons/svelte"; |
13 | | - import { type Snippet, getContext, onMount } from "svelte"; |
14 | | - import { onDestroy } from "svelte"; |
15 | | - import { Shadow } from "svelte-loading-spinners"; |
16 | | - import QrCode from "svelte-qrcode"; |
17 | | -
|
18 | | - let userData: Record<string, unknown> | undefined = $state(undefined); |
19 | | - let greeting: string | undefined = $state(undefined); |
20 | | - let ename: string | undefined = $state(undefined); |
21 | | - let profileCreationStatus: "idle" | "loading" | "success" | "failed" = |
22 | | - $state("idle"); |
23 | | -
|
24 | | - let shareQRdrawerOpen = $state(false); |
25 | | - let statusInterval: ReturnType<typeof setInterval> | undefined = |
26 | | - $state(undefined); |
27 | | - let showToast = $state(false); |
28 | | - let toastMessage = $state(""); |
29 | | -
|
30 | | - function shareQR() { |
31 | | - alert("QR Code shared!"); |
32 | | - 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, Toast } from "$lib/ui"; |
| 6 | +import * as Button from "$lib/ui/Button"; |
| 7 | +import { |
| 8 | + CircleArrowDataTransferDiagonalFreeIcons, |
| 9 | + QrCodeIcon, |
| 10 | + Settings02Icon, |
| 11 | +} from "@hugeicons/core-free-icons"; |
| 12 | +import { HugeiconsIcon } from "@hugeicons/svelte"; |
| 13 | +import { type Snippet, getContext, onMount } from "svelte"; |
| 14 | +import { onDestroy } from "svelte"; |
| 15 | +import { Shadow } from "svelte-loading-spinners"; |
| 16 | +import QrCode from "svelte-qrcode"; |
| 17 | +
|
| 18 | +let userData: Record<string, unknown> | undefined = $state(undefined); |
| 19 | +let greeting: string | undefined = $state(undefined); |
| 20 | +let ename: string | undefined = $state(undefined); |
| 21 | +let profileCreationStatus: "idle" | "loading" | "success" | "failed" = |
| 22 | + $state("idle"); |
| 23 | +
|
| 24 | +let shareQRdrawerOpen = $state(false); |
| 25 | +let statusInterval: ReturnType<typeof setInterval> | undefined = |
| 26 | + $state(undefined); |
| 27 | +let showToast = $state(false); |
| 28 | +let toastMessage = $state(""); |
| 29 | +
|
| 30 | +function shareQR() { |
| 31 | + alert("QR Code shared!"); |
| 32 | + shareQRdrawerOpen = false; |
| 33 | +} |
| 34 | +
|
| 35 | +async function copyEName() { |
| 36 | + if (!ename) return; |
| 37 | + try { |
| 38 | + await navigator.clipboard.writeText(ename); |
| 39 | + toastMessage = "eName copied to clipboard!"; |
| 40 | + showToast = true; |
| 41 | + } catch (error) { |
| 42 | + console.error("Failed to copy eName:", error); |
| 43 | + toastMessage = "Failed to copy eName"; |
| 44 | + showToast = true; |
33 | 45 | } |
| 46 | +} |
34 | 47 |
|
35 | | - async function copyEName() { |
36 | | - if (!ename) return; |
37 | | - try { |
38 | | - await navigator.clipboard.writeText(ename); |
39 | | - toastMessage = "eName copied to clipboard!"; |
40 | | - showToast = true; |
41 | | - } catch (error) { |
42 | | - console.error("Failed to copy eName:", error); |
43 | | - toastMessage = "Failed to copy eName"; |
44 | | - showToast = true; |
45 | | - } |
46 | | - } |
47 | | -
|
48 | | - function handleToastClose() { |
49 | | - showToast = false; |
50 | | - } |
| 48 | +function handleToastClose() { |
| 49 | + showToast = false; |
| 50 | +} |
51 | 51 |
|
52 | | - async function retryProfileCreation() { |
53 | | - try { |
54 | | - await globalState.vaultController.retryProfileCreation(); |
55 | | - } catch (error) { |
56 | | - console.error("Retry failed:", error); |
57 | | - } |
| 52 | +async function retryProfileCreation() { |
| 53 | + try { |
| 54 | + await globalState.vaultController.retryProfileCreation(); |
| 55 | + } catch (error) { |
| 56 | + console.error("Retry failed:", error); |
58 | 57 | } |
| 58 | +} |
59 | 59 |
|
60 | | - const globalState = getContext<() => GlobalState>("globalState")(); |
| 60 | +const globalState = getContext<() => GlobalState>("globalState")(); |
61 | 61 |
|
62 | | - onMount(() => { |
63 | | - // Load initial data |
64 | | - (async () => { |
65 | | - const userInfo = await globalState.userController.user; |
66 | | - const isFake = await globalState.userController.isFake; |
67 | | - userData = { ...userInfo, isFake }; |
68 | | - const vaultData = await globalState.vaultController.vault; |
69 | | - ename = vaultData?.ename; |
70 | | - })(); |
| 62 | +onMount(() => { |
| 63 | + // Load initial data |
| 64 | + (async () => { |
| 65 | + const userInfo = await globalState.userController.user; |
| 66 | + const isFake = await globalState.userController.isFake; |
| 67 | + userData = { ...userInfo, isFake }; |
| 68 | + const vaultData = await globalState.vaultController.vault; |
| 69 | + ename = vaultData?.ename; |
| 70 | + })(); |
71 | 71 |
|
72 | | - // Get initial profile creation status |
| 72 | + // Get initial profile creation status |
73 | 73 | profileCreationStatus = globalState.vaultController.profileCreationStatus; |
74 | | - console.log("status current", profileCreationStatus); |
75 | | -
|
76 | | - // Set up a watcher for profile creation status changes |
77 | | - const checkStatus = () => { |
78 | | - profileCreationStatus = |
79 | | - globalState.vaultController.profileCreationStatus; |
80 | | - }; |
81 | | -
|
82 | | - // Check status periodically |
83 | | - statusInterval = setInterval(checkStatus, 1000); |
84 | | -
|
85 | | - const currentHour = new Date().getHours(); |
86 | | - greeting = |
87 | | - currentHour > 17 |
88 | | - ? "Good Evening" |
89 | | - : currentHour > 12 |
90 | | - ? "Good Afternoon" |
91 | | - : "Good Morning"; |
92 | | - }); |
93 | | -
|
94 | | - onDestroy(() => { |
95 | | - if (statusInterval) { |
96 | | - clearInterval(statusInterval); |
97 | | - } |
98 | | - }); |
| 74 | + console.log("status current", profileCreationStatus); |
| 75 | +
|
| 76 | + // Set up a watcher for profile creation status changes |
| 77 | + const checkStatus = () => { |
| 78 | + profileCreationStatus = |
| 79 | + globalState.vaultController.profileCreationStatus; |
| 80 | + }; |
| 81 | +
|
| 82 | + // Check status periodically |
| 83 | + statusInterval = setInterval(checkStatus, 1000); |
| 84 | +
|
| 85 | + const currentHour = new Date().getHours(); |
| 86 | + greeting = |
| 87 | + currentHour > 17 |
| 88 | + ? "Good Evening" |
| 89 | + : currentHour > 12 |
| 90 | + ? "Good Afternoon" |
| 91 | + : "Good Morning"; |
| 92 | +}); |
| 93 | +
|
| 94 | +onDestroy(() => { |
| 95 | + if (statusInterval) { |
| 96 | + clearInterval(statusInterval); |
| 97 | + } |
| 98 | +}); |
99 | 99 | </script> |
100 | 100 |
|
101 | 101 | {#if profileCreationStatus === "loading"} |
|
0 commit comments