Skip to content

Commit 2b4831a

Browse files
committed
return alert to atom-coderoad
1 parent 0e3a140 commit 2b4831a

File tree

18 files changed

+264
-30
lines changed

18 files changed

+264
-30
lines changed

lib/actions.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
"use strict";
2-
var actions_1 = require('./modules/hints/actions');
3-
exports.hintPositionSet = actions_1.hintPositionSet;
4-
var actions_2 = require('./modules/page/actions');
5-
exports.pageSet = actions_2.pageSet;
6-
exports.pageNext = actions_2.pageNext;
7-
var actions_3 = require('./modules/progress/actions');
8-
exports.progressLoad = actions_3.progressLoad;
9-
exports.progressCompletePage = actions_3.progressCompletePage;
10-
var actions_4 = require('./modules/tests/actions');
11-
exports.testRun = actions_4.testRun;
12-
exports.testResult = actions_4.testResult;
13-
exports.testComplete = actions_4.testComplete;
14-
var actions_5 = require('./modules/setup/actions');
15-
exports.setupVerify = actions_5.setupVerify;
16-
exports.setupPackage = actions_5.setupPackage;
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;
6+
var actions_2 = require('./modules/hints/actions');
7+
exports.hintPositionSet = actions_2.hintPositionSet;
8+
var actions_3 = require('./modules/page/actions');
9+
exports.pageSet = actions_3.pageSet;
10+
exports.pageNext = actions_3.pageNext;
11+
var actions_4 = require('./modules/progress/actions');
12+
exports.progressLoad = actions_4.progressLoad;
13+
exports.progressCompletePage = actions_4.progressCompletePage;
14+
var actions_5 = require('./modules/tests/actions');
15+
exports.testRun = actions_5.testRun;
16+
exports.testResult = actions_5.testResult;
17+
exports.testComplete = actions_5.testComplete;
18+
var actions_6 = require('./modules/setup/actions');
19+
exports.setupVerify = actions_6.setupVerify;
20+
exports.setupPackage = actions_6.setupPackage;
1721
var tutorial_1 = require('./modules/tutorial');
1822
exports.tutorialSet = tutorial_1.tutorialSet;
1923
var tutorials_1 = require('./modules/tutorials');
2024
exports.tutorialsFind = tutorials_1.tutorialsFind;
2125
exports.tutorialUpdate = tutorials_1.tutorialUpdate;
2226
var core_coderoad_1 = require('core-coderoad');
23-
exports.alertOpen = core_coderoad_1.alertOpen;
24-
exports.alertClose = core_coderoad_1.alertClose;
25-
exports.alertReplay = core_coderoad_1.alertReplay;
2627
exports.editorDevToolsToggle = core_coderoad_1.editorDevToolsToggle;
2728
exports.editorOpen = core_coderoad_1.editorOpen;
2829
exports.editorInsert = core_coderoad_1.editorInsert;

lib/components/Alert/index.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
action: 'NOTE',
24+
};
25+
var styles = {
26+
display: 'inline-block',
27+
margin: '0px 10px',
28+
};
29+
var Alert = (function (_super) {
30+
__extends(Alert, _super);
31+
function Alert() {
32+
_super.apply(this, arguments);
33+
}
34+
Alert.prototype.render = function () {
35+
var _a = this.props, alert = _a.alert, alertClose = _a.alertClose;
36+
var action = alert.action, message = alert.message, open = alert.open, duration = alert.duration, color = alert.color;
37+
return (React.createElement(Snackbar_1.default, {style: styles, bodyStyle: { color: color }, open: open, action: action || 'NOTE', message: message || '', autoHideDuration: duration || 2000, onActionTouchTap: alertClose, onRequestClose: alertClose}));
38+
};
39+
Alert = __decorate([
40+
react_redux_1.connect(function (state) { return ({
41+
alert: state.alert || defaultAlert,
42+
}); }, { alertClose: actions_1.alertClose }),
43+
__metadata('design:paramtypes', [])
44+
], Alert);
45+
return Alert;
46+
}(React.Component));
47+
Object.defineProperty(exports, "__esModule", { value: true });
48+
exports.default = Alert;

