Skip to content

Commit 68b5dcc

Browse files
committed
config paths earlier, refactor alert/progress reducers
1 parent af19182 commit 68b5dcc

File tree

28 files changed

+168
-148
lines changed

28 files changed

+168
-148
lines changed

lib/actions/alert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var _types_1 = require('./_types');
33
function alertToggle(alert, filter) {
44
return function (dispatch, getState) {
5-
dispatch({ type: _types_1.ALERT_TOGGLE, payload: { alert: alert } });
5+
dispatch({ type: _types_1.ALERT_TOGGLE, payload: { alert: alert }, filter: filter });
66
};
77
}
88
exports.alertToggle = alertToggle;

lib/actions/config-task-tests.js

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

lib/actions/page.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use strict";
22
var _types_1 = require('./_types');
3-
var config_task_tests_1 = require('./config-task-tests');
43
var hint_1 = require('./hint');
54
function pageNext() {
65
return function (dispatch, getState) {
@@ -20,7 +19,7 @@ function pageSet(pagePosition) {
2019
if (pagePosition === void 0) { pagePosition = 0; }
2120
return function (dispatch, getState) {
2221
var _a = getState(), dir = _a.dir, progress = _a.progress, tutorial = _a.tutorial;
23-
var tasks = config_task_tests_1.default(dir, tutorial, tutorial.pages[pagePosition].tasks || []);
22+
var tasks = tutorial.pages[pagePosition].tasks || [];
2423
if (pagePosition >= progress.pages.length) {
2524
dispatch({ type: _types_1.ROUTE_SET, payload: { route: 'final' } });
2625
}

lib/actions/progress.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22
var _types_1 = require('./_types');
33
var alert_1 = require('./alert');
4+
var test_1 = require('./test');
45
function progressPagePositionLoad() {
56
return function (dispatch, getState) {
67
var progress = getState().progress;
@@ -13,29 +14,37 @@ function progressLoad() {
1314
var tutorial = getState().tutorial;
1415
dispatch({ type: _types_1.PROGRESS_LOAD, payload: { tutorial: tutorial } });
1516
dispatch(progressPagePositionLoad());
17+
dispatch(test_1.testRun());
1618
};
1719
}
1820
exports.progressLoad = progressLoad;
19-
function completePage() {
21+
function completePage(completed) {
22+
if (completed === void 0) { completed = true; }
2023
return function (dispatch, getState) {
2124
var _a = getState(), pagePosition = _a.pagePosition, progress = _a.progress, tutorial = _a.tutorial;
22-
dispatch({ type: _types_1.COMPLETE_PAGE, payload: { pagePosition: pagePosition, tutorial: tutorial } });
23-
if (progress.pages.every(function (x) { return x.completed; })) {
24-
dispatch(completeTutorial());
25+
dispatch({ type: _types_1.COMPLETE_PAGE, payload: { pagePosition: pagePosition, tutorial: tutorial, completed: completed } });
26+
if (completed) {
27+
if (progress.pages.every(function (x) { return x.completed; })) {
28+
dispatch(completeTutorial());
29+
}
30+
else {
31+
dispatch(alert_1.alertToggle({
32+
message: "Page " + (pagePosition + 1) + " Complete",
33+
action: 'pass',
34+
}));
35+
}
2536
}
26-
else {
27-
dispatch(alert_1.alertToggle({
28-
message: "Page " + (pagePosition + 1) + " Complete",
29-
action: 'pass',
30-
}));
37+
else if (progress.completed) {
38+
dispatch(completeTutorial(false));
3139
}
3240
};
3341
}
3442
exports.completePage = completePage;
35-
function completeTutorial() {
43+
function completeTutorial(completed) {
44+
if (completed === void 0) { completed = true; }
3645
return function (dispatch, getState) {
3746
var tutorial = getState().tutorial;
38-
dispatch({ type: _types_1.COMPLETE_TUTORIAL, payload: { tutorial: tutorial } });
47+
dispatch({ type: _types_1.COMPLETE_TUTORIAL, payload: { tutorial: tutorial, completed: completed } });
3948
dispatch(alert_1.alertToggle({
4049
message: 'Tutorial Complete',
4150
action: 'pass',

lib/actions/test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22
var _types_1 = require('./_types');
33
var hint_1 = require('./hint');
4+
var progress_1 = require('./progress');
45
function testRun() {
56
return function (dispatch, getState) {
67
var _a = getState(), taskTests = _a.taskTests, dir = _a.dir, tutorial = _a.tutorial, taskPosition = _a.taskPosition;
@@ -12,11 +13,14 @@ function testRun() {
1213
exports.testRun = testRun;
1314
function testResult(result) {
1415
return function (dispatch, getState) {
15-
var taskActions = getState().taskActions;
16+
var _a = getState(), taskActions = _a.taskActions, progress = _a.progress, pagePosition = _a.pagePosition;
1617
var filter = getTestFilter(result);
17-
if (result.change !== 0) {
18+
if (filter === 'PASS' || filter === 'FAIL') {
1819
dispatch(hint_1.hintPositionSet(0));
1920
}
21+
if (filter === 'FAIL' && progress.pages[pagePosition]) {
22+
dispatch(progress_1.completePage(false));
23+
}
2024
dispatch({ type: _types_1.TEST_RESULT, payload: { result: result, taskActions: taskActions }, filter: filter });
2125
};
2226
}

lib/components/Page/Tasks/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var Tasks = (function (_super) {
2828
var _a = this.props, tasks = _a.tasks, taskPosition = _a.taskPosition, testRun = _a.testRun, completed = _a.completed, page = _a.page;
2929
var visTasks = visibleTasks(tasks, taskPosition);
3030
var backgroundColor = completed ? colors_1.lightGreen200 : 'white';
31-
return (React.createElement("div", null, React.createElement(Card_1.Card, {style: { backgroundColor: backgroundColor, margin: margin }}, React.createElement(List_1.List, null, React.createElement(Subheader_1.default, null, "Tasks"), visTasks.map(function (task, index) { return (React.createElement(Task_1.default, {key: index, index: index, task: task, taskPosition: taskPosition, testRun: testRun})); }))), React.createElement(TasksComplete_1.default, {page: page}), React.createElement("div", {ref: 'listEnd'})));
31+
return (React.createElement("div", null, React.createElement(Card_1.Card, {style: { backgroundColor: backgroundColor, margin: margin }}, React.createElement(List_1.List, null, React.createElement(Subheader_1.default, null, "Tasks"), visTasks.map(function (task, index) { return (React.createElement(Task_1.default, {key: index, index: index, task: task, taskPosition: taskPosition, testRun: testRun})); }))), React.createElement(TasksComplete_1.default, {page: page, completed: completed}), React.createElement("div", {ref: 'listEnd'})));
3232
};
3333
return Tasks;
3434
}(React.Component));

lib/components/Page/TasksComplete/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ var textStyles = {
1212
fontSize: '1.1em'
1313
};
1414
var TasksComplete = function (_a) {
15-
var page = _a.page;
16-
if (!page.completed || !page.onPageComplete) {
15+
var page = _a.page, completed = _a.completed;
16+
if (!completed || !page.onPageComplete) {
1717
return null;
1818
}
1919
return (React.createElement(Card_1.Card, {style: styles}, React.createElement(Card_1.CardText, null, React.createElement(index_1.Markdown, {style: textStyles}, page.onPageComplete))));

lib/components/Page/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ var styles = {
1010
overflowY: 'scroll',
1111
};
1212
var Page = function (_a) {
13-
var page = _a.page, taskPosition = _a.taskPosition, hintPosition = _a.hintPosition, tasks = _a.tasks, testRun = _a.testRun;
13+
var page = _a.page, taskPosition = _a.taskPosition, hintPosition = _a.hintPosition, tasks = _a.tasks, testRun = _a.testRun, progress = _a.progress, pagePosition = _a.pagePosition;
1414
var task = taskPosition <= tasks.length ? tasks[taskPosition] : null;
15-
var completed = page.completed;
15+
var completed = progress.pages[pagePosition];
1616
return (React.createElement("section", {style: styles, className: 'cr-page'}, React.createElement(index_1.ContentCard, {title: page.title, content: page.description}), React.createElement(Tasks_1.default, {tasks: tasks, taskPosition: taskPosition, testRun: testRun, completed: completed, page: page}), React.createElement(PageToolbar_1.default, {tasks: tasks, taskPosition: taskPosition}, React.createElement(Hints_1.default, {task: task, hintPosition: hintPosition}), React.createElement(ProgressBar_1.default, {taskLength: tasks.length, taskPosition: taskPosition, completed: completed}))));
1717
};
1818
Object.defineProperty(exports, "__esModule", { value: true });

lib/reducers/alert/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function alertReducer(alert, action) {
3434
});
3535
case _types_1.TEST_RESULT:
3636
var result = action.payload.result;
37-
switch (action.payload.filter) {
37+
switch (action.filter) {
3838
case 'PASS':
3939
return setAlert({
4040
message: result.msg,

lib/reducers/page/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@ var _types_1 = require('../../actions/_types');
33
var _page = {
44
title: '',
55
description: '',
6-
completed: false,
76
};
87
function pageReducer(p, action) {
98
if (p === void 0) { p = _page; }
109
switch (action.type) {
1110
case _types_1.PAGE_SET:
1211
var _a = action.payload, pagePosition = _a.pagePosition, tutorial = _a.tutorial;
13-
var _b = tutorial.pages[pagePosition], title = _b.title, description = _b.description, onPageComplete = _b.onPageComplete, completed = _b.completed;
12+
var _b = tutorial.pages[pagePosition], title = _b.title, description = _b.description, onPageComplete = _b.onPageComplete;
1413
return {
1514
title: title,
1615
description: description,
1716
onPageComplete: onPageComplete,
18-
completed: completed || false
1917
};
20-
case _types_1.COMPLETE_PAGE:
21-
return Object.assign({}, p, { completed: true });
2218
default:
2319
return p;
2420
}

lib/reducers/progress/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ function progressReducer(progress, action) {
1919
pages: tutorial.pages.map(function () { return false; })
2020
};
2121
case _types_1.COMPLETE_PAGE:
22-
var _a = action.payload, tutorial = _a.tutorial, pagePosition = _a.pagePosition;
23-
progress.pages[pagePosition] = true;
22+
var _a = action.payload, tutorial = _a.tutorial, pagePosition = _a.pagePosition, completed = _a.completed;
23+
progress.pages[pagePosition] = completed;
2424
local_storage_1.saveToLocalStorage(tutorial, progress);
2525
return progress;
2626
case _types_1.COMPLETE_TUTORIAL:
27-
var tutorial = action.payload.tutorial.tutorial;
28-
progress.completed = true;
27+
var _b = action.payload.tutorial, tutorial = _b.tutorial, completed = _b.completed;
28+
progress.completed = completed;
2929
local_storage_1.saveToLocalStorage(tutorial, progress);
3030
return progress;
3131
default:

lib/reducers/tutorial/config-paths.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"use strict";
2+
var path_1 = require('path');
3+
var system_1 = require('../../services/system');
4+
function configTestString(dir, name, config, testPath) {
5+
if (system_1.isWindows) {
6+
testPath = testPath.split('/').join('\\');
7+
}
8+
if (config.dir) {
9+
testPath = path_1.join(config.dir, testPath);
10+
}
11+
else {
12+
testPath = path_1.join(dir, 'node_modules', name, testPath);
13+
}
14+
if (config.testSuffix) {
15+
testPath += config.testSuffix;
16+
}
17+
return testPath;
18+
}
19+
function configPaths(dir, name, config, pages) {
20+
return pages.map(function (page) {
21+
page.tasks.map(function (task) {
22+
task.tests = task.tests.map(function (testPath) {
23+
if (typeof testPath === 'string') {
24+
return configTestString(dir, name, config, testPath);
25+
}
26+
else {
27+
console.error('Invalid task test', testPath);
28+
}
29+
});
30+
return task;
31+
});
32+
return page;
33+
});
34+
}
35+
Object.defineProperty(exports, "__esModule", { value: true });
36+
exports.default = configPaths;

lib/reducers/tutorial/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var path_1 = require('path');
33
var tutorial_config_1 = require('./tutorial-config');
44
var _types_1 = require('../../actions/_types');
5+
var config_paths_1 = require('./config-paths');
56
var _tutorial = {
67
name: null,
78
info: null,
@@ -18,6 +19,7 @@ function tutorialReducer(tutorial, action) {
1819
var packageJson = require(path_1.join(packagePath, 'package.json'));
1920
var config = tutorial_config_1.tutorialConfig(packageJson, dir);
2021
var _b = require(path_1.join(packagePath, packageJson.main)), info = _b.info, pages = _b.pages;
22+
pages = config_paths_1.default(dir, name_1, config, pages || []);
2123
return {
2224
name: packageJson.name,
2325
info: info,

src/actions/alert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {ALERT_REPLAY, ALERT_TOGGLE} from './_types';
22

33
export function alertToggle(alert: Object, filter?: string): ReduxThunk.ThunkInterface {
44
return (dispatch, getState): void => {
5-
dispatch({ type: ALERT_TOGGLE, payload: { alert } });
5+
dispatch({ type: ALERT_TOGGLE, payload: { alert }, filter });
66
};
77
}
88

src/actions/config-task-tests.ts

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

src/actions/page.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
ROUTE_SET, PAGE_SET, PAGE_POSITION_SET
33
} from './_types';
4-
import configTaskTests from './config-task-tests';
54
import {hintPositionSet} from './hint';
65

76
export function pageNext(): ReduxThunk.ThunkInterface | Action {
@@ -21,9 +20,7 @@ export function pageSet(pagePosition = 0): ReduxThunk.ThunkInterface {
2120
return (dispatch, getState): void => {
2221
const {dir, progress, tutorial} = getState();
2322
// create absolute paths for 'task-tests'
24-
const tasks = configTaskTests(
25-
dir, tutorial, tutorial.pages[pagePosition].tasks || []
26-
);
23+
const tasks = tutorial.pages[pagePosition].tasks || [];
2724
if (pagePosition >= progress.pages.length) {
2825
dispatch({ type: ROUTE_SET, payload: { route: 'final' } });
2926
}

0 commit comments

Comments
 (0)