Cancellable processes

This commit is contained in:
James Barnsley
2017-04-06 09:01:53 +12:00
parent f292e512dc
commit 27272dcd0f
7 changed files with 74 additions and 29 deletions

View File

@ -262,10 +262,11 @@ export function stopLoading(key){
}
}
export function startProcess(key){
export function startProcess(key,content){
return {
type: 'START_PROCESS',
key: key
key: key,
content: content
}
}

View File

@ -268,15 +268,13 @@ const UIMiddleware = (function(){
case 'CREATE_NOTIFICATION':
// start a timeout to remove this (non loading) notification
if (action.notification.type != 'process'){
var timeout = setTimeout(
function(){
store.dispatch(uiActions.removeNotification(action.notification.key))
},
(action.notification.type == 'shortcut' ? 1000 : 3000)
)
}
// start a timeout to remove this notification
var timeout = setTimeout(
function(){
store.dispatch(uiActions.removeNotification(action.notification.key))
},
(action.notification.type == 'shortcut' ? 1000 : 3000)
)
next(action)
break

View File

@ -745,7 +745,23 @@ export default function reducer(ui = {}, action){
case 'START_PROCESS':
var processes = Object.assign({}, (ui.processes ? ui.processes : []))
processes[action.key] = 'active'
processes[action.key] = {
key: action.key,
content: action.content
}
return Object.assign({}, ui, {processes: processes})
case 'CANCEL_PROCESS':
var processes = Object.assign({}, (ui.processes ? ui.processes : {}))
if (processes[action.key]){
processes[action.key] = Object.assign(
{},
processes[action.key],
{
cancelling: true
}
)
}
return Object.assign({}, ui, {processes: processes})
case 'STOP_PROCESS':