Add confirmation dialog

This commit is contained in:
Thomas Nordquist
2019-07-17 09:14:10 +02:00
parent 094831f037
commit 1cef529ac7
6 changed files with 147 additions and 8 deletions

View File

@@ -9,6 +9,14 @@ export enum ActionTypes {
showNotification = 'SHOW_NOTIFICATION',
didLaunch = 'DID_LAUNCH',
toggleSettingsVisibility = 'TOGGLE_SETTINGS_VISIBILITY',
requestConfirmation = 'REQUEST_CONFIRMATION',
removeConfirmationRequest = 'REMOVE_CONFIRMATION_REQUEST',
}
export interface ConfirmationRequest {
inquiry: string
title: string
callback: (confirmed: boolean) => void
}
export interface GlobalAction extends Action {
@@ -17,6 +25,7 @@ export interface GlobalAction extends Action {
showUpdateDetails?: boolean
error?: string
notification?: string
confirmationRequest?: ConfirmationRequest
}
interface GlobalStateInterface {
@@ -26,6 +35,7 @@ interface GlobalStateInterface {
notification?: string
launching: boolean
settingsVisible: boolean
confirmationRequests: Array<ConfirmationRequest>
}
export type GlobalState = Record<GlobalStateInterface>
@@ -37,6 +47,7 @@ const initialStateFactory = Record<GlobalStateInterface>({
notification: undefined,
launching: true,
settingsVisible: false,
confirmationRequests: [],
})
export const globalState: Reducer<Record<GlobalStateInterface>, GlobalAction> = (
@@ -67,6 +78,21 @@ export const globalState: Reducer<Record<GlobalStateInterface>, GlobalAction> =
}
return state.set('showUpdateDetails', action.showUpdateDetails)
case ActionTypes.requestConfirmation:
if (action.confirmationRequest === undefined) {
return state
}
return state.set('confirmationRequests', [...state.get('confirmationRequests'), action.confirmationRequest])
case ActionTypes.removeConfirmationRequest:
if (action.confirmationRequest === undefined) {
return state
}
return state.set(
'confirmationRequests',
state.get('confirmationRequests').filter(a => a !== action.confirmationRequest)
)
default:
return state
}