Skip to content

Commit c682dc4

Browse files
committed
fix tutorial link
1 parent f1888cc commit c682dc4

File tree

8 files changed

+52
-61
lines changed

8 files changed

+52
-61
lines changed

lib/components/Tutorials/SelectTutorial/index.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,29 @@ var React = require('react');
1717
var react_redux_1 = require('react-redux');
1818
var actions_1 = require('../../../actions');
1919
var FlatButton_1 = require('material-ui/FlatButton');
20-
function displayName(name) {
21-
if (name.match(/^coderoad-tutorial-/)) {
22-
return name.slice(18);
23-
}
24-
else if (name.match(/^coderoad-/)) {
25-
return name.slice(9);
26-
}
27-
return name;
28-
}
2920
var SelectTutorial = (function (_super) {
3021
__extends(SelectTutorial, _super);
3122
function SelectTutorial() {
3223
_super.apply(this, arguments);
3324
}
25+
SelectTutorial.prototype.displayName = function (name) {
26+
if (name.match(/^coderoad-tutorial-/)) {
27+
return name.slice(18);
28+
}
29+
else if (name.match(/^coderoad-/)) {
30+
return name.slice(9);
31+
}
32+
return name;
33+
};
3434
SelectTutorial.prototype.render = function () {
3535
var _a = this.props, tutorial = _a.tutorial, selectTutorial = _a.selectTutorial;
36-
var title = tutorial.title;
37-
return (React.createElement(FlatButton_1.default, {label: displayName(title), primary: true, onTouchTap: selectTutorial.bind(this, title)}));
36+
console.log('tutorial', tutorial);
37+
var name = tutorial.name;
38+
return (React.createElement(FlatButton_1.default, {label: this.displayName(name), primary: true, onTouchTap: selectTutorial.bind(this, name)}));
3839
};
3940
SelectTutorial = __decorate([
4041
react_redux_1.connect(null, function (dispatch) { return ({
41-
selectTutorial: function (title) { return dispatch(actions_1.tutorialSet(name)); },
42+
selectTutorial: function (name) { return dispatch(actions_1.tutorialSet(name)); },
4243
}); }),
4344
__metadata('design:paramtypes', [])
4445
], SelectTutorial);

lib/modules/page/actions.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
"use strict";
22
var types_1 = require('./types');
33
var actions_1 = require('../../actions');
4-
var actions_2 = require('../../actions');
5-
exports.editorOpen = actions_2.editorOpen;
6-
exports.editorSave = actions_2.editorSave;
7-
exports.editorSet = actions_2.editorSet;
8-
exports.editorInsert = actions_2.editorInsert;
4+
var selectors_1 = require('../../selectors');
95
function pageNext() {
106
return function (dispatch, getState) {
117
var pagePosition = getState().pagePosition;
@@ -16,14 +12,15 @@ exports.pageNext = pageNext;
1612
function pageSet(pagePosition) {
1713
if (pagePosition === void 0) { pagePosition = 0; }
1814
return function (dispatch, getState) {
19-
var _a = getState(), dir = _a.dir, progress = _a.progress, tutorial = _a.tutorial, route = _a.route;
15+
var state = getState();
16+
var progress = state.progress, tutorial = state.tutorial, route = state.route;
2017
if (pagePosition >= progress.pages.length) {
2118
return dispatch(actions_1.routeSet('final'));
2219
}
2320
dispatch(actions_1.hintPositionSet(0));
24-
var tasks = tutorial.pages[pagePosition].tasks || [];
21+
var tasks = selectors_1.tasksSelector(state) || [];
2522
dispatch({
26-
type: types_1.PAGE_SET, payload: { dir: dir, pagePosition: pagePosition, tutorial: tutorial, progress: progress, tasks: tasks }
23+
type: types_1.PAGE_SET, payload: { pagePosition: pagePosition, tutorial: tutorial, progress: progress, tasks: tasks }
2724
});
2825
};
2926
}

lib/modules/tutorial/actions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use strict";
22
var types_1 = require('./types');
33
var route_1 = require('core-coderoad/lib/route');
4-
function tutorialSet(title) {
4+
function tutorialSet(name) {
55
return function (dispatch, getState) {
66
var dir = getState().dir;
7-
dispatch({ type: types_1.TUTORIAL_SET, payload: { title: title, dir: dir } });
7+
dispatch({ type: types_1.TUTORIAL_SET, payload: { name: name, dir: dir } });
88
dispatch(route_1.routeSet('progress'));
99
};
1010
}

lib/modules/tutorial/reducer.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
"use strict";
22
var path_1 = require('path');
3-
var config_1 = require('./utils/config');
43
var types_1 = require('./types');
54
var config_paths_1 = require('./utils/config-paths');
65
var _tutorial = {
7-
title: null,
6+
name: null,
87
info: null,
98
pages: [],
109
packageJson: null,
11-
config: null,
1210
};
1311
function tutorialReducer(tutorial, action) {
1412
if (tutorial === void 0) { tutorial = _tutorial; }
1513
switch (action.type) {
1614
case types_1.TUTORIAL_SET:
17-
var _a = action.payload, title = _a.title, dir = _a.dir;
18-
var packagePath = path_1.join(dir, 'node_modules', title);
15+
var _a = action.payload, name_1 = _a.name, dir = _a.dir;
16+
var packagePath = path_1.join(dir, 'node_modules', name_1);
1917
var packageJson = require(path_1.join(packagePath, 'package.json'));
20-
var config = config_1.tutorialConfig(packageJson, dir);
18+
console.log(packageJson);
2119
var _b = require(path_1.join(packagePath, packageJson.main)), info = _b.info, pages = _b.pages;
22-
console.log(packageJson, packageJson.name);
23-
pages = config_paths_1.default(dir, title, config, pages || []);
20+
pages = config_paths_1.default(dir, name_1, packageJson.config, pages || []);
2421
return {
25-
title: packageJson.name,
22+
name: packageJson.name,
2623
info: info,
2724
pages: pages,
2825
packageJson: packageJson,
29-
config: config,
3026
};
3127
default:
3228
return tutorial;

src/components/Tutorials/SelectTutorial/index.tsx

+13-14
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,28 @@ import {connect} from 'react-redux';
33
import {tutorialSet} from '../../../actions';
44
import FlatButton from 'material-ui/FlatButton';
55

6-
function displayName(name: string): string {
7-
if (name.match(/^coderoad-tutorial-/)) {
8-
return name.slice(18);
9-
} else if (name.match(/^coderoad-/)) {
10-
return name.slice(9);
11-
}
12-
return name;
13-
}
14-
156
@connect(null, dispatch => ({
16-
selectTutorial: (title: string) => dispatch(tutorialSet(name)),
7+
selectTutorial: (name: string) => dispatch(tutorialSet(name)),
178
}))
189
export default class SelectTutorial extends React.Component<{
19-
tutorial: Tutorial.Info, selectTutorial?: any
10+
tutorial: Tutorial.Info, selectTutorial?: any
2011
}, {}> {
12+
displayName(name: string): string {
13+
if (name.match(/^coderoad-tutorial-/)) {
14+
return name.slice(18);
15+
} else if (name.match(/^coderoad-/)) {
16+
return name.slice(9);
17+
}
18+
return name;
19+
}
2120
render() {
2221
const {tutorial, selectTutorial} = this.props;
23-
const title = tutorial.title;
22+
const {name} = tutorial;
2423
return (
2524
<FlatButton
26-
label={displayName(title)}
25+
label={this.displayName(name)}
2726
primary={true}
28-
onTouchTap={selectTutorial.bind(this, title)}
27+
onTouchTap={selectTutorial.bind(this, name)}
2928
/>
3029
);
3130
}

src/modules/page/actions.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {PAGE_SET} from './types';
22
import {hintPositionSet, routeSet} from '../../actions';
3-
export {editorOpen, editorSave, editorSet, editorInsert} from '../../actions';
3+
import {tasksSelector} from '../../selectors';
44

55
export function pageNext(): ReduxThunk.ThunkInterface | Action {
66
return (dispatch, getState): void => {
@@ -11,16 +11,17 @@ export function pageNext(): ReduxThunk.ThunkInterface | Action {
1111

1212
export function pageSet(pagePosition = 0): ReduxThunk.ThunkInterface {
1313
return (dispatch, getState): void => {
14-
const {dir, progress, tutorial, route} = getState();
14+
const state = getState();
15+
const {progress, tutorial, route} = state;
1516
// routes
1617
if (pagePosition >= progress.pages.length) {
1718
return dispatch(routeSet('final'));
1819
}
1920
dispatch(hintPositionSet(0));
2021
// create absolute paths for 'task-tests'
21-
const tasks = tutorial.pages[pagePosition].tasks || [];
22+
const tasks = tasksSelector(state) || [];
2223
dispatch({
23-
type: PAGE_SET, payload: { dir, pagePosition, tutorial, progress, tasks }
24+
type: PAGE_SET, payload: { pagePosition, tutorial, progress, tasks }
2425
});
2526
};
2627
}

src/modules/tutorial/actions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {TUTORIAL_SET} from './types';
22
import {routeSet} from 'core-coderoad/lib/route';
33

4-
export function tutorialSet(title: string): ReduxThunk.ThunkInterface {
4+
export function tutorialSet(name: string): ReduxThunk.ThunkInterface {
55
return (dispatch, getState) => {
66
const {dir} = getState();
7-
dispatch({ type: TUTORIAL_SET, payload: {title, dir }});
7+
dispatch({ type: TUTORIAL_SET, payload: {name, dir }});
88
dispatch(routeSet('progress'));
99
};
1010
}

src/modules/tutorial/reducer.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import {TUTORIAL_SET} from './types';
44
import configPaths from './utils/config-paths';
55

66
const _tutorial: CR.Tutorial = {
7-
title: null,
7+
name: null,
88
info: null,
99
pages: [],
1010
packageJson: null,
11-
config: null,
1211
};
1312

1413
export default function tutorialReducer(
@@ -17,20 +16,18 @@ export default function tutorialReducer(
1716
switch (action.type) {
1817

1918
case TUTORIAL_SET:
20-
const {title, dir} = action.payload;
21-
const packagePath: string = join(dir, 'node_modules', title);
19+
const {name, dir} = action.payload;
20+
const packagePath: string = join(dir, 'node_modules', name);
2221
const packageJson: PackageJson = require(join(packagePath, 'package.json'));
23-
const config: Tutorial.Config = tutorialConfig(packageJson, dir);
22+
// const config: Tutorial.Config = tutorialConfig(packageJson, dir);
2423
let {info, pages} = require(join(packagePath, packageJson.main));
25-
console.log(packageJson, packageJson.name);
2624
// configure test paths to absolute paths
27-
pages = configPaths(dir, title, config, pages || []);
25+
pages = configPaths(dir, name, packageJson.config, pages || []);
2826
return {
29-
title: packageJson.name,
27+
name: packageJson.name,
3028
info,
3129
pages,
3230
packageJson,
33-
config,
3431
};
3532

3633
default:

0 commit comments

Comments
 (0)