Skip to content

Commit 292c286

Browse files
committedMay 16, 2016
move route into route module
·
v0.10.9v0.10.0
1 parent e9b224e commit 292c286

File tree

35 files changed

+191
-211
lines changed

35 files changed

+191
-211
lines changed
 

‎lib/actions/_types.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exports.HINT_POSITION_SET = 'HINT_POSITION_SET';
66
exports.PAGE_SET = 'PAGE_SET';
77
exports.PROGRESS_LOAD = 'PROGRESS_LOAD';
88
exports.PROGRESS_PAGE_POSITION_LOAD = 'PROGRESS_PAGE_POSITION_LOAD';
9-
exports.ROUTE_SET = 'ROUTE_SET';
109
exports.TEST_SAVE = 'TEST_SAVE';
1110
exports.SETUP_PACKAGE = 'SETUP_PACKAGE';
1211
exports.SETUP_VERIFY = 'SETUP_VERIFY';

‎lib/actions/alert.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎lib/actions/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
"use strict";
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;
62
var progress_1 = require('./progress');
73
exports.progressLoad = progress_1.progressLoad;
84
exports.completePage = progress_1.completePage;
@@ -13,8 +9,6 @@ exports.hintPositionSet = hint_1.hintPositionSet;
139
var page_1 = require('./page');
1410
exports.pageSet = page_1.pageSet;
1511
exports.pageNext = page_1.pageNext;
16-
var route_1 = require('./route');
17-
exports.routeSet = route_1.routeSet;
1812
var setup_1 = require('./setup');
1913
exports.setupVerify = setup_1.setupVerify;
2014
exports.setupPackage = setup_1.setupPackage;
@@ -29,3 +23,9 @@ exports.tutorialSet = tutorial_1.tutorialSet;
2923
exports.tutorialUpdate = tutorial_1.tutorialUpdate;
3024
var toggle_1 = require('./toggle');
3125
exports.devToolsToggle = toggle_1.devToolsToggle;
26+
var actions_1 = require('../modules/alert/actions');
27+
exports.alertOpen = actions_1.alertOpen;
28+
exports.alertClose = actions_1.alertClose;
29+
exports.alertReplay = actions_1.alertReplay;
30+
var actions_2 = require('../modules/route/actions');
31+
exports.routeSet = actions_2.routeSet;

‎lib/actions/page.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
"use strict";
22
var _types_1 = require('./_types');
33
var hint_1 = require('./hint');
4+
var actions_1 = require('../modules/route/actions');
45
function pageNext() {
56
return function (dispatch, getState) {
6-
var _a = getState(), pagePosition = _a.pagePosition, tutorial = _a.tutorial;
7-
var pages = tutorial.pages;
8-
if (pagePosition >= pages.length - 1) {
9-
dispatch({ type: _types_1.ROUTE_SET, payload: { route: 'final' } });
10-
}
11-
else {
12-
pagePosition += 1;
13-
dispatch(pageSet(pagePosition));
14-
}
7+
var pagePosition = getState().pagePosition;
8+
dispatch(pageSet(pagePosition + 1));
159
};
1610
}
1711
exports.pageNext = pageNext;
@@ -20,7 +14,7 @@ function pageSet(pagePosition) {
2014
return function (dispatch, getState) {
2115
var _a = getState(), dir = _a.dir, progress = _a.progress, tutorial = _a.tutorial, route = _a.route;
2216
if (pagePosition >= progress.pages.length) {
23-
dispatch({ type: _types_1.ROUTE_SET, payload: { route: 'final' } });
17+
return dispatch(actions_1.routeSet('final'));
2418
}
2519
dispatch(hint_1.hintPositionSet(0));
2620
var tasks = tutorial.pages[pagePosition].tasks || [];

‎lib/actions/route.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎lib/actions/tutorial.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"use strict";
22
var _types_1 = require('./_types');
33
var progress_1 = require('./progress');
4-
var route_1 = require('./route');
5-
var actions_1 = require('../modules/alert/actions');
4+
var actions_1 = require('../modules/route/actions');
5+
var actions_2 = require('../modules/alert/actions');
66
function tutorialSet(name) {
77
return function (dispatch, getState) {
88
var dir = getState().dir;
99
dispatch({ type: _types_1.TUTORIAL_SET, payload: { name: name, dir: dir } });
1010
dispatch(progress_1.progressLoad());
11-
dispatch(route_1.routeSet('progress'));
11+
dispatch(actions_1.routeSet('progress'));
1212
};
1313
}
1414
exports.tutorialSet = tutorialSet;
@@ -20,7 +20,7 @@ function tutorialUpdate(name) {
2020
duration: 3000,
2121
};
2222
dispatch({ type: _types_1.TUTORIAL_UPDATE, payload: { name: name } });
23-
dispatch(actions_1.alertOpen(alert));
23+
dispatch(actions_2.alertOpen(alert));
2424
};
2525
}
2626
exports.tutorialUpdate = tutorialUpdate;

