fix(app): dialog not closing
This commit is contained in:
@@ -28,18 +28,33 @@ 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 timer = { current: undefined as ReturnType<typeof setTimeout> | undefined }
|
||||||
|
const lock = { value: false }
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
if (timer.current === undefined) return
|
||||||
|
clearTimeout(timer.current)
|
||||||
|
timer.current = undefined
|
||||||
|
})
|
||||||
|
|
||||||
const close = () => {
|
const close = () => {
|
||||||
const current = active()
|
const current = active()
|
||||||
if (!current || closing) return
|
if (!current || lock.value) return
|
||||||
closing = true
|
lock.value = true
|
||||||
current.onClose?.()
|
current.onClose?.()
|
||||||
current.setClosing(true)
|
current.setClosing(true)
|
||||||
setTimeout(() => {
|
|
||||||
|
const id = current.id
|
||||||
|
if (timer.current !== undefined) {
|
||||||
|
clearTimeout(timer.current)
|
||||||
|
timer.current = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
timer.current = setTimeout(() => {
|
||||||
|
timer.current = undefined
|
||||||
current.dispose()
|
current.dispose()
|
||||||
setActive(undefined)
|
if (active()?.id === id) setActive(undefined)
|
||||||
closing = false
|
lock.value = false
|
||||||
}, 100)
|
}, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +79,12 @@ function init() {
|
|||||||
current.dispose()
|
current.dispose()
|
||||||
setActive(undefined)
|
setActive(undefined)
|
||||||
}
|
}
|
||||||
closing = false
|
|
||||||
|
if (timer.current !== undefined) {
|
||||||
|
clearTimeout(timer.current)
|
||||||
|
timer.current = undefined
|
||||||
|
}
|
||||||
|
lock.value = 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