Add notification when merging changes into the tree

This commit is contained in:
Thomas Nordquist
2019-04-08 00:57:32 +02:00
parent 436b569e93
commit 8c5f708386
5 changed files with 47 additions and 13 deletions

View File

@@ -1,11 +1,15 @@
import { ActionTypes, AppState, CustomAction } from '../reducers'
import { Dispatch } from 'redux'
import { ActionTypes } from '../reducers'
export const showError = (error?: string) => ({
error,
type: ActionTypes.showError,
})
export const showNotification = (notification?: string) => ({
notification,
type: ActionTypes.showNotification,
})
export const didLaunch = () => ({
type: ActionTypes.didLaunch,
})

View File

@@ -5,6 +5,7 @@ import { AppState } from '../reducers'
import { batchActions } from 'redux-batched-actions'
import { setTopic } from './Publish'
import { TopicViewModel } from '../model/TopicViewModel'
import { globalActions } from '.';
const debounce = require('lodash.debounce')
export const selectTopic = (topic: q.TreeNode<TopicViewModel>) => (dispatch: Dispatch<any>, getState: () => AppState) => {
@@ -58,10 +59,20 @@ export const showTree = (tree?: q.Tree<TopicViewModel>) => (dispatch: Dispatch<a
})
}
export const togglePause = (tree?: q.Tree<TopicViewModel>) => (dispatch: Dispatch<any>, getState: () => AppState): AnyAction => {
export const togglePause = (tree?: q.Tree<TopicViewModel>) => (dispatch: Dispatch<any>, getState: () => AppState) => {
const paused = getState().tree.paused
const tree = getState().tree.tree
const changes = tree ? tree.unmergedChanges().length : 0
return dispatch({
if (paused && changes > 0) {
dispatch(globalActions.showNotification('Applying recorded changes.'))
}
dispatch({
type: paused ? ActionTypes.TREE_RESUME_UPDATES : ActionTypes.TREE_PAUSE_UPDATES,
})
if (paused && changes > 0) {
dispatch(globalActions.showNotification(`Sucessfully applied ${changes} changes.`))
}
}