Disable modal confirm button while async callbacks are being processed to avoid multiple executions
This commit is contained in:
parent
2df104568d
commit
4d8e4061b3
|
@ -10,31 +10,50 @@
|
||||||
export let onConfirm
|
export let onConfirm
|
||||||
|
|
||||||
const modalContext = getContext(ContextKey)
|
const modalContext = getContext(ContextKey)
|
||||||
|
let loading = false
|
||||||
|
|
||||||
function hide() {
|
function hide() {
|
||||||
modalContext.hide()
|
modalContext.hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function confirm() {
|
async function confirm() {
|
||||||
|
loading = true
|
||||||
if (!onConfirm || (await onConfirm()) !== false) {
|
if (!onConfirm || (await onConfirm()) !== false) {
|
||||||
hide()
|
hide()
|
||||||
}
|
}
|
||||||
|
loading = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if showCancelButton || showConfirmButton}
|
|
||||||
<footer>
|
<footer>
|
||||||
|
<div class="content">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
<div class="buttons">
|
||||||
{#if showCancelButton}
|
{#if showCancelButton}
|
||||||
<Button secondary on:click={hide}>{cancelText}</Button>
|
<Button secondary on:click={hide}>{cancelText}</Button>
|
||||||
{/if}
|
{/if}
|
||||||
{#if showConfirmButton}
|
{#if showConfirmButton}
|
||||||
<Button primary {...$$restProps} on:click={confirm}>{confirmText}</Button>
|
<Button
|
||||||
|
primary
|
||||||
|
{...$$restProps}
|
||||||
|
disabled={$$props.disabled || loading}
|
||||||
|
on:click={confirm}>
|
||||||
|
{confirmText}
|
||||||
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
{/if}
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
footer {
|
footer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--spacing-m);
|
||||||
|
}
|
||||||
|
.buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
|
|
Loading…
Reference in New Issue