[O] Make confirm callback nullable

This commit is contained in:
Azalea
2025-03-20 06:28:28 -04:00
parent 917f8476b9
commit edf5dd133b
2 changed files with 5 additions and 5 deletions

View File

@@ -13,9 +13,9 @@
export let error: string | null export let error: string | null
export let loading: boolean = false export let loading: boolean = false
function doConfirm(fn: () => void) { function doConfirm(fn?: () => void) {
confirm = null confirm = null
fn() fn && fn()
} }
</script> </script>
@@ -27,9 +27,9 @@
<div class="actions"> <div class="actions">
{#if confirm.cancel} {#if confirm.cancel}
<button on:click={() => doConfirm(confirm!!.cancel!!)}>{t('action.cancel')}</button> <button on:click={() => doConfirm(confirm?.cancel)}>{t('action.cancel')}</button>
{/if} {/if}
<button on:click={() => doConfirm(confirm!!.confirm)} class:error={confirm.dangerous}>{t('action.confirm')}</button> <button on:click={() => doConfirm(confirm?.confirm)} class:error={confirm.dangerous}>{t('action.confirm')}</button>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -50,7 +50,7 @@ export interface CardSummary {
export interface ConfirmProps { export interface ConfirmProps {
title: string title: string
message: string message: string
confirm: () => void confirm?: () => void
cancel?: () => void cancel?: () => void
dangerous?: boolean dangerous?: boolean
} }