Skip to content

Commit 3f197cf

Browse files
committed
move alert into "alert" module
1 parent b5cf63b commit 3f197cf

35 files changed

+188
-78
lines changed

lib/actions/_types.js

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
"use strict";
2-
exports.ALERT_REPLAY = 'ALERT_REPLAY';
3-
exports.ALERT_OPEN = 'ALERT_OPEN';
4-
exports.ALERT_CLOSE = 'ALERT_CLOSE';
52
exports.COMPLETE_PAGE = 'COMPLETE_PAGE';
63
exports.COMPLETE_TUTORIAL = 'COMPLETE_TUTORIAL';
74
exports.DEVTOOLS_TOGGLE = 'DEVTOOLS_TOGGLE';

lib/actions/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use strict";
2-
var alert_1 = require('./alert');
3-
exports.alertOpen = alert_1.alertOpen;
4-
exports.alertClose = alert_1.alertClose;
5-
exports.alertReplay = alert_1.alertReplay;
2+
var actions_1 = require('../modules/alert/actions');
3+
exports.alertOpen = actions_1.alertOpen;
4+
exports.alertClose = actions_1.alertClose;
5+
exports.alertReplay = actions_1.alertReplay;
66
var progress_1 = require('./progress');
77
exports.progressLoad = progress_1.progressLoad;
88
exports.completePage = progress_1.completePage;

