cobalt/web/src/components/dialog/DialogContainer.svelte
wukko 93ff9b62d6
Some checks are pending
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Waiting to run
Run tests / check lockfile correctness (push) Waiting to run
Run tests / web sanity check (push) Waiting to run
Run tests / api sanity check (push) Waiting to run
web/DialogContainer: prevent an error after a race condition
an error is no longer thrown if several dialogs were closed while timeout was running

this should really be replaced by proper dialog management system, with each dialog having a unique id and removal happening via that id, not just array.pop()
2025-03-17 16:47:03 +06:00

43 lines
1.1 KiB
Svelte

<script lang="ts">
import { tick } from "svelte";
import { killDialog } from "$lib/state/dialogs";
import DialogBackdropClose from "$components/dialog/DialogBackdropClose.svelte";
export let id: string;
export let dismissable = true;
let dialogParent: HTMLDialogElement;
let open = false;
let closing = false;
export const close = () => {
if (dialogParent) {
closing = true;
open = false;
// wait 150ms for the closing animation to finish
setTimeout(() => {
// check if dialog parent is still present
if (dialogParent) {
dialogParent.close();
killDialog();
}
}, 150);
}
};
$: if (dialogParent) {
dialogParent.showModal();
tick().then(() => {
open = true;
});
}
</script>
<dialog id="dialog-{id}" bind:this={dialogParent} class:closing class:open>
<slot></slot>
<DialogBackdropClose closeFunc={dismissable ? close : () => {}} />
</dialog>