Skip to content

Commit 7ebc4b0

Browse files
authored
Merge pull request #426 from CodingCatDev/v2-loading-indicator
V2 loading indicator
2 parents 20c8fba + 484c3ab commit 7ebc4b0

5 files changed

Lines changed: 91 additions & 67 deletions

File tree

‎apps/codingcatdev/src/lib/stores/stores.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { writable } from 'svelte/store';
1+
import { writable, derived } from 'svelte/store';
22
import type { Writable } from 'svelte/store';
3+
import { navigating } from "$app/stores";
4+
35

46
// Set within root layout, persists current SvelteKit $page.url.pathname
57
export const storeCurrentUrl: Writable<string | undefined> = writable(undefined);
@@ -11,3 +13,12 @@ export interface User {
1113
uid?: string;
1214
}
1315
export const storeUser: Writable<User | undefined> = writable(undefined);
16+
17+
let navTimer: number | NodeJS.Timeout | null | undefined = null;
18+
export const navigationIsDelayed = derived(navigating, (newValue, set) => {
19+
if (navTimer) { clearTimeout(navTimer); }
20+
if (newValue) {
21+
navTimer = setTimeout(() => set(true), 500);
22+
}
23+
set(false);
24+
});

‎apps/codingcatdev/src/routes/+layout.svelte‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
// Core
55
import { page } from '$app/stores';
66
import { afterNavigate } from '$app/navigation';
7-
import { storeCurrentUrl, storeUser } from '$lib/stores/stores';
7+
import { navigationIsDelayed, storeCurrentUrl, storeUser } from '$lib/stores/stores';
88
99
//Style
1010
import '../app.postcss';
1111
1212
// BlackCatUI Components
13-
import { AppShell, Modal, Toast, storePopup } from '@codingcatdev/blackcatui';
13+
import { AppShell, Modal, ProgressCircle, Toast, storePopup } from '@codingcatdev/blackcatui';
1414
1515
// Depedency: Floating UI
1616
import { computePosition, autoUpdate, flip, shift, offset, arrow } from '@floating-ui/dom';
@@ -123,7 +123,15 @@
123123
<svelte:fragment slot="bcu-app-shell-header"><CcdAppBar /></svelte:fragment>
124124

125125
<!-- Page Content -->
126-
<slot />
126+
{#if $navigationIsDelayed}
127+
<!-- LOOK HERE -->
128+
<div class="flex flex-col m-2 md:m-8 items-center gap-2 md:gap-8">
129+
<ProgressCircle stroke={60} value={undefined} width="w-20 md:w-36" />
130+
<h1 class="ext-3xl text-center text-cText">Fetching...</h1>
131+
</div>
132+
{:else}
133+
<slot />
134+
{/if}
127135

128136
<!-- Page Footer -->
129137
<svelte:fragment slot="bcu-app-shell-page-footer"><CcdFooter /></svelte:fragment>
Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
<script lang="ts">
22
import LayoutWrapper from '../(layout-partials)/LayoutWrapper.svelte';
3-
4-
import { enhance } from '$app/forms';
5-
import type { ActionData } from './$types';
6-
7-
import { ccdSignInWithEmailAndPassword } from '$lib/client/firebase';
8-
9-
import { toastStore } from '@codingcatdev/blackcatui';
10-
113
import GoogleAuth from './GoogleAuth.svelte';
124
import TwitterAuth from './TwitterAuth.svelte';
135
import GitHubAuth from './GitHubAuth.svelte';
@@ -16,68 +8,18 @@
168
// export let form: ActionData;
179
1810
import type { PageData } from './$types';
11+
import EmailAuth from './EmailAuth.svelte';
1912
export let data: PageData;
2013
$: action = `?/login&redirectTo=${data.redirectTo ? data.redirectTo : '/dashboard'}`;
2114
</script>
2215

2316
<LayoutWrapper>
2417
<section class="bcu-card flex flex-col gap-4 p-4">
25-
<form
26-
class="flex justify-center w-full"
27-
method="POST"
28-
{action}
29-
use:enhance={async ({ action, cancel, controller, data, form }) => {
30-
// `form` is the `<form>` element
31-
// `data` is its `FormData` object
32-
// `action` is the URL to which the form is posted
33-
// `cancel()` will prevent the submission
34-
35-
const email = `${data.get('email')}`;
36-
const password = `${data.get('password')}`;
37-
38-
if (!email || !password) {
39-
toastStore.trigger({
40-
message: 'Please Provide Username and Password.'
41-
});
42-
cancel();
43-
} else {
44-
try {
45-
await ccdSignInWithEmailAndPassword({ email, password });
46-
} catch (err) {
47-
if (err instanceof Error) {
48-
toastStore.trigger({
49-
message: err.message,
50-
background: 'variant-filled-error'
51-
});
52-
}
53-
}
54-
}
55-
56-
return async ({ result, update }) => {
57-
// `result` is an `ActionResult` object
58-
// `update` is a function which triggers the logic that would be triggered if this callback wasn't set
59-
60-
update();
61-
};
62-
}}
63-
>
64-
<div class="flex flex-col gap-4 text-token">
65-
<label class="label">
66-
<span>Email</span>
67-
<input class="input" name="email" type="email" placeholder="codercatdev" />
68-
</label>
69-
<label class="label">
70-
<span>Password</span>
71-
<input class="input" name="password" type="password" placeholder="****" />
72-
</label>
73-
<button class="bcu-button variant-filled-primary" type="submit">Login</button>
74-
</div>
75-
</form>
76-
18+
<EmailAuth {action} />
7719
<hr />
7820

7921
<GoogleAuth {action} />
80-
<TwitterAuth />
81-
<GitHubAuth />
22+
<!-- <TwitterAuth /> -->
23+
<GitHubAuth {action} />
8224
</section>
8325
</LayoutWrapper>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<script lang="ts">
2+
import { enhance } from '$app/forms';
3+
import type { ActionData } from './$types';
4+
5+
import { ccdSignInWithEmailAndPassword } from '$lib/client/firebase';
6+
7+
import { toastStore } from '@codingcatdev/blackcatui';
8+
9+
export let action: string;
10+
</script>
11+
12+
<form
13+
class="flex justify-center w-full"
14+
method="POST"
15+
{action}
16+
use:enhance={async ({ action, cancel, controller, data, form }) => {
17+
// `form` is the `<form>` element
18+
// `data` is its `FormData` object
19+
// `action` is the URL to which the form is posted
20+
// `cancel()` will prevent the submission
21+
22+
const email = `${data.get('email')}`;
23+
const password = `${data.get('password')}`;
24+
25+
if (!email || !password) {
26+
toastStore.trigger({
27+
message: 'Please Provide Username and Password.'
28+
});
29+
cancel();
30+
} else {
31+
try {
32+
await ccdSignInWithEmailAndPassword({ email, password });
33+
} catch (err) {
34+
if (err instanceof Error) {
35+
toastStore.trigger({
36+
message: err.message,
37+
background: 'variant-filled-error'
38+
});
39+
}
40+
}
41+
}
42+
43+
return async ({ result, update }) => {
44+
// `result` is an `ActionResult` object
45+
// `update` is a function which triggers the logic that would be triggered if this callback wasn't set
46+
47+
update();
48+
};
49+
}}
50+
>
51+
<div class="flex flex-col gap-4 text-token">
52+
<label class="label">
53+
<span>Email</span>
54+
<input class="input" name="email" type="email" placeholder="codercatdev" />
55+
</label>
56+
<label class="label">
57+
<span>Password</span>
58+
<input class="input" name="password" type="password" placeholder="****" />
59+
</label>
60+
<button class="bcu-button variant-filled-primary" type="submit">Login</button>
61+
</div>
62+
</form>

‎apps/codingcatdev/src/routes/login/GitHubAuth.svelte‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
1010
// Display
1111
import { enhance } from '$app/forms';
12+
export let action: string;
1213
</script>
1314

1415
<form
1516
class="flex justify-center w-full"
1617
method="POST"
17-
action="?/login"
18+
{action}
1819
use:enhance={async ({ action, cancel, controller, data, form }) => {
1920
await ccdSignInWithPopUp(provider);
2021

0 commit comments

Comments
 (0)