Skip to content

Commit 33b0c59

Browse files
author
bunsenstraat
committed
fix queue processing
1 parent 03d4b9e commit 33b0c59

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

libs/remix-ui/app/src/lib/remix-app/actions/modals.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type ActionMap<M extends { [index: string]: any }> = {
1414
export const enum modalActionTypes {
1515
setModal = 'SET_MODAL',
1616
setToast = 'SET_TOAST',
17+
processQueue = 'PROCESS_QUEUEU',
1718
handleHideModal = 'HANDLE_HIDE_MODAL',
1819
handleToaster = 'HANDLE_HIDE_TOAST'
1920
}
@@ -22,7 +23,8 @@ type ModalPayload = {
2223
[modalActionTypes.setModal]: AppModal
2324
[modalActionTypes.handleHideModal]: any
2425
[modalActionTypes.setToast]: string | JSX.Element
25-
[modalActionTypes.handleToaster]: any
26+
[modalActionTypes.handleToaster]: any,
27+
[modalActionTypes.processQueue]: any
2628
}
2729

2830
export type ModalAction = ActionMap<ModalPayload>[keyof ActionMap<

libs/remix-ui/app/src/lib/remix-app/context/provider.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ import { AppContext, dispatchModalContext, modalContext } from './context'
99
export const ModalProvider = ({ children = [], reducer = modalReducer, initialState = ModalInitialState } = {}) => {
1010
const [{ modals, toasters, focusModal, focusToaster }, dispatch] = useReducer(reducer, initialState)
1111

12+
const onNextFn = async () => {
13+
dispatch({
14+
type: modalActionTypes.processQueue
15+
})
16+
}
17+
1218
const modal = (data: AppModal) => {
1319
const { id, title, message, okLabel, okFn, cancelLabel, cancelFn, modalType, defaultValue, hideFn } = data
1420
return new Promise((resolve, reject) => {
1521
dispatch({
1622
type: modalActionTypes.setModal,
17-
payload: { id, title, message, okLabel, okFn, cancelLabel, cancelFn, modalType: modalType || ModalTypes.default, defaultValue: defaultValue, hideFn, resolve }
23+
payload: { id, title, message, okLabel, okFn, cancelLabel, cancelFn, modalType: modalType || ModalTypes.default, defaultValue: defaultValue, hideFn, resolve, next: onNextFn }
1824
})
1925
})
2026
}

libs/remix-ui/app/src/lib/remix-app/interface/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export interface AppModal {
1414
modalType?: ModalTypes,
1515
defaultValue?: string
1616
hideFn?: () => void,
17-
resolve?: (value?:any) => void
17+
resolve?: (value?:any) => void,
18+
next?: () => void
1819
}
1920

2021
export interface AlertModal {

libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const modalReducer = (state: ModalState = ModalInitialState, action: Moda
1919
modalType: action.payload.modalType,
2020
defaultValue: action.payload.defaultValue,
2121
hideFn: action.payload.hideFn,
22-
resolve: action.payload.resolve
22+
resolve: action.payload.resolve,
23+
next: action.payload.next
2324
}
2425

2526
const modalList: AppModal[] = state.modals.slice()
@@ -39,15 +40,22 @@ export const modalReducer = (state: ModalState = ModalInitialState, action: Moda
3940
if (state.focusModal.resolve) {
4041
state.focusModal.resolve(undefined)
4142
}
43+
if (state.focusModal.next) {
44+
state.focusModal.next()
45+
}
4246
}, 250)
4347
const modalList: AppModal[] = state.modals.slice()
4448
modalList.shift() // remove the current modal from the list
49+
state.focusModal = { ...state.focusModal, hide: true, message: null }
50+
return { ...state, modals: modalList }
51+
}
52+
case modalActionTypes.processQueue: {
53+
const modalList: AppModal[] = state.modals.slice()
4554
if (modalList.length) {
4655
const focusModal = modalList[0] // extract the next modal from the list
4756
return { ...state, modals: modalList, focusModal }
4857
} else {
49-
state.focusModal = { ...state.focusModal, hide: true, message: null }
50-
return { ...state, modals: [] }
58+
return { ...state, modals: modalList }
5159
}
5260
}
5361
case modalActionTypes.setToast: {

libs/remix-ui/modal-dialog/src/lib/remix-ui-modal-dialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export const ModalDialog = (props: ModalDialogProps) => {
2020
}
2121

2222
useEffect(() => {
23-
calledHideFunctionOnce.current = false
23+
calledHideFunctionOnce.current = props.hide
2424
modal.current.focus()
25-
}, [props.timestamp])
25+
}, [props.hide])
2626

2727
useEffect(() => {
2828
function handleBlur (e) {

libs/remix-ui/modal-dialog/src/lib/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ export interface ModalDialogProps {
1414
handleHide: (hideState?: boolean) => void,
1515
children?: React.ReactNode,
1616
resolve?: (value?:any) => void,
17+
next?: () => void
1718
}

0 commit comments

Comments
 (0)