Show loading spinners for form actions and page loads

This commit is contained in:
thiloho
2024-09-07 14:28:23 +02:00
parent e153120a47
commit 958b8e3643
13 changed files with 193 additions and 6 deletions

View File

@@ -2,13 +2,29 @@
import { enhance } from "$app/forms";
import SuccessOrError from "$lib/components/SuccessOrError.svelte";
import type { ActionData } from "./$types";
import LoadingSpinner from "$lib/components/LoadingSpinner.svelte";
const { form }: { form: ActionData } = $props();
let sending = $state(false);
</script>
<SuccessOrError success={form?.success} message={form?.message} />
<form method="POST" use:enhance>
{#if sending}
<LoadingSpinner />
{/if}
<form
method="POST"
use:enhance={() => {
sending = true;
return async ({ update }) => {
await update();
sending = false;
};
}}
>
<label>
Username:
<input type="text" name="username" required />