Creating processes

This commit is contained in:
James Barnsley
2017-04-05 20:28:41 +12:00
parent 14509e6c8b
commit f292e512dc
8 changed files with 65 additions and 28 deletions

View File

@ -224,28 +224,21 @@ export function createBrowserNotification( data ){
}
}
export function createNotification(content, type = 'default', id = helpers.generateGuid()){
export function createNotification(content, type = 'default', key = helpers.generateGuid()){
return {
type: 'CREATE_NOTIFICATION',
notification: {
id: id,
key: key,
type: type,
content: content
}
}
}
export function cancelLoading(id){
return {
type: 'CANCEL_LOADING_'+id,
id: id
}
}
export function removeNotification(id){
export function removeNotification(key){
return {
type: 'REMOVE_NOTIFICATION',
id: id
key: key
}
}
@ -268,3 +261,24 @@ export function stopLoading(key){
key: key
}
}
export function startProcess(key){
return {
type: 'START_PROCESS',
key: key
}
}
export function cancelProcess(key){
return {
type: 'CANCEL_PROCESS',
key: key
}
}
export function stopProcess(key){
return {
type: 'STOP_PROCESS',
key: key
}
}

View File

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

View File

@ -711,16 +711,16 @@ export default function reducer(ui = {}, action){
case 'CREATE_NOTIFICATION':
var notifications = [...ui.notifications, action.notification]
notifications = helpers.mergeDuplicates(notifications,'id')
notifications = helpers.mergeDuplicates(notifications,'key')
return Object.assign({}, ui, { notifications: notifications })
case 'REMOVE_NOTIFICATION':
var notifications = Object.assign([], ui.notifications)
function getByID( notification ){
return notification.id === action.id
function getByKey( notification ){
return notification.key === action.key
}
var index = notifications.findIndex(getByID)
var index = notifications.findIndex(getByKey)
if( index > -1 ) notifications.splice(index, 1)
return Object.assign({}, ui, { notifications: notifications })
@ -728,7 +728,7 @@ export default function reducer(ui = {}, action){
/**
* Loader
* Loading and processes
**/
case 'START_LOADING':
@ -743,6 +743,18 @@ export default function reducer(ui = {}, action){
}
return Object.assign({}, ui, {load_queue: load_queue})
case 'START_PROCESS':
var processes = Object.assign({}, (ui.processes ? ui.processes : []))
processes[action.key] = 'active'
return Object.assign({}, ui, {processes: processes})
case 'STOP_PROCESS':
var processes = Object.assign({}, (ui.processes ? ui.processes : {}))
if (processes[action.key]){
delete processes[action.key]
}
return Object.assign({}, ui, {processes: processes})
default:
return ui