feat(ui): add global feedback and agent menu
This commit is contained in:
@@ -1,10 +1,27 @@
|
||||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import { actionFeedback } from '$lib/toast';
|
||||
import type { Snippet } from 'svelte';
|
||||
let { action, method = 'POST', enctype, class: className = '', children }: { action: string; method?: 'POST'; enctype?: 'multipart/form-data'; class?: string; children: Snippet<[boolean]> } = $props();
|
||||
let {
|
||||
action,
|
||||
method = 'POST',
|
||||
enctype,
|
||||
class: className = '',
|
||||
toast = true,
|
||||
successMessage,
|
||||
children
|
||||
}: {
|
||||
action: string;
|
||||
method?: 'POST';
|
||||
enctype?: 'multipart/form-data';
|
||||
class?: string;
|
||||
toast?: boolean;
|
||||
successMessage?: string;
|
||||
children: Snippet<[boolean]>;
|
||||
} = $props();
|
||||
let pending = $state(false);
|
||||
</script>
|
||||
<form {action} {method} {enctype} class={className} use:enhance={() => { if (pending) return; pending = true; return async ({ update }) => { try { await update(); } finally { pending = false; } }; }}>
|
||||
<form {action} {method} {enctype} class={className} use:enhance={() => { if (pending) return; pending = true; return async ({ result, update }) => { try { if (toast) actionFeedback(result, action, successMessage); await update(); } finally { pending = false; } }; }}>
|
||||
<fieldset disabled={pending} aria-busy={pending}>{@render children(pending)}</fieldset>
|
||||
</form>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user