lib/actions/page.js

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function pageSet(pagePosition) {
1919
if (pagePosition === void 0) { pagePosition = 0; }
2020
return function (dispatch, getState) {
2121
var _a = getState(), dir = _a.dir, progress = _a.progress, tutorial = _a.tutorial, route = _a.route;
22-
console.log(pagePosition, dir, progress, tutorial, route);
2322
if (pagePosition >= progress.pages.length) {
2423
dispatch({ type: _types_1.ROUTE_SET, payload: { route: 'final' } });
2524
}

lib/actions/progress.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
var _types_1 = require('./_types');
3-
var alert_1 = require('./alert');
3+
var actions_1 = require('../modules/alert/actions');
44
var test_1 = require('./test');
55
function progressPagePositionLoad() {
66
return function (dispatch, getState) {
@@ -28,7 +28,7 @@ function completePage(completed) {
2828
dispatch(completeTutorial());
2929
}
3030
else {
31-
dispatch(alert_1.alertOpen({
31+
dispatch(actions_1.alertOpen({
3232
message: "Page " + (pagePosition + 1) + " Complete",
3333
action: 'PASS',
3434
}));
@@ -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.alertOpen({
48+
dispatch(actions_1.alertOpen({
4949
message: 'Tutorial Complete',
5050
action: 'PASS',
5151
}));

lib/actions/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var _types_1 = require('./_types');
33
var hint_1 = require('./hint');
44
var progress_1 = require('./progress');
5-
var alert_1 = require('./alert');
5+
var actions_1 = require('../modules/alert/actions');
66
function testRun() {
77
return function (dispatch, getState) {
88
var _a = getState(), taskTests = _a.taskTests, dir = _a.dir, tutorial = _a.tutorial, taskPosition = _a.taskPosition;
@@ -35,7 +35,7 @@ function testResult(result) {
3535
});
3636
}
3737
dispatch({ type: _types_1.TEST_RESULT, payload: { result: result, taskActions: taskActions } });
38-
dispatch(alert_1.alertOpen(alert));
38+
dispatch(actions_1.alertOpen(alert));
3939
};
4040
}
4141
exports.testResult = testResult;

lib/actions/tutorial.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +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');
5+
var actions_1 = require('../modules/alert/actions');
66
function tutorialSet(name) {
77
return function (dispatch, getState) {
88
var dir = getState().dir;
@@ -20,7 +20,7 @@ function tutorialUpdate(name) {
2020
duration: 3000,
2121
};
2222
dispatch({ type: _types_1.TUTORIAL_UPDATE, payload: { name: name } });
23-
dispatch(alert_1.alertOpen(alert));
23+
dispatch(actions_1.alertOpen(alert));
2424
};
2525
}
2626
exports.tutorialUpdate = tutorialUpdate;

lib/components/Page/ProgressBar/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var LinearProgress_1 = require('material-ui/LinearProgress');
44
var style = {
55
height: '10px',
66
position: 'relative',
7-
margin: '0',
7+
margin: '0px',
88
};
99
var ProgressBar = function (_a) {
1010
var taskPosition = _a.taskPosition, taskLength = _a.taskLength, completed = _a.completed;

lib/components/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
2-
var Alert_1 = require('./Alert');
3-
exports.Alert = Alert_1.default;
2+
var alert_1 = require('../modules/alert');
3+
exports.Alert = alert_1.Alert;
44
var AppMenu_1 = require('./AppMenu');
55
exports.AppMenu = AppMenu_1.default;
66
var FinalPage_1 = require('./FinalPage');

lib/modules/alert/Alert.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"use strict";
2+
var __extends = (this && this.__extends) || function (d, b) {
3+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4+
function __() { this.constructor = d; }
5+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6+
};
7+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
8+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11+
return c > 3 && r && Object.defineProperty(target, key, r), r;
12+
};
13+
var __metadata = (this && this.__metadata) || function (k, v) {
14+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
15+
};
16+
var React = require('react');
17+
var react_redux_1 = require('react-redux');
18+
var Snackbar_1 = require('material-ui/Snackbar');
19+
var actions_1 = require('./actions');
20+
var defaultAlert = {
21+
message: '',
22+
open: false,
23+
};
24+
var styles = {
25+
display: 'inline-block',
26+
margin: '0px 10px',
27+
};
28+
var Alert = (function (_super) {
29+
__extends(Alert, _super);
30+
function Alert() {
31+
_super.apply(this, arguments);
32+
}
33+
Alert.prototype.render = function () {
34+
var _a = this.props, alert = _a.alert, close = _a.close;
35+
var action = alert.action, message = alert.message, open = alert.open, duration = alert.duration, color = alert.color;
36+
return (React.createElement(Snackbar_1.default, {style: styles, bodyStyle: { color: color }, open: open, message: message || '', action: action || '', autoHideDuration: duration || 2000, onRequestClose: close}));
37+
};
38+
Alert = __decorate([
39+
react_redux_1.connect(null, function (dispatch) {
40+
return {
41+
close: function () { return dispatch(actions_1.alertClose()); }
42+
};
43+
}),
44+
__metadata('design:paramtypes', [])
45+
], Alert);
46+
return Alert;
47+
}(React.Component));
48+
Object.defineProperty(exports, "__esModule", { value: true });
49+
exports.default = Alert;

lib/modules/alert/actions.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
var types_1 = require('./types');
3+
function alertOpen(alert) {
4+
return function (dispatch, getState) {
5+
dispatch({ type: types_1.ALERT_OPEN, payload: { alert: alert } });
6+
};
7+
}
8+
exports.alertOpen = alertOpen;
9+
function alertReplay() {
10+
return { type: types_1.ALERT_REPLAY };
11+
}
12+
exports.alertReplay = alertReplay;
13+
function alertClose() {
14+
return { type: types_1.ALERT_CLOSE };
15+
}
16+
exports.alertClose = alertClose;

lib/modules/alert/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
var reducer_1 = require('./reducer');
3+
exports.reducer = reducer_1.default;
4+
var Alert_1 = require('./Alert');
5+
exports.Alert = Alert_1.default;

lib/modules/alert/reducer.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use strict";
2+
var types_1 = require('./types');
3+
var colors = {
4+
PASS: '#73C990',
5+
FAIL: '#FF4081',
6+
NOTE: '#9DA5B4',
7+
};
8+
var _alert = {
9+
message: '',
10+
open: false,
11+
action: 'NOTE',
12+
duration: 1500,
13+
color: colors.NOTE
14+
};
15+
var open = {
16+
open: true,
17+
action: 'NOTE',
18+
duration: 1500
19+
};
20+
var current = _alert;
21+
function setAlert(a) {
22+
a.color = colors[a.action] || colors.NOTE;
23+
var statusBarAlert = document.getElementsByClassName('cr-alert-replay')[0];
24+
statusBarAlert.style.color = a.color;
25+
current = a;
26+
return Object.assign({}, open, a);
27+
}
28+
function alert(alert, action) {
29+
if (alert === void 0) { alert = _alert; }
30+
switch (action.type) {
31+
case types_1.ALERT_REPLAY:
32+
return setAlert(current);
33+
case types_1.ALERT_OPEN:
34+
return setAlert(action.payload.alert);
35+
case types_1.ALERT_CLOSE:
36+
return Object.assign({}, alert, { open: false });
37+
default:
38+
return alert;
39+
}
40+
}
41+
Object.defineProperty(exports, "__esModule", { value: true });
42+
exports.default = alert;

lib/modules/alert/types.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
exports.ALERT_REPLAY = 'ALERT_REPLAY';
3+
exports.ALERT_OPEN = 'ALERT_OPEN';
4+
exports.ALERT_CLOSE = 'ALERT_CLOSE';

lib/reducers/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
var redux_1 = require('redux');
3-
var alert_1 = require('./alert');
3+
var alert_1 = require('../modules/alert');
44
var checks_1 = require('./checks');
55
var devTools_toggle_1 = require('./devTools-toggle');
66
var dir_1 = require('./dir');
@@ -20,7 +20,7 @@ var tutorial_list_1 = require('./tutorial-list');
2020
var window_toggle_1 = require('./window-toggle');
2121
Object.defineProperty(exports, "__esModule", { value: true });
2222
exports.default = redux_1.combineReducers({
23-
alert: alert_1.default, checks: checks_1.default, devToolsToggle: devTools_toggle_1.default, dir: dir_1.default, hintPosition: hint_position_1.default,
23+
alert: alert_1.reducer, checks: checks_1.default, devToolsToggle: devTools_toggle_1.default, dir: dir_1.default, hintPosition: hint_position_1.default,
2424
packageJson: package_json_1.default, page: page_1.default, pagePosition: page_position_1.default, progress: progress_1.default, route: route_1.default, tasks: tasks_1.default,
2525
tutorial: tutorial_1.default, tutorialList: tutorial_list_1.default,
2626
taskActions: task_actions_1.default, taskPosition: task_position_1.default, taskTests: task_tests_1.default, testRun: test_run_1.default, windowToggle: window_toggle_1.default

lib/store/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var reducers_1 = require('../reducers');
44
var createLogger = require('redux-logger');
55
var redux_thunk_1 = require('redux-thunk');
66
var middlewares = [redux_thunk_1.default];
7-
var devMode = true;
7+
var devMode = false;
88
if (devMode) {
99
var logger = createLogger();
1010
middlewares.push(logger);

src/actions/_types.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
export const ALERT_REPLAY = 'ALERT_REPLAY';
2-
export const ALERT_OPEN = 'ALERT_OPEN';
3-
export const ALERT_CLOSE = 'ALERT_CLOSE';
41
export const COMPLETE_PAGE = 'COMPLETE_PAGE';
52
export const COMPLETE_TUTORIAL = 'COMPLETE_TUTORIAL';
63
export const DEVTOOLS_TOGGLE = 'DEVTOOLS_TOGGLE';

src/actions/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export {alertOpen, alertClose, alertReplay} from './alert';
1+
export {alertOpen, alertClose, alertReplay} from '../modules/alert/actions';
22
export {
33
progressLoad, completePage, completeTutorial,
44
progressPagePositionLoad

src/actions/page.ts

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export function pageNext(): ReduxThunk.ThunkInterface | Action {
2020
export function pageSet(pagePosition = 0): ReduxThunk.ThunkInterface {
2121
return (dispatch, getState): void => {
2222
const {dir, progress, tutorial, route} = getState();
23-
console.log(pagePosition, dir, progress, tutorial, route);
2423

2524
// routes
2625
if (pagePosition >= progress.pages.length) {

src/actions/progress.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
PROGRESS_PAGE_POSITION_LOAD, PROGRESS_LOAD, COMPLETE_PAGE, COMPLETE_TUTORIAL
33
} from './_types';
4-
import {alertOpen} from './alert';
4+
import {alertOpen} from '../modules/alert/actions';
55
import {testRun} from './test';
66

77
export function progressPagePositionLoad(): ReduxThunk.ThunkInterface {

src/actions/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
} from './_types';
44
import {hintPositionSet} from './hint';
55
import {completePage} from './progress';
6-
import {alertOpen} from './alert';
6+
import {alertOpen} from '../modules/alert/actions';
77

88
export function testRun(): ReduxThunk.ThunkInterface {
99
return (dispatch, getState): void => {

src/actions/tutorial.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
} from './_types';
44
import {progressLoad} from './progress';
55
import {routeSet} from './route';
6-
import {alertOpen} from './alert';
6+
import {alertOpen} from '../modules/alert/actions';
77

88
export function tutorialSet(name: string): ReduxThunk.ThunkInterface {
99
return (dispatch, getState) => {

src/components/Alert/_alert.less

-14
This file was deleted.

src/components/Page/ProgressBar/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import LinearProgress from 'material-ui/LinearProgress';
44
const style = {
55
height: '10px',
66
position: 'relative',
7-
margin: '0',
7+
margin: '0px',
88
};
99

1010
const ProgressBar: React.StatelessComponent<{

src/components/index.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// import {components} from 'coderoad-core';
2-
3-
export {default as Alert} from './Alert';
1+
export {Alert} from '../modules/alert';
42
export {default as AppMenu} from './AppMenu';
53
export {default as FinalPage} from './FinalPage';
64
export {default as Page} from './Page';
@@ -11,7 +9,3 @@ export {default as Tutorials} from './Tutorials';
119
export {default as Markdown} from './common/Markdown';
1210
export {default as RouteButton} from './common/RouteButton';
1311
export {default as ContentCard} from './common/ContentCard';
14-
15-
// export const ContentCard = components.ContentCard;
16-
// export const Markdown = components.Markdown;
17-
// export const RouteButton = components.RouteButton;

src/components/styles/index.less

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@import 'ui-variables';
22
@import '../AppMenu/_app-menu';
3-
@import '../Alert/_alert';
43
#crv {
54
position: relative;
65
overflow-y: scroll;

src/components/Alert/index.tsx renamed to src/modules/alert/Alert.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import * as React from 'react';
22
import {connect} from 'react-redux';
33
import Snackbar from 'material-ui/Snackbar';
4-
import {alertClose} from '../../actions';
4+
import {alertClose} from './actions';
55

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

11+
const styles = {
12+
display: 'inline-block',
13+
margin: '0px 10px',
14+
};
15+
1116
@connect(null, dispatch => {
1217
return {
1318
close: () => dispatch(alertClose())
@@ -18,13 +23,14 @@ export default class Alert extends React.Component<{
1823
}, {}> {
1924
render() {
2025
const {alert, close} = this.props;
21-
const {action, message, open, duration} = alert;
26+
const {action, message, open, duration, color} = alert;
2227
return (
2328
<Snackbar
24-
className={`cr-alert ${action}`}
29+
style={styles}
30+
bodyStyle={{color}}
2531
open={open}
2632
message={message || ''}
27-
action={action || 'NOTE'}
33+
action={action || ''}
2834
autoHideDuration={duration || 2000}
2935
onRequestClose={close}
3036
/>

0 commit comments

Comments
 (0)