|
3 | 3 | import { resolve } from '$app/paths'; |
4 | 4 | import { page } from '$app/state'; |
5 | 5 | import { browser } from '$app/environment'; |
| 6 | + import { onMount } from 'svelte'; |
| 7 | + import Logo from '$lib/components/Logo.svelte'; |
| 8 | + import UserTag from '$lib/components/UserTag.svelte'; |
6 | 9 |
|
7 | 10 | import LucideGithub from '~icons/lucide/github'; |
8 | 11 |
|
| 12 | + const props = $props(); |
| 13 | + let { data } = props; |
| 14 | +
|
| 15 | + type AuthSnapshot = App.PageData['auth']; |
| 16 | + const DEFAULT_AUTH: AuthSnapshot = { |
| 17 | + isAuthenticated: false, |
| 18 | + sessionId: null, |
| 19 | + user: null |
| 20 | + }; |
| 21 | +
|
| 22 | + let authState: AuthSnapshot = $state(data?.auth ?? DEFAULT_AUTH); |
| 23 | +
|
| 24 | + $effect(() => { |
| 25 | + if (data?.auth) { |
| 26 | + authState = data.auth; |
| 27 | + } |
| 28 | + }); |
| 29 | +
|
| 30 | + onMount(() => { |
| 31 | + const unsubscribe = auth.subscribe((state) => { |
| 32 | + authState = { |
| 33 | + isAuthenticated: state.isAuthenticated, |
| 34 | + sessionId: state.sessionId, |
| 35 | + user: state.user |
| 36 | + }; |
| 37 | + }); |
| 38 | +
|
| 39 | + return () => unsubscribe(); |
| 40 | + }); |
| 41 | +
|
9 | 42 | // Handle url changes |
10 | 43 | $effect(() => { |
11 | 44 | if (browser) { |
|
42 | 75 | } |
43 | 76 | </script> |
44 | 77 |
|
45 | | -<div class="min-h-screen p-8 bg-mantle"> |
| 78 | +<div class="bg-mantle"> |
46 | 79 | <!-- Header --> |
47 | 80 | <header class="text-center mb-4 mt-[10vh]"> |
| 81 | + <Logo |
| 82 | + className="w-32 h-32 mx-auto mb-4 text-ctp-subtext0 dark:text-ctp-lavender-300 drop-shadow-[0_10px_30px_rgba(108,111,133,0.35)] dark:drop-shadow-[0_10px_30px_rgba(198,160,246,0.35)] transition-colors" |
| 83 | + /> |
48 | 84 | <div class="flex text-text items-center justify-center gap-3 mb-4"> |
49 | 85 | <h1 class="text-5xl font-bold">rustytime</h1> |
50 | 86 | </div> |
|
53 | 89 |
|
54 | 90 | <!-- Main Content --> |
55 | 91 | <div class="rounded-xl p-8 mb-12"> |
56 | | - {#if $auth.isLoading} |
57 | | - <!-- Loading State --> |
58 | | - <div class="text-center"> |
59 | | - <div class="animate-spin rounded-full h-12 w-12 border-b-2 border-ctp-text mx-auto"></div> |
60 | | - <p class="mt-4 text-subtext0">Loading...</p> |
61 | | - </div> |
62 | | - {:else if $auth.isAuthenticated && $auth.user} |
| 92 | + {#if authState.isAuthenticated && authState.user} |
63 | 93 | <!-- Authenticated User --> |
64 | 94 | <div class="text-center"> |
65 | 95 | <div class="flex items-center justify-center gap-4 mb-6"> |
66 | | - {#if $auth.user.avatar_url} |
| 96 | + {#if authState.user.avatar_url} |
67 | 97 | <img |
68 | | - src={$auth.user.avatar_url} |
| 98 | + src={authState.user.avatar_url} |
69 | 99 | alt="Profile" |
70 | 100 | class="w-16 h-16 rounded-full border-2 border-ctp-green-500" |
71 | 101 | /> |
72 | 102 | {/if} |
73 | 103 | <div> |
74 | 104 | <h2 class="text-2xl text-subtext1 font-bold"> |
75 | | - Welcome, {$auth.user.name || 'User'}! |
| 105 | + Welcome, {authState.user.name || 'User'}! |
76 | 106 | </h2> |
77 | 107 | <div class="flex flex-row items-center gap-1 align-middle"> |
78 | | - <span |
79 | | - class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full {$auth.user |
80 | | - .is_admin |
81 | | - ? 'bg-ctp-red-400 text-ctp-crust' |
82 | | - : 'bg-ctp-overlay2 text-ctp-crust'} items-center h-6" |
83 | | - > |
84 | | - {$auth.user.is_admin ? 'Admin' : 'User'} |
85 | | - </span> |
86 | | - <p class="text-subtext0">User ID: {$auth.user.id}</p> |
| 108 | + <UserTag is_admin={authState.user.is_admin} /> |
| 109 | + <p class="text-subtext0">User ID: {authState.user.id}</p> |
87 | 110 | </div> |
88 | 111 | </div> |
89 | 112 | </div> |
90 | 113 |
|
91 | 114 | <div class="space-y-4"> |
92 | 115 | <a |
93 | 116 | href={resolve('/dashboard')} |
94 | | - class="inline-block bg-ctp-peach-500 hover:bg-ctp-peach-600 text-ctp-base font-semibold py-3 px-6 rounded-lg" |
| 117 | + class="inline-block bg-ctp-mauve-400 hover:bg-ctp-mauve-500 text-ctp-base font-semibold py-3 px-6 rounded-lg" |
95 | 118 | > |
96 | 119 | Go to Dashboard |
97 | 120 | </a> |
98 | 121 |
|
99 | | - {#if $auth.user.is_admin} |
| 122 | + {#if authState.user.is_admin} |
100 | 123 | <a |
101 | 124 | href={resolve('/admin')} |
102 | | - class="inline-block bg-ctp-red-600 hover:bg-ctp-red-700 text-ctp-base font-semibold py-3 px-6 rounded-lg ml-4" |
| 125 | + class="inline-block bg-ctp-red-400 hover:bg-ctp-red-500 text-ctp-base font-semibold py-3 px-6 rounded-lg ml-4" |
103 | 126 | > |
104 | 127 | Admin Panel |
105 | 128 | </a> |
|
0 commit comments