From 8c5f7083867db4b8a5f3411bd86ed762e709642e Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Mon, 8 Apr 2019 00:57:32 +0200 Subject: [PATCH] Add notification when merging changes into the tree --- app/src/actions/Global.ts | 8 ++++++-- app/src/actions/Tree.ts | 15 +++++++++++++-- app/src/components/App.tsx | 22 +++++++++++++++------- app/src/components/Layout/Notification.tsx | 5 +++-- app/src/reducers/index.ts | 10 ++++++++++ 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/app/src/actions/Global.ts b/app/src/actions/Global.ts index f23ecc7..79cf6c2 100644 --- a/app/src/actions/Global.ts +++ b/app/src/actions/Global.ts @@ -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, }) diff --git a/app/src/actions/Tree.ts b/app/src/actions/Tree.ts index 655ba75..14301de 100644 --- a/app/src/actions/Tree.ts +++ b/app/src/actions/Tree.ts @@ -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) => (dispatch: Dispatch, getState: () => AppState) => { @@ -58,10 +59,20 @@ export const showTree = (tree?: q.Tree) => (dispatch: Dispatch) => (dispatch: Dispatch, getState: () => AppState): AnyAction => { +export const togglePause = (tree?: q.Tree) => (dispatch: Dispatch, 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.`)) + } } diff --git a/app/src/components/App.tsx b/app/src/components/App.tsx index 7375db0..69448fe 100644 --- a/app/src/components/App.tsx +++ b/app/src/components/App.tsx @@ -19,6 +19,7 @@ interface Props { classes: any settingsVisible: boolean error?: string + notification?: string actions: typeof globalActions settingsActions: typeof settingsActions launching: boolean @@ -30,16 +31,22 @@ class App extends React.PureComponent { this.state = { } } - private renderError() { - if (this.props.error) { - const error = typeof this.props.error === 'string' ? this.props.error : JSON.stringify(this.props.error) + private renderNotification() { + const message = this.props.error || this.props.notification + const isError = message === this.props.error + if (message) { + // Guard in case someone ever calls showError with an error instead of a string + const str = typeof message === 'string' ? message : JSON.stringify(message) return ( { this.props.actions.showError(undefined) }} + message={str} + type={isError ? 'error' : 'notification'} + onClose={() => { isError ? this.props.actions.showError(undefined) : this.props.actions.showNotification(undefined) }} /> ) } + + return null } public componentDidMount() { @@ -58,13 +65,13 @@ class App extends React.PureComponent {
- {this.renderError()} + {this.renderNotification()} Loading...
}>
- +
Loading...
}> @@ -134,6 +141,7 @@ const mapStateToProps = (state: AppState) => { settingsVisible: state.settings.get('visible'), connectionId: state.connection.connectionId, error: state.globalState.error, + notification: state.globalState.notification, highlightTopicUpdates: state.settings.get('highlightTopicUpdates'), launching: state.globalState.launching, } diff --git a/app/src/components/Layout/Notification.tsx b/app/src/components/Layout/Notification.tsx index 4d3e49a..b0a99ae 100644 --- a/app/src/components/Layout/Notification.tsx +++ b/app/src/components/Layout/Notification.tsx @@ -6,6 +6,7 @@ import { green, red } from '@material-ui/core/colors' interface Props { message?: string + type: 'error' | 'notification' onClose: () => void classes: any } @@ -16,7 +17,7 @@ class Notification extends React.Component { } public static styles = (theme: Theme) => ({ - success: { + notification: { backgroundColor: green[600], color: theme.typography.button.color, }, @@ -40,7 +41,7 @@ class Notification extends React.Component { onClose={this.props.onClose} > diff --git a/app/src/reducers/index.ts b/app/src/reducers/index.ts index b73ef10..c3a6f44 100644 --- a/app/src/reducers/index.ts +++ b/app/src/reducers/index.ts @@ -11,6 +11,7 @@ export enum ActionTypes { showUpdateNotification = 'SHOW_UPDATE_NOTIFICATION', showUpdateDetails = 'SHOW_UPDATE_DETAILS', showError = 'SHOW_ERROR', + showNotification = 'SHOW_NOTIFICATION', didLaunch = 'DID_LAUNCH', } @@ -19,6 +20,7 @@ export interface CustomAction extends Action { showUpdateNotification?: boolean showUpdateDetails?: boolean error?: string + notification?: string } export interface AppState { @@ -34,6 +36,7 @@ export interface GlobalState { showUpdateNotification?: boolean showUpdateDetails: boolean error?: string + notification?: string launching: boolean } @@ -61,6 +64,13 @@ const globalState: Reducer = (state = ini error: action.error, } + case ActionTypes.showNotification: + console.log(action) + return { + ...state, + notification: action.notification, + } + case ActionTypes.didLaunch: return { ...state,