Browse Source

tui: fix dialog replacement to prevent nested dialogs from showing simultaneously

Dax Raad 2 months ago
parent
commit
416a919c6d
1 changed files with 8 additions and 1 deletions
  1. 8 1
      packages/ui/src/context/dialog.tsx

+ 8 - 1
packages/ui/src/context/dialog.tsx

@@ -22,6 +22,7 @@ const Context = createContext<ReturnType<typeof init>>()
 function init() {
 function init() {
   const [store, setStore] = createSignal<
   const [store, setStore] = createSignal<
     {
     {
+      id: string
       element: DialogElement
       element: DialogElement
       onClose?: () => void
       onClose?: () => void
       owner: Owner
       owner: Owner
@@ -45,11 +46,13 @@ function init() {
       for (const item of store()) {
       for (const item of store()) {
         item.onClose?.()
         item.onClose?.()
       }
       }
+      const id = Math.random().toString(36)
       setStore([
       setStore([
         {
         {
+          id,
           element: () =>
           element: () =>
             runWithOwner(owner, () => (
             runWithOwner(owner, () => (
-              <Show when={result.stack.at(-1)?.owner === owner}>
+              <Show when={result.stack.at(-1)?.id === id}>
                 <Kobalte
                 <Kobalte
                   modal
                   modal
                   defaultOpen
                   defaultOpen
@@ -79,11 +82,15 @@ function init() {
       setStore([])
       setStore([])
     },
     },
   }
   }
+
   return result
   return result
 }
 }
 
 
 export function DialogProvider(props: ParentProps) {
 export function DialogProvider(props: ParentProps) {
   const ctx = init()
   const ctx = init()
+  createEffect(() => {
+    console.log("store", ctx.stack.length)
+  })
   return (
   return (
     <Context.Provider value={ctx}>
     <Context.Provider value={ctx}>
       {props.children}
       {props.children}