lib/components/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"use strict";
22
var core_coderoad_1 = require('core-coderoad');
3-
exports.Alert = core_coderoad_1.Alert;
43
exports.Markdown = core_coderoad_1.Markdown;
4+
var Alert_1 = require('./Alert');
5+
exports.Alert = Alert_1.default;
56
var AppMenu_1 = require('./AppMenu');
67
exports.AppMenu = AppMenu_1.default;
78
var FinalPage_1 = require('./FinalPage');

lib/modules/alert/actions.js

Lines changed: 16 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
var reducer_1 = require('./reducer');
3+
exports.reducer = reducer_1.default;
4+
var actions_1 = require('./actions');
5+
exports.alertOpen = actions_1.alertOpen;
6+
exports.alertClose = actions_1.alertClose;
7+
exports.alertReplay = actions_1.alertReplay;

lib/modules/alert/reducer.js

Lines changed: 42 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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/modules/tests/test-run/run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ function runTaskTests(taskTests, dir, tutorial, taskPosition) {
55
var tests = taskTests;
66
if (tests && tests.length) {
77
var tutorialConfig = tutorial.config;
8-
var output = parse_loaders_1.default(tests, tutorialConfig.testSuffix, tutorial, dir);
8+
var testString = parse_loaders_1.default(tests, tutorialConfig.testSuffix, tutorial, dir);
99
var config = {
1010
dir: dir,
1111
tutorialDir: tutorialConfig.dir,
1212
taskPosition: taskPosition
1313
};
14-
tutorialConfig.run(output, config, handle_result_1.default);
14+
tutorialConfig.run({ testString: testString, config: config, handleResult: handle_result_1.default });
1515
}
1616
return true;
1717
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
},
3131
"dependencies": {
3232
"atom-plugin-command-line": "1.0.2",
33-
"coderoad-cli": "0.6.0",
34-
"core-coderoad": "0.4.0",
35-
"material-ui": "0.15.0",
33+
"coderoad-cli": "0.7.1",
34+
"core-coderoad": "0.5.0",
35+
"material-ui": "0.15.1",
3636
"node-file-exists": "1.1.0",
3737
"react": "15.1.0",
3838
"react-dom": "15.1.0",

src/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export {alertOpen, alertClose, alertReplay} from './modules/alert/actions';
12
export {hintPositionSet} from './modules/hints/actions';
23
export {pageSet, pageNext} from './modules/page/actions';
34
export {progressLoad, progressCompletePage} from './modules/progress/actions';
@@ -7,7 +8,6 @@ export {tutorialSet} from './modules/tutorial';
78
export {tutorialsFind, tutorialUpdate} from './modules/tutorials';
89

910
export {
10-
alertOpen, alertClose, alertReplay,
1111
editorDevToolsToggle, editorOpen, editorInsert,
1212
editorSave, editorSet,
1313
routeSet,

src/components/Alert/index.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as React from 'react';
2+
import {connect} from 'react-redux';
3+
import Snackbar from 'material-ui/Snackbar';
4+
import {alertClose} from '../../actions';
5+
6+
const defaultAlert = {
7+
message: '',
8+
open: false,
9+
action: 'NOTE',
10+
};
11+
12+
const styles = {
13+
display: 'inline-block',
14+
margin: '0px 10px',
15+
};
16+
17+
@connect(state => ({
18+
alert: state.alert || defaultAlert,
19+
}), {alertClose})
20+
export default class Alert extends React.Component<{
21+
alert?: CR.Alert, alertClose?: () => Redux.ActionCreator
22+
}, {}> {
23+
render() {
24+
const {alert, alertClose} = this.props;
25+
const {action, message, open, duration, color} = alert;
26+
return (
27+
<Snackbar
28+
style={styles}
29+
bodyStyle={{color}}
30+
open={open}
31+
action={action || 'NOTE'}
32+
message={message || ''}
33+
autoHideDuration={duration || 2000}
34+
onActionTouchTap={alertClose}
35+
onRequestClose={alertClose}
36+
/>
37+
);
38+
}
39+
}
40+
41+
// action={action || ''} removed from Snackbar as of Material 0.15.1 due to bug

src/components/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
export {
2-
Alert, Markdown
3-
} from 'core-coderoad';
1+
export {Markdown} from 'core-coderoad';
42

3+
export {default as Alert} from './Alert';
54
export {default as AppMenu} from './AppMenu';
65
export {default as FinalPage} from './FinalPage';
76
export {default as Page} from './Page';

src/modules/alert/actions.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {ALERT_REPLAY, ALERT_OPEN, ALERT_CLOSE} from './types';
2+
3+
export function alertOpen(alert: Object): ReduxThunk.ThunkInterface {
4+
return (dispatch, getState): void => {
5+
dispatch({ type: ALERT_OPEN, payload: { alert } });
6+
};
7+
}
8+
9+
export function alertReplay(): Action {
10+
return { type: ALERT_REPLAY };
11+
}
12+
13+
export function alertClose(): Action {
14+
return { type: ALERT_CLOSE };
15+
}

src/modules/alert/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export {default as reducer} from './reducer';
2+
export {alertOpen, alertClose, alertReplay} from './actions';

src/modules/alert/reducer.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {ALERT_REPLAY, ALERT_OPEN, ALERT_CLOSE} from './types';
2+
3+
const colors = {
4+
PASS: '#73C990', // green
5+
FAIL: '#FF4081', // red
6+
NOTE: '#9DA5B4', // blue
7+
};
8+
9+
const _alert: CR.Alert = {
10+
message: '',
11+
open: false,
12+
action: 'NOTE',
13+
duration: 1500,
14+
color: colors.NOTE
15+
};
16+
17+
const open = {
18+
open: true,
19+
action: 'NOTE',
20+
duration: 1500
21+
};
22+
23+
let current: CR.Alert = _alert;
24+
25+
function setAlert(a: CR.Alert): CR.Alert {
26+
a.color = colors[a.action] || colors.NOTE;
27+
let statusBarAlert = <HTMLElement>document.getElementsByClassName('cr-alert-replay')[0];
28+
statusBarAlert.style.color = a.color;
29+
current = a;
30+
return Object.assign({}, open, a);
31+
}
32+
33+
export default function alert(
34+
alert = _alert, action: Action
35+
): CR.Alert {
36+
switch (action.type) {
37+
38+
case ALERT_REPLAY:
39+
return setAlert(current);
40+
41+
case ALERT_OPEN:
42+
return setAlert(action.payload.alert);
43+
44+
case ALERT_CLOSE:
45+
return Object.assign({}, alert, { open: false });
46+
47+
default:
48+
return alert;
49+
}
50+
}

src/modules/alert/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const ALERT_REPLAY = 'ALERT_REPLAY';
2+
export const ALERT_OPEN = 'ALERT_OPEN';
3+
export const ALERT_CLOSE = 'ALERT_CLOSE';

src/modules/tests/test-run/run.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function runTaskTests(
99

1010
if (tests && tests.length) {
1111
const tutorialConfig: Tutorial.Config = tutorial.config;
12-
const output = parseLoaders(
12+
const testString = parseLoaders(
1313
tests, tutorialConfig.testSuffix, tutorial, dir
1414
);
1515

@@ -20,7 +20,7 @@ export default function runTaskTests(
2020
};
2121

2222
// call test runner
23-
tutorialConfig.run(output, config, handleResult);
23+
tutorialConfig.run({testString, config, handleResult});
2424
}
2525
return true;
2626
}

tsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
"src/components/StatusBar/index.ts",
2929
"src/components/styles/theme.ts",
3030
"src/index.ts",
31+
"src/modules/alert/actions.ts",
32+
"src/modules/alert/index.ts",
33+
"src/modules/alert/reducer.ts",
34+
"src/modules/alert/types.ts",
3135
"src/modules/hints/actions.ts",
3236
"src/modules/hints/index.ts",
3337
"src/modules/hints/reducer.ts",
@@ -81,6 +85,7 @@
8185
"src/store.ts",
8286
"src/subscriptions.ts",
8387
"src/typings.d.ts",
88+
"src/components/Alert/index.tsx",
8489
"src/components/AppMenu/CloseWindow.tsx",
8590
"src/components/AppMenu/index.tsx",
8691
"src/components/AppMenu/issuesLink.tsx",

0 commit comments

Comments
 (0)