fix(ui): prevent double-close and fix dialog replacement
This commit is contained in:
@@ -28,15 +28,18 @@ const Context = createContext<ReturnType<typeof init>>()
|
|||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
const [active, setActive] = createSignal<Active | undefined>()
|
const [active, setActive] = createSignal<Active | undefined>()
|
||||||
|
let closing = false
|
||||||
|
|
||||||
const close = () => {
|
const close = () => {
|
||||||
const current = active()
|
const current = active()
|
||||||
if (!current) return
|
if (!current || closing) return
|
||||||
|
closing = true
|
||||||
current.onClose?.()
|
current.onClose?.()
|
||||||
current.setClosing(true)
|
current.setClosing(true)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
current.dispose()
|
current.dispose()
|
||||||
setActive(undefined)
|
setActive(undefined)
|
||||||
|
closing = false
|
||||||
}, 100)
|
}, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +58,13 @@ function init() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const show = (element: DialogElement, owner: Owner, onClose?: () => void) => {
|
const show = (element: DialogElement, owner: Owner, onClose?: () => void) => {
|
||||||
close()
|
// Immediately dispose any existing dialog when showing a new one
|
||||||
|
const current = active()
|
||||||
|
if (current) {
|
||||||
|
current.dispose()
|
||||||
|
setActive(undefined)
|
||||||
|
}
|
||||||
|
closing = false
|
||||||
|
|
||||||
const id = Math.random().toString(36).slice(2)
|
const id = Math.random().toString(36).slice(2)
|
||||||
let dispose: (() => void) | undefined
|
let dispose: (() => void) | undefined
|
||||||
|
|||||||
Reference in New Issue
Block a user