File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
components/ui/modal/stacked Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,12 @@ export const useModalStack = (options?: ModalStackOptions) => {
64
64
}
65
65
}
66
66
const actions = {
67
+ getTopModalStack ( ) {
68
+ return jotaiStore . get ( modalStackAtom ) [ 0 ]
69
+ } ,
70
+ getModalStackById ( id : string ) {
71
+ return jotaiStore . get ( modalStackAtom ) . find ( ( item ) => item . id === id )
72
+ } ,
67
73
dismiss ( id : string ) {
68
74
jotaiStore . set ( modalStackAtom , ( p ) => p . filter ( ( item ) => item . id !== id ) )
69
75
} ,
Original file line number Diff line number Diff line change @@ -81,16 +81,26 @@ const ShortcutModalContent = () => {
81
81
}
82
82
83
83
export const useShortcutsModal = ( ) => {
84
- const { present } = useModalStack ( )
84
+ const { present, dismiss, getModalStackById } = useModalStack ( )
85
+ const id = "shortcuts"
85
86
86
- return useCallback ( ( ) => {
87
+ const showShortcutsModal = useCallback ( ( ) => {
87
88
present ( {
88
89
title : "Shortcuts" ,
90
+ id,
89
91
overlay : false ,
90
- id : "shortcuts" ,
91
92
content : ( ) => < ShortcutModalContent /> ,
92
93
CustomModalComponent : PlainModal ,
93
94
clickOutsideToDismiss : true ,
94
95
} )
95
96
} , [ present ] )
97
+
98
+ return useCallback ( ( ) => {
99
+ const shortcutsModal = getModalStackById ( id )
100
+ if ( shortcutsModal && shortcutsModal . modal ) {
101
+ dismiss ( id )
102
+ return
103
+ }
104
+ showShortcutsModal ( )
105
+ } , [ dismiss , getModalStackById , showShortcutsModal ] )
96
106
}
You can’t perform that action at this time.
0 commit comments