Skip to content

Commit ca0b1a4

Browse files
committed
load data through tutorial reducer
1 parent 23f193d commit ca0b1a4

File tree

40 files changed

+150
-201
lines changed

40 files changed

+150
-201
lines changed

lib/actions.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
"use strict";
2-
var actions_1 = require('./modules/page/actions');
3-
exports.pageSet = actions_1.pageSet;
4-
exports.pageNext = actions_1.pageNext;
52
var package_json_1 = require('./modules/package-json');
63
exports.pjSave = package_json_1.pjSave;
74
var setup_1 = require('./modules/setup');
85
exports.setupVerify = setup_1.setupVerify;
96
exports.setupPackage = setup_1.setupPackage;
107
var tutorial_1 = require('./modules/tutorial');
118
exports.tutorialInit = tutorial_1.tutorialInit;
9+
exports.tutorialLoad = tutorial_1.tutorialLoad;
1210
var alert_1 = require('core-coderoad/lib/alert');
1311
exports.alertOpen = alert_1.alertOpen;
1412
exports.alertClose = alert_1.alertClose;

lib/components/Page/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ var styles = {
66
overflowY: 'scroll',
77
};
88
var Page = function (_a) {
9-
var page = _a.page, tasks = _a.tasks, pagePosition = _a.pagePosition;
9+
var tutorial = _a.tutorial, pagePosition = _a.pagePosition;
10+
var page = tutorial.pages[pagePosition];
11+
if (!page) {
12+
return null;
13+
}
1014
return (React.createElement("section", {style: styles, className: 'cr-page'}, React.createElement(index_1.ContentCard, {title: page.title, content: page.description})));
1115
};
1216
Object.defineProperty(exports, "__esModule", { value: true });

lib/modules/data/actions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
var types_1 = require('./types');
3+
function dataLoad() {
4+
return function (dispatch, getState) {
5+
var dir = getState().dir;
6+
dispatch({ type: types_1.DATA_LOAD, payload: { dir: dir } });
7+
};
8+
}
9+
exports.dataLoad = dataLoad;

lib/modules/data/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 actions_1 = require('./actions');
3+
exports.dataLoad = actions_1.dataLoad;
4+
var reducer_1 = require('./reducer');
5+
exports.reducer = reducer_1.default;

lib/modules/data/reducer.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"use strict";
2+
var types_1 = require('./types');
3+
var fs_1 = require('fs');
4+
var path_1 = require('path');
5+
var _d = {};
6+
function dataReducer(d, action) {
7+
if (d === void 0) { d = _d; }
8+
switch (action.type) {
9+
case types_1.DATA_LOAD:
10+
var dir = action.payload.dir;
11+
var data = JSON.parse(fs_1.readFileSync(path_1.join(dir, 'coderoad.json'), 'utf8'));
12+
console.log(data);
13+
return data;
14+
default:
15+
return d;
16+
}
17+
}
18+
Object.defineProperty(exports, "__esModule", { value: true });
19+
exports.default = dataReducer;

lib/modules/data/types.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use strict";
2+
exports.DATA_LOAD = 'DATA_LOAD';
3+
exports.DATA_SAVE = 'DATA_BUILD';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
var types_1 = require('./types');
3+
function pageSet(position) {
4+
return { type: types_1.PAGE_SET };
5+
}
6+
exports.pageSet = pageSet;

lib/modules/page-position/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 actions_1 = require('./actions');
3+
exports.pageSet = actions_1.pageSet;
4+
var reducer_1 = require('./reducer');
5+
exports.reducer = reducer_1.default;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
var types_1 = require('./types');
3+
function pagePosition(pagePosition, action) {
4+
if (pagePosition === void 0) { pagePosition = 0; }
5+
switch (action.type) {
6+
case types_1.PAGE_SET:
7+
return action.payload.pagePosition;
8+
default:
9+
return pagePosition;
10+
}
11+
}
12+
Object.defineProperty(exports, "__esModule", { value: true });
13+
exports.default = pagePosition;

lib/modules/page-position/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.PAGE_SET = 'PAGE_SET';

0 commit comments

Comments
 (0)