‎lib/components/AppMenu/CloseWindow.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ 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 IconButton_1 = require('material-ui/IconButton');
2019
var close_1 = require('material-ui/svg-icons/navigation/close');
2120
var CloseWindow = (function (_super) {
@@ -29,7 +28,7 @@ var CloseWindow = (function (_super) {
2928
CloseWindow = __decorate([
3029
react_redux_1.connect(null, function (dispatch) {
3130
return {
32-
windowToggle: function () { return dispatch(actions_1.windowToggle()); }
31+
windowToggle: function () { return dispatch({ type: 'WINDOW_TOGGLE' }); }
3332
};
3433
}),
3534
__metadata('design:paramtypes', [])

‎lib/components/Tutorials/SelectTutorial/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ var SelectTutorial = (function (_super) {
3939
SelectTutorial = __decorate([
4040
react_redux_1.connect(null, function (dispatch) {
4141
return {
42-
selectTutorial: function (name) {
43-
dispatch(actions_1.tutorialSet(name));
44-
},
42+
selectTutorial: function (name) { return dispatch(actions_1.tutorialSet(name)); }
4543
};
4644
}),
4745
__metadata('design:paramtypes', [])

‎lib/components/Tutorials/index.js

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,54 @@
11
"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+
};
216
var React = require('react');
17+
var react_redux_1 = require('react-redux');
318
var Table_1 = require('material-ui/Table');
419
var LoadTutorials_1 = require('./LoadTutorials');
520
var UpdateTutorial_1 = require('./UpdateTutorial');
621
var SelectTutorial_1 = require('./SelectTutorial');
22+
var actions_1 = require('../../actions');
723
var styles = {
824
padding: '10px',
925
textAlign: 'center',
1026
};
11-
var Tutorials = function (_a) {
12-
var tutorialList = _a.tutorialList;
13-
return (React.createElement("div", {style: styles}, React.createElement(Table_1.Table, null, React.createElement(Table_1.TableHeader, {displaySelectAll: false, adjustForCheckbox: false}, React.createElement(Table_1.TableRow, null, React.createElement(Table_1.TableHeaderColumn, null, "Tutorial"), React.createElement(Table_1.TableHeaderColumn, null, "Version"))), React.createElement(Table_1.TableBody, {displayRowCheckbox: false}, tutorialList.map(function tutorialRow(tutorial, index) {
14-
return (React.createElement(Table_1.TableRow, {key: index}, React.createElement(Table_1.TableRowColumn, null, React.createElement(SelectTutorial_1.default, {tutorial: tutorial})), React.createElement(Table_1.TableRowColumn, null, tutorial.version, !!tutorial.latest
15-
? React.createElement(UpdateTutorial_1.default, {tutorial: tutorial})
16-
: null)));
17-
}))), React.createElement("br", null), React.createElement(LoadTutorials_1.default, null)));
18-
};
27+
var Tutorials = (function (_super) {
28+
__extends(Tutorials, _super);
29+
function Tutorials(props) {
30+
_super.call(this, props);
31+
}
32+
Tutorials.prototype.componentDidMount = function () {
33+
this.props.loadTutorials();
34+
};
35+
Tutorials.prototype.render = function () {
36+
var tutorialList = this.props.tutorialList;
37+
return (React.createElement("div", {style: styles}, React.createElement(Table_1.Table, null, React.createElement(Table_1.TableHeader, {displaySelectAll: false, adjustForCheckbox: false}, React.createElement(Table_1.TableRow, null, React.createElement(Table_1.TableHeaderColumn, null, "Tutorial"), React.createElement(Table_1.TableHeaderColumn, null, "Version"))), React.createElement(Table_1.TableBody, {displayRowCheckbox: false}, tutorialList.map(function tutorialRow(tutorial, index) {
38+
return (React.createElement(Table_1.TableRow, {key: index}, React.createElement(Table_1.TableRowColumn, null, React.createElement(SelectTutorial_1.default, {tutorial: tutorial})), React.createElement(Table_1.TableRowColumn, null, tutorial.version, !!tutorial.latest
39+
? React.createElement(UpdateTutorial_1.default, {tutorial: tutorial})
40+
: null)));
41+
}))), React.createElement("br", null), React.createElement(LoadTutorials_1.default, null)));
42+
};
43+
Tutorials = __decorate([
44+
react_redux_1.connect(null, function (dispatch) {
45+
return {
46+
loadTutorials: function () { return dispatch(actions_1.tutorialsFind()); }
47+
};
48+
}),
49+
__metadata('design:paramtypes', [Object])
50+
], Tutorials);
51+
return Tutorials;
52+
}(React.Component));
1953
Object.defineProperty(exports, "__esModule", { value: true });
2054
exports.default = Tutorials;

‎lib/components/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
"use strict";
2-
var alert_1 = require('../modules/alert');
3-
exports.Alert = alert_1.Alert;
42
var AppMenu_1 = require('./AppMenu');
53
exports.AppMenu = AppMenu_1.default;
64
var FinalPage_1 = require('./FinalPage');
@@ -17,7 +15,9 @@ var Tutorials_1 = require('./Tutorials');
1715
exports.Tutorials = Tutorials_1.default;
1816
var Markdown_1 = require('./common/Markdown');
1917
exports.Markdown = Markdown_1.default;
20-
var RouteButton_1 = require('./common/RouteButton');
21-
exports.RouteButton = RouteButton_1.default;
2218
var ContentCard_1 = require('./common/ContentCard');
2319
exports.ContentCard = ContentCard_1.default;
20+
var alert_1 = require('../modules/alert');
21+
exports.Alert = alert_1.Alert;
22+
var route_1 = require('../modules/route');
23+
exports.RouteButton = route_1.RouteButton;

‎lib/components/Alert/index.js renamed to ‎lib/modules/route/RouteButton.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,26 @@ var __metadata = (this && this.__metadata) || function (k, v) {
1515
};
1616
var React = require('react');
1717
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 Alert = (function (_super) {
25-
__extends(Alert, _super);
26-
function Alert() {
18+
var RaisedButton_1 = require('material-ui/RaisedButton');
19+
var actions_1 = require('./actions');
20+
var RouteButton = (function (_super) {
21+
__extends(RouteButton, _super);
22+
function RouteButton() {
2723
_super.apply(this, arguments);
2824
}
29-
Alert.prototype.render = function () {
30-
var _a = this.props, alert = _a.alert, close = _a.close;
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: close}));
25+
RouteButton.prototype.render = function () {
26+
var _a = this.props, label = _a.label, route = _a.route, style = _a.style, routeTo = _a.routeTo;
27+
return (React.createElement(RaisedButton_1.default, {label: label, style: style || {}, onTouchTap: routeTo.bind(this, route), secondary: true}));
3328
};
34-
Alert = __decorate([
29+
RouteButton = __decorate([
3530
react_redux_1.connect(null, function (dispatch) {
3631
return {
37-
close: function () { return dispatch(actions_1.alertClose()); }
32+
routeTo: function (route) { return dispatch(actions_1.routeSet(route)); }
3833
};
3934
}),
4035
__metadata('design:paramtypes', [])
41-
], Alert);
42-
return Alert;
36+
], RouteButton);
37+
return RouteButton;
4338
}(React.Component));
4439
Object.defineProperty(exports, "__esModule", { value: true });
45-
exports.default = Alert;
40+
exports.default = RouteButton;

‎lib/modules/route/actions.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use strict";
2+
var types_1 = require('./types');
3+
var previous = null;
4+
function routeSet(route) {
5+
if (route && route !== previous) {
6+
return function (dispatch) {
7+
previous = route;
8+
dispatch({ type: types_1.ROUTE_SET, payload: { route: route } });
9+
};
10+
}
11+
}
12+
exports.routeSet = routeSet;

‎lib/modules/route/index.js

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

‎lib/reducers/route/index.js renamed to ‎lib/modules/route/reducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use strict";
2-
var _types_1 = require('../../actions/_types');
2+
var types_1 = require('./types');
33
var _route = 'start';
44
function routeReducer(route, action) {
55
if (route === void 0) { route = _route; }
66
switch (action.type) {
7-
case _types_1.ROUTE_SET:
7+
case types_1.ROUTE_SET:
88
return action.payload.route;
99
default:
1010
return route;

‎lib/modules/route/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
exports.ROUTE_SET = 'ROUTE_SET';

‎lib/reducers/alert/index.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

‎lib/reducers/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"use strict";
22
var redux_1 = require('redux');
3-
var alert_1 = require('../modules/alert');
4-
var window_1 = require('../modules/window');
53
var checks_1 = require('./checks');
64
var devTools_toggle_1 = require('./devTools-toggle');
75
var dir_1 = require('./dir');
@@ -10,18 +8,20 @@ var package_json_1 = require('./package-json');
108
var page_1 = require('./page');
119
var page_position_1 = require('./page-position');
1210
var progress_1 = require('./progress');
13-
var route_1 = require('./route');
1411
var tasks_1 = require('./tasks');
1512
var task_actions_1 = require('./task-actions');
1613
var task_position_1 = require('./task-position');
1714
var task_tests_1 = require('./task-tests');
1815
var test_run_1 = require('./test-run');
1916
var tutorial_1 = require('./tutorial');
2017
var tutorial_list_1 = require('./tutorial-list');
18+
var alert_1 = require('../modules/alert');
19+
var window_1 = require('../modules/window');
20+
var route_1 = require('../modules/route');
2121
Object.defineProperty(exports, "__esModule", { value: true });
2222
exports.default = redux_1.combineReducers({
2323
alert: alert_1.reducer, checks: checks_1.default, devToolsToggle: devTools_toggle_1.default, dir: dir_1.default, hintPosition: hint_position_1.default,
24-
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,
24+
packageJson: package_json_1.default, page: page_1.default, pagePosition: page_position_1.default, progress: progress_1.default, route: route_1.reducer, 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_1.reducer
2727
});

‎lib/reducers/page-position/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ var _types_1 = require('../../actions/_types');
33
function pagePositionReducer(pagePosition, action) {
44
if (pagePosition === void 0) { pagePosition = 0; }
55
switch (action.type) {
6-
case _types_1.PROGRESS_PAGE_POSITION_LOAD:
7-
var pages = action.payload.progress.pages;
8-
var firstFail = pages.indexOf(false);
9-
return firstFail < 0 ? pages.length - 1 : firstFail;
10-
case _types_1.PAGE_POSITION_SET:
6+
case _types_1.PAGE_SET:
117
return action.payload.pagePosition;
128
default:
139
return pagePosition;

‎lib/reducers/window-toggle/index.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎src/actions/_types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export const HINT_POSITION_SET = 'HINT_POSITION_SET';
55
export const PAGE_SET = 'PAGE_SET';
66
export const PROGRESS_LOAD = 'PROGRESS_LOAD';
77
export const PROGRESS_PAGE_POSITION_LOAD = 'PROGRESS_PAGE_POSITION_LOAD';
8-
export const ROUTE_SET = 'ROUTE_SET';
98
export const TEST_SAVE = 'TEST_SAVE';
109
export const SETUP_PACKAGE = 'SETUP_PACKAGE';
1110
export const SETUP_VERIFY = 'SETUP_VERIFY';

‎src/actions/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
export {alertOpen, alertClose, alertReplay} from '../modules/alert/actions';
1+
// Actions
22
export {
33
progressLoad, completePage, completeTutorial,
44
progressPagePositionLoad
55
} from './progress';
66
export {hintPositionSet} from './hint';
77
export {pageSet, pageNext} from './page';
8-
export {routeSet} from './route';
98
export {setupVerify, setupPackage} from './setup';
109
export {
1110
testRun, testComplete, testResult, testSave
1211
} from './test';
1312
export {
1413
tutorialsFind, tutorialSet, tutorialUpdate
1514
} from './tutorial';
16-
export {windowToggle, devToolsToggle, quit} from './toggle';
15+
export {devToolsToggle} from './toggle';
16+
17+
// Modules
18+
export {alertOpen, alertClose, alertReplay} from '../modules/alert/actions';
19+
export {routeSet} from '../modules/route/actions';

‎src/actions/page.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
1-
import {
2-
ROUTE_SET, PAGE_SET
3-
} from './_types';
1+
import {PAGE_SET} from './_types';
42
import {hintPositionSet} from './hint';
5-
import {routeSet} from './route';
3+
import {routeSet} from '../modules/route/actions';
64

75
export function pageNext(): ReduxThunk.ThunkInterface | Action {
86
return (dispatch, getState): void => {
9-
let {pagePosition, tutorial} = getState();
10-
const pages = tutorial.pages;
11-
if (pagePosition >= pages.length - 1) {
12-
dispatch({ type: ROUTE_SET, payload: { route: 'final' } });
13-
} else {
14-
pagePosition += 1;
15-
dispatch(pageSet(pagePosition));
16-
}
7+
let {pagePosition} = getState();
8+
dispatch(pageSet(pagePosition + 1));
179
};
1810
}
1911

2012
export function pageSet(pagePosition = 0): ReduxThunk.ThunkInterface {
2113
return (dispatch, getState): void => {
2214
const {dir, progress, tutorial, route} = getState();
23-
2415
// routes
2516
if (pagePosition >= progress.pages.length) {
26-
dispatch({ type: ROUTE_SET, payload: { route: 'final' } });
17+
return dispatch(routeSet('final'));
2718
}
2819
dispatch(hintPositionSet(0));
2920
// create absolute paths for 'task-tests'

‎src/actions/tutorial.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
TUTORIALS_FIND, TUTORIAL_UPDATE, TUTORIAL_SET
33
} from './_types';
44
import {progressLoad} from './progress';
5-
import {routeSet} from './route';
5+
import {routeSet} from '../modules/route/actions';
66
import {alertOpen} from '../modules/alert/actions';
77

88
export function tutorialSet(name: string): ReduxThunk.ThunkInterface {

‎src/components/AppMenu/CloseWindow.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import * as React from 'react';
22
import {connect} from 'react-redux';
3-
import {windowToggle} from '../../actions';
43
import IconButton from 'material-ui/IconButton';
54
import NavigationClose from 'material-ui/svg-icons/navigation/close';
65

76
@connect(null, (dispatch) => {
87
return {
9-
windowToggle: () => dispatch(windowToggle())
8+
windowToggle: () => dispatch({ type: 'WINDOW_TOGGLE'})
109
};
1110
})
1211
export default class CloseWindow extends React.Component<{

‎src/components/Tutorials/SelectTutorial/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import * as React from 'react';
22
import {connect} from 'react-redux';
33
import FlatButton from 'material-ui/FlatButton';
4-
import {
5-
pagePositionSet, tutorialSet, progressLoad, routeSet
6-
} from '../../../actions';
4+
import {tutorialSet} from '../../../actions';
75

86
function displayName(name: string): string {
97
if (name.match(/^coderoad-tutorial-/)) {
@@ -16,9 +14,7 @@ function displayName(name: string): string {
1614

1715
@connect(null, (dispatch) => {
1816
return {
19-
selectTutorial: (name: string) => {
20-
dispatch(tutorialSet(name));
21-
},
17+
selectTutorial: (name: string) => dispatch(tutorialSet(name))
2218
};
2319
})
2420
export default class SelectTutorial extends React.Component<{

‎src/components/Tutorials/index.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
import * as React from 'react';
2+
import {connect} from 'react-redux';
23
import {
34
Table, TableHeaderColumn, TableRow, TableHeader, TableRowColumn, TableBody
45
} from 'material-ui/Table';
56
import LoadTutorials from './LoadTutorials';
67
import UpdateTutorial from './UpdateTutorial';
78
import SelectTutorial from './SelectTutorial';
9+
import {tutorialsFind} from '../../actions';
810

911
const styles = {
1012
padding: '10px',
1113
textAlign: 'center',
1214
};
1315

14-
const Tutorials: React.StatelessComponent<{
15-
tutorialList: Tutorial.Info[]
16-
}> = ({tutorialList}) => (
16+
17+
@connect(null, (dispatch) => {
18+
return {
19+
loadTutorials: () => dispatch(tutorialsFind())
20+
};
21+
})
22+
export default class Tutorials extends React.Component<{
23+
tutorialList: Tutorial.Info[], loadTutorials?: any
24+
}, {}> {
25+
constructor(props) {
26+
super(props);
27+
}
28+
componentDidMount() {
29+
this.props.loadTutorials();
30+
}
31+
render() {
32+
const {tutorialList} = this.props;
33+
return (
1734
<div style={styles}>
1835
<Table>
1936

@@ -55,5 +72,6 @@ const Tutorials: React.StatelessComponent<{
5572
<br />
5673
<LoadTutorials />
5774
</div>
58-
);
59-
export default Tutorials;
75+
);
76+
}
77+
}

‎src/components/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export {Alert} from '../modules/alert';
21
export {default as AppMenu} from './AppMenu';
32
export {default as FinalPage} from './FinalPage';
43
export {default as Page} from './Page';
@@ -7,5 +6,8 @@ export {default as Routes} from './Routes';
76
export {default as Start} from './Start';
87
export {default as Tutorials} from './Tutorials';
98
export {default as Markdown} from './common/Markdown';
10-
export {default as RouteButton} from './common/RouteButton';
9+
1110
export {default as ContentCard} from './common/ContentCard';
11+
12+
export {Alert} from '../modules/alert';
13+
export {RouteButton} from '../modules/route';

‎src/modules/route/RouteButton.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as React from 'react';
2+
import {connect} from 'react-redux';
3+
import RaisedButton from 'material-ui/RaisedButton';
4+
import {routeSet} from './actions';
5+
6+
@connect(null, dispatch => {
7+
return {
8+
routeTo: (route: string) => dispatch(routeSet(route))
9+
};
10+
})
11+
export default class RouteButton extends React.Component<{
12+
label: string, route: string, routeTo?: any, style?: Object
13+
}, {}> {
14+
render() {
15+
const {label, route, style, routeTo} = this.props;
16+
return (
17+
<RaisedButton
18+
label={label}
19+
style={style || {}}
20+
onTouchTap={routeTo.bind(this, route)}
21+
secondary={true}
22+
/>
23+
);
24+
}
25+
}

‎src/actions/route.ts renamed to ‎src/modules/route/actions.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ROUTE_SET} from './_types';
1+
import {ROUTE_SET} from './types';
22
import {tutorialsFind} from './tutorial';
33

44
let previous = null;
@@ -7,11 +7,6 @@ let previous = null;
77
export function routeSet(route: string): ReduxThunk.ThunkInterface {
88
if (route && route !== previous) {
99
return (dispatch) => {
10-
// preloading for routes
11-
switch (route) {
12-
case 'tutorials':
13-
dispatch(tutorialsFind());
14-
}
1510
previous = route;
1611
dispatch({ type: ROUTE_SET, payload: { route } });
1712
};

‎src/modules/route/index.ts

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

‎src/reducers/route/index.ts renamed to ‎src/modules/route/reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ROUTE_SET} from '../../actions/_types';
1+
import {ROUTE_SET} from './types';
22

33
const _route = 'start';
44

‎src/modules/route/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const ROUTE_SET = 'ROUTE_SET';

‎src/reducers/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {combineReducers} from 'redux';
22

3-
import {reducer as alert} from '../modules/alert';
4-
import {reducer as windowToggle} from '../modules/window';
3+
// reducers
54
import checks from './checks';
65
import devToolsToggle from './devTools-toggle';
76
import dir from './dir';
@@ -10,7 +9,6 @@ import packageJson from './package-json';
109
import page from './page';
1110
import pagePosition from './page-position';
1211
import progress from './progress';
13-
import route from './route';
1412
import tasks from './tasks';
1513
import taskActions from './task-actions';
1614
import taskPosition from './task-position';
@@ -19,6 +17,11 @@ import testRun from './test-run';
1917
import tutorial from './tutorial';
2018
import tutorialList from './tutorial-list';
2119

20+
// module reducers
21+
import {reducer as alert} from '../modules/alert';
22+
import {reducer as windowToggle} from '../modules/window';
23+
import {reducer as route} from '../modules/route';
24+
2225
export default combineReducers({
2326
alert, checks, devToolsToggle, dir, hintPosition,
2427
packageJson, page, pagePosition, progress, route, tasks,

‎src/reducers/page-position/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import {
2-
PROGRESS_PAGE_POSITION_LOAD, PAGE_SET, PAGE_POSITION_SET
2+
PROGRESS_PAGE_POSITION_LOAD, PAGE_SET
33
} from '../../actions/_types';
44

55
export default function pagePositionReducer(
66
pagePosition = 0, action: Action
77
): CR.PagePosition {
88
switch (action.type) {
99

10-
case PROGRESS_PAGE_POSITION_LOAD:
11-
const pages = action.payload.progress.pages;
12-
const firstFail = pages.indexOf(false);
13-
return firstFail < 0 ? pages.length - 1 : firstFail;
10+
// case PROGRESS_PAGE_POSITION_LOAD:
11+
// const pages = action.payload.progress.pages;
12+
// const firstFail = pages.indexOf(false);
13+
// return firstFail < 0 ? pages.length - 1 : firstFail;
1414

15-
case PAGE_POSITION_SET:
15+
case PAGE_SET:
1616
return action.payload.pagePosition;
1717

1818
default:

‎tsconfig.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"src/actions/index.ts",
5757
"src/actions/page.ts",
5858
"src/actions/progress.ts",
59-
"src/actions/route.ts",
6059
"src/actions/setup.ts",
6160
"src/actions/test.ts",
6261
"src/actions/toggle.ts",
@@ -79,6 +78,10 @@
7978
"src/modules/alert/index.ts",
8079
"src/modules/alert/reducer.ts",
8180
"src/modules/alert/types.ts",
81+
"src/modules/route/actions.ts",
82+
"src/modules/route/index.ts",
83+
"src/modules/route/reducer.ts",
84+
"src/modules/route/types.ts",
8285
"src/modules/window/actions.ts",
8386
"src/modules/window/index.ts",
8487
"src/modules/window/reducer.ts",
@@ -97,7 +100,6 @@
97100
"src/reducers/page/index.ts",
98101
"src/reducers/progress/index.ts",
99102
"src/reducers/progress/local-storage.ts",
100-
"src/reducers/route/index.ts",
101103
"src/reducers/task-actions/editor-reducer.ts",
102104
"src/reducers/task-actions/index.ts",
103105
"src/reducers/task-actions/parser/index.ts",
@@ -165,7 +167,8 @@
165167
"src/components/Tutorials/LoadTutorials/index.tsx",
166168
"src/components/Tutorials/SelectTutorial/index.tsx",
167169
"src/components/Tutorials/UpdateTutorial/index.tsx",
168-
"src/modules/alert/Alert.tsx"
170+
"src/modules/alert/Alert.tsx",
171+
"src/modules/route/RouteButton.tsx"
169172
],
170173
"exclude": [
171174
"node_modules"

0 commit comments

Comments
 (0)
Please sign in to comment.