From fca5940e802aa53d10cb00f4bce52c07f38f11f7 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 16 Nov 2022 15:35:22 +0100 Subject: [PATCH] visual hints when buttons are loading goto --- .../lib/components/common/button/Button.svelte | 18 +++++++++++++++--- .../landing/FlowGettingStarted.svelte | 8 +------- .../components/landing/FlowLandingBox.svelte | 4 ++-- .../landing/RessourceGettingStarted.svelte | 2 +- .../lib/components/landing/ScriptBox.svelte | 4 ++-- .../landing/ScriptGettingStarted.svelte | 2 +- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/frontend/src/lib/components/common/button/Button.svelte b/frontend/src/lib/components/common/button/Button.svelte index d055ab318c..862d073f09 100644 --- a/frontend/src/lib/components/common/button/Button.svelte +++ b/frontend/src/lib/components/common/button/Button.svelte @@ -4,6 +4,7 @@ import Icon from 'svelte-awesome' import { ButtonType } from './model' import { goto } from '$app/navigation' + import { faArrowsRotate, faSpinner } from '@fortawesome/free-solid-svg-icons' export let size: ButtonType.Size = 'md' export let spacingSize: ButtonType.Size = size @@ -20,6 +21,8 @@ export let id: string = '' export let nonCaptureEvent: boolean = false + let loading = false + const dispatch = createEventDispatcher() // Order of classes: border, border modifier, bg, bg modifier, text, text modifier, everything else const colorVariants: Record> = { @@ -70,7 +73,7 @@ tabindex: disabled ? -1 : 0 } - function onClick(event: MouseEvent) { + async function onClick(event: MouseEvent) { if (!nonCaptureEvent) { event.preventDefault() dispatch('click', event) @@ -78,7 +81,9 @@ if (href.startsWith('http') || target == '_blank') { window.open(href, target) } else { - goto(href) + loading = true + await goto(href) + loading = false } } } @@ -100,9 +105,16 @@ on:blur {...buttonProps} > - {#if startIcon} + {#if loading} + + {:else if startIcon} {/if} + {#if !iconOnly} {/if} diff --git a/frontend/src/lib/components/landing/FlowGettingStarted.svelte b/frontend/src/lib/components/landing/FlowGettingStarted.svelte index 1987c78180..2b036a9e14 100644 --- a/frontend/src/lib/components/landing/FlowGettingStarted.svelte +++ b/frontend/src/lib/components/landing/FlowGettingStarted.svelte @@ -18,13 +18,7 @@ the Hub!
-
diff --git a/frontend/src/lib/components/landing/ScriptBox.svelte b/frontend/src/lib/components/landing/ScriptBox.svelte index cd81f6cc89..fcb1d6de4c 100644 --- a/frontend/src/lib/components/landing/ScriptBox.svelte +++ b/frontend/src/lib/components/landing/ScriptBox.svelte @@ -34,7 +34,7 @@