Skip to content

Commit

Permalink
Make toasts disabled by default, closes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhoefling committed Nov 29, 2015
1 parent 52dc90e commit a213aae
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
.vagrant
dist/molten
3 changes: 3 additions & 0 deletions app/ActionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ var getDocumentationFail = error => ({ type: Constants.GET_DOCUMENTATION_FAIL, e
var getDocumentationSuccess = (docType, documentation) =>
({ type: Constants.GET_DOCUMENTATION_SUCCESS, docType, documentation });

export const setSetting = (setting, value) => ({ type: Constants.SET_SETTING, setting, value });
export const clearSetting = setting => ({ type: Constants.CLEAR_SETTING, setting });

export const serverEventReceived = event => ({ type: Constants.SERVER_EVENT_RECEIVED, event });
export const clearEvents = () => ({ type: Constants.CLEAR_EVENTS });

Expand Down
3 changes: 3 additions & 0 deletions app/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export default {
GET_JOB_SUCCESS: 'GET_JOB_SUCCESS',
GET_JOB_FAIL: 'GET_JOB_FAIL',

SET_SETTING: 'SET_SETTING',
CLEAR_SETTING: 'CLEAR_SETTING',

TRANSITION: 'transition',

SERVER_EVENT_RECEIVED: 'SERVER_EVENT_RECEIVED',
Expand Down
2 changes: 1 addition & 1 deletion app/components/TabHeaders.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const TabHeaders = React.createClass({
<a href='https://github.com/martinhoefling/molten'>
<img title='open on github'
className={styles.github}
src={config.ASSET_BASE_URL + '/github.svg'}/>
src={config.ASSET_BASE_URL + '/contrib/github.svg'}/>
</a>
</div>
</div>
Expand Down
10 changes: 8 additions & 2 deletions app/containers/Toast.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ const EVENT_LIST = [

const Toast = React.createClass({
propTypes: {
events: React.PropTypes.array
enabled: React.PropTypes.bool.isRequired,
events: React.PropTypes.array.isRequired
},

publishEvent(event) {
Expand Down Expand Up @@ -113,12 +114,16 @@ const Toast = React.createClass({

componentWillReceiveProps(nextProps) {
var newEvents = nextProps.events.splice(this.props.events.length);
if (newEvents.length) {
if (newEvents.length && nextProps.enabled) {
newEvents.forEach(this.publishEvent);
}
},

render() {
if (!this.props.enabled) {
return null;
}

return (
<div>
<ToastContainer
Expand All @@ -132,6 +137,7 @@ const Toast = React.createClass({

function select(state) {
return {
enabled: !!state.Settings.eventsAsToasts,
events: state.Events.events
};
}
Expand Down
24 changes: 23 additions & 1 deletion app/containers/tabs/SettingsTab.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import React from 'react';
import { connect } from 'react-redux';
import { setSetting } from 'ActionCreators';

import RaisedButton from 'material-ui/lib/raised-button';
import Checkbox from 'material-ui/lib/checkbox';

import localStore from 'helpers/localstore';

import tabStyle from './Tab.less';

const SettingsTab = React.createClass({
propTypes: {
settings: React.PropTypes.object.isRequired,
setSetting: React.PropTypes.func.isRequired
},

render() {
return (
<div className={tabStyle.this}>
Expand All @@ -14,9 +23,22 @@ const SettingsTab = React.createClass({
primary={true}
onClick={() => localStore.clear() }
/>
<Checkbox
name='displayEventsAsToasts'
value='displayEventsAsToasts'
label='Display events as Toasts'
defaultChecked={this.props.settings.eventsAsToasts}
onCheck={(event, checked) => this.props.setSetting('eventsAsToasts', checked)}
/>
</div>
);
}
});

export default SettingsTab;
function select(state) {
return {
settings: state.Settings
};
}

export default connect(select, { setSetting })(SettingsTab);
16 changes: 16 additions & 0 deletions app/reducers/SettingsReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Constants from 'Constants';
import _ from 'lodash';

const initialState = {};

export default function sessionReducer(state = initialState, action) {
switch (action.type) {
case Constants.SET_SETTING:
return Object.assign({}, state, { [action.setting]: action.value });
case Constants.CLEAR_SETTING:
return _.omit(state, action.setting);
default:
return state;
}
}

3 changes: 2 additions & 1 deletion app/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import Events from 'reducers/EventReducer';
import Jobs from 'reducers/JobReducer';
import Documentation from 'reducers/DocumentationReducer';
import Minions from 'reducers/MinionReducer';
import Settings from 'reducers/SettingsReducer';
import routes from 'Routes';

const reducers = combineReducers({
Session, Capabilities, Commands, Events, Jobs, Documentation, Minions,
Session, Capabilities, Commands, Events, Jobs, Documentation, Minions, Settings,
router: routerStateReducer
});

Expand Down

0 comments on commit a213aae

Please sign in to comment.