Skip to content

Commit 693b36f

Browse files
committed
refactor alert
1 parent 9d02a1a commit 693b36f

File tree

16 files changed

+39
-41
lines changed

16 files changed

+39
-41
lines changed

lib/actions/progress.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function completeTutorial(completed) {
4545
return function (dispatch, getState) {
4646
var tutorial = getState().tutorial;
4747
dispatch({ type: _types_1.COMPLETE_TUTORIAL, payload: { tutorial: tutorial, completed: completed } });
48-
dispatch(alert_1.alertToggle({
48+
dispatch('ALER'({
4949
message: 'Tutorial Complete',
5050
action: 'PASS',
5151
}));

lib/actions/tutorial.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var _types_1 = require('./_types');
33
var progress_1 = require('./progress');
44
var route_1 = require('./route');
5+
var alert_1 = require('./alert');
56
function tutorialSet(name) {
67
return function (dispatch, getState) {
78
var dir = getState().dir;
@@ -16,10 +17,10 @@ function tutorialUpdate(name) {
1617
var alert = {
1718
message: "run `npm install --save-dev " + name + "`",
1819
action: 'note',
19-
duration: 4000,
20+
duration: 3000,
2021
};
2122
dispatch({ type: _types_1.TUTORIAL_UPDATE, payload: { name: name } });
22-
dispatch({ type: _types_1.ALERT_TOGGLE, payload: { alert: alert } });
23+
dispatch(alert_1.alertToggle(alert));
2324
};
2425
}
2526
exports.tutorialUpdate = tutorialUpdate;

lib/components/Alert/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
1515
};
1616
var React = require('react');
1717
var react_redux_1 = require('react-redux');
18-
var actions_1 = require('../../actions');
1918
var Snackbar_1 = require('material-ui/Snackbar');
19+
var actions_1 = require('../../actions');
2020
var defaultAlert = {
2121
message: '',
2222
open: false,
@@ -28,13 +28,13 @@ var Alert = (function (_super) {
2828
}
2929
Alert.prototype.render = function () {
3030
var _a = this.props, alert = _a.alert, alertToggle = _a.alertToggle;
31-
var action = alert.action, open = alert.open, message = alert.message, duration = alert.duration;
32-
return (React.createElement(Snackbar_1.default, {className: "cr-alert " + action, open: open || false, message: message || '', action: action, autoHideDuration: duration || 2000, onActionTouchTap: alertToggle, onRequestClose: alertToggle}));
31+
var action = alert.action, message = alert.message, open = alert.open, duration = alert.duration;
32+
return (React.createElement(Snackbar_1.default, {className: "cr-alert " + action, open: open, message: message || '', action: action || 'NOTE', autoHideDuration: duration || 2000, onRequestClose: alertToggle}));
3333
};
3434
Alert = __decorate([
3535
react_redux_1.connect(null, function (dispatch) {
3636
return {
37-
alertToggle: function () { return dispatch(actions_1.alertToggle()); },
37+
alertToggle: function () { return dispatch(actions_1.alertToggle({ open: false })); }
3838
};
3939
}),
4040
__metadata('design:paramtypes', [])

lib/reducers/alert/index.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ function alertReducer(alert, action) {
2929
case _types_1.ALERT_REPLAY:
3030
return setAlert(current);
3131
case _types_1.ALERT_TOGGLE:
32-
var a = action.payload.alert;
33-
if (!a) {
34-
return _alert;
35-
}
36-
return setAlert(a);
32+
return setAlert(action.payload.alert);
3733
default:
3834
return alert;
3935
}

lib/store/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ var redux_1 = require('redux');
33
var redux_action_thunk_1 = require('redux-action-thunk');
44
var reducers_1 = require('../reducers');
55
var createLogger = require('redux-logger');
6-
var redux_thunk_1 = require('redux-thunk');
7-
var middlewares = [redux_action_thunk_1.ratMiddleware, redux_thunk_1.default];
8-
var devMode = false;
6+
var middlewares = [redux_action_thunk_1.ratMiddleware];
7+
var devMode = true;
98
if (devMode) {
109
var logger = createLogger();
1110
middlewares.push(logger);

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
"react-redux": "4.4.5",
4747
"react-tap-event-plugin": "1.0.0",
4848
"redux": "3.5.2",
49-
"redux-action-thunk": "0.1.0",
49+
"redux-action-thunk": "0.3.0",
5050
"redux-logger": "2.6.1",
51-
"redux-thunk": "^2.1.0"
51+
"redux-thunk": "2.1.0"
5252
},
5353
"scripts": {
5454
"compile": "tsc"

src/actions/alert.ts

+8
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ export function alertToggle(alert: Object): ReduxThunk.ThunkInterface {
99
export function alertReplay(): Action {
1010
return { type: ALERT_REPLAY };
1111
}
12+
13+
// import {rat} from 'redux-action-thunk';
14+
//
15+
// rat.add('ALERT_TOGGLE', (dispatch, getState) => (alert) => {
16+
// dispatch({ type: 'ALERT_TOGGLE', payload: { alert } });
17+
// });
18+
//
19+
// rat.add('ALERT_REPLAY');

src/actions/hint.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {HINT_SHOW, HINT_POSITION_SET} from './_types';
1+
import {HINT_POSITION_SET} from './_types';
22

33
export function hintPositionSet(hintPosition: number): Action {
44
return {type: HINT_POSITION_SET, payload: { hintPosition } };

src/actions/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export {alertToggle, alertReplay} from './alert';
2+
// import './alert';
23
export {
34
progressLoad, completePage, completeTutorial,
45
progressPagePositionLoad

src/actions/progress.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function completeTutorial(completed = true): ReduxThunk.ThunkInterface {
4545
return (dispatch, getState): void => {
4646
const {tutorial} = getState();
4747
dispatch({ type: COMPLETE_TUTORIAL, payload: { tutorial, completed } });
48-
dispatch(alertToggle({
48+
dispatch('ALER'({
4949
message: 'Tutorial Complete',
5050
action: 'PASS',
5151
}));

src/actions/tutorial.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
2-
TUTORIALS_FIND, TUTORIAL_UPDATE, TUTORIAL_SET,
3-
ALERT_TOGGLE
2+
TUTORIALS_FIND, TUTORIAL_UPDATE, TUTORIAL_SET
43
} from './_types';
54
import {progressLoad} from './progress';
65
import {routeSet} from './route';
6+
import {alertToggle} from './alert';
77

88
export function tutorialSet(name: string): ReduxThunk.ThunkInterface {
99
return (dispatch, getState): void => {
@@ -19,10 +19,10 @@ export function tutorialUpdate(name: string): ReduxThunk.ThunkInterface {
1919
const alert = {
2020
message: `run \`npm install --save-dev ${name}\``,
2121
action: 'note',
22-
duration: 4000,
22+
duration: 3000,
2323
};
2424
dispatch({ type: TUTORIAL_UPDATE, payload: { name } });
25-
dispatch({ type: ALERT_TOGGLE, payload: { alert } });
25+
dispatch(alertToggle(alert));
2626
};
2727
}
2828

src/components/Alert/index.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
import * as React from 'react';
22
import {connect} from 'react-redux';
3-
import {alertToggle} from '../../actions';
43
import Snackbar from 'material-ui/Snackbar';
4+
import {alertToggle} from '../../actions';
55

66
const defaultAlert = {
77
message: '',
88
open: false,
99
};
1010

11-
@connect(null, (dispatch) => {
11+
@connect(null, dispatch => {
1212
return {
13-
alertToggle: () => dispatch(alertToggle()),
13+
alertToggle: () => dispatch(alertToggle({open: false}))
1414
};
1515
})
1616
export default class Alert extends React.Component<{
1717
alert: CR.Alert, alertToggle?: any
1818
}, {}> {
1919
render() {
2020
const {alert, alertToggle} = this.props;
21-
const {action, open, message, duration} = alert;
21+
const {action, message, open, duration} = alert;
2222
return (
2323
<Snackbar
2424
className={`cr-alert ${action}`}
25-
open={open || false}
25+
open={open}
2626
message={message || ''}
27-
action={action}
27+
action={action || 'NOTE'}
2828
autoHideDuration={duration || 2000}
29-
onActionTouchTap={alertToggle}
3029
onRequestClose={alertToggle}
3130
/>
3231
);

src/components/Common/RouteButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {connect} from 'react-redux';
33
import {routeSet} from '../../actions';
44
import RaisedButton from 'material-ui/RaisedButton';
55

6-
@connect(null, (dispatch) => {
6+
@connect(null, dispatch => {
77
return {
88
routeTo: (route: string) => dispatch(routeSet(route)),
99
};

src/reducers/alert/index.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ export default function alertReducer(
4141
return setAlert(current);
4242

4343
case ALERT_TOGGLE:
44-
const a = action.payload.alert;
45-
46-
if (!a) {
47-
// close alert
48-
return _alert;
49-
}
50-
return setAlert(a);
44+
return setAlert(action.payload.alert);
5145

5246
default:
5347
return alert;

src/reducers/tutorial-list/update.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import commandLine from '../../services/command-line';
2-
import {alertToggle} from '../../actions';
2+
// import {alertToggle} from '../../actions';
33
import {tutorialsFind} from '../../actions';
44

55
export function tutorialUpdate(name: string): void {

src/store/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as createLogger from 'redux-logger';
55
import thunk from 'redux-thunk';
66

77
// const middlewares = [ramMiddleware];
8-
const middlewares = [ratMiddleware, thunk];
8+
const middlewares = [ratMiddleware];
99

10-
const devMode = false;
10+
const devMode = true;
1111
if (devMode) {
1212
const logger = createLogger();
1313
middlewares.push(logger);

0 commit comments

Comments
 (0)