Skip to content

Commit a6f6a14

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

File tree

26 files changed

+168
-69
lines changed

26 files changed

+168
-69
lines changed

lib/actions/alert.js

+1-1
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/page.js

+1-2
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

+20-11
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

+6-2
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

+1-1
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

+2-2
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

+2-2
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

+1-1
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

+1-5
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

+4-4
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

+36
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

+2
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

+1-1
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/page.ts

+1-4
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
}

src/actions/progress.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
PROGRESS_PAGE_POSITION_LOAD, PROGRESS_LOAD, COMPLETE_PAGE, COMPLETE_TUTORIAL
33
} from './_types';
44
import {alertToggle} from './alert';
5+
import {testRun} from './test';
56

67
export function progressPagePositionLoad(): ReduxThunk.ThunkInterface {
78
return (dispatch, getState): void => {
@@ -16,29 +17,34 @@ export function progressLoad(): ReduxThunk.ThunkInterface {
1617
dispatch({ type: PROGRESS_LOAD, payload: { tutorial } });
1718
// call pagePositionLoad after progress loads
1819
dispatch(progressPagePositionLoad());
20+
dispatch(testRun());
1921
};
2022
}
2123

22-
export function completePage(): ReduxThunk.ThunkInterface {
24+
export function completePage(completed = true): ReduxThunk.ThunkInterface {
2325
return (dispatch, getState): void => {
2426
const {pagePosition, progress, tutorial} = getState();
2527
// all pages are true, tutorial complete
26-
dispatch({ type: COMPLETE_PAGE, payload: { pagePosition, tutorial } });
27-
if (progress.pages.every(x => x.completed)) {
28-
dispatch(completeTutorial());
29-
} else {
30-
dispatch(alertToggle({
31-
message: `Page ${pagePosition + 1} Complete`,
32-
action: 'pass',
33-
}));
28+
dispatch({ type: COMPLETE_PAGE, payload: { pagePosition, tutorial, completed } });
29+
if (completed) {
30+
if (progress.pages.every(x => x.completed)) {
31+
dispatch(completeTutorial());
32+
} else {
33+
dispatch(alertToggle({
34+
message: `Page ${pagePosition + 1} Complete`,
35+
action: 'pass',
36+
}));
37+
}
38+
} else if (progress.completed) {
39+
dispatch(completeTutorial(false));
3440
}
3541
};
3642
}
3743

38-
export function completeTutorial(): ReduxThunk.ThunkInterface {
44+
export function completeTutorial(completed = true): ReduxThunk.ThunkInterface {
3945
return (dispatch, getState): void => {
4046
const {tutorial} = getState();
41-
dispatch({ type: COMPLETE_TUTORIAL, payload: { tutorial } });
47+
dispatch({ type: COMPLETE_TUTORIAL, payload: { tutorial, completed } });
4248
dispatch(alertToggle({
4349
message: 'Tutorial Complete',
4450
action: 'pass',

src/actions/test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
TEST_RUN, TEST_RESULT, TEST_COMPLETE, TEST_SAVE
33
} from './_types';
44
import {hintPositionSet} from './hint';
5+
import {completePage} from './progress';
56

67
export function testRun(): ReduxThunk.ThunkInterface {
78
return (dispatch, getState): void => {
@@ -14,11 +15,14 @@ export function testRun(): ReduxThunk.ThunkInterface {
1415

1516
export function testResult(result: Test.Result): ReduxThunk.ThunkInterface {
1617
return (dispatch, getState): void => {
17-
const {taskActions} = getState();
18+
const {taskActions, progress, pagePosition} = getState();
1819
const filter: string = getTestFilter(result);
19-
if (result.change !== 0) {
20+
if (filter === 'PASS' || filter === 'FAIL') {
2021
dispatch(hintPositionSet(0));
2122
}
23+
if (filter === 'FAIL' && progress.pages[pagePosition]) {
24+
dispatch(completePage(false));
25+
}
2226
dispatch({ type: TEST_RESULT, payload: { result, taskActions }, filter });
2327
};
2428
}

src/components/Page/Tasks/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export default class Tasks extends React.Component<{
4545
</List>
4646
</Card>
4747

48-
<TasksComplete page={page} />
48+
<TasksComplete
49+
page={page}
50+
completed={completed}
51+
/>
4952

5053
<div ref='listEnd' />
5154
</div>

src/components/Page/TasksComplete/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const textStyles = {
1414
};
1515

1616
const TasksComplete: React.StatelessComponent<{
17-
page: CR.Page
18-
}> = ({page}) => {
19-
if (!page.completed || !page.onPageComplete) { return null; }
17+
page: CR.Page, completed: boolean
18+
}> = ({page, completed}) => {
19+
if (!completed || !page.onPageComplete) { return null; }
2020
return (
2121
<Card style={styles}>
2222
<CardText>

src/components/Page/index.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ const styles = {
1414

1515
const Page: React.StatelessComponent<{
1616
page: CR.Page, tasks: CR.Task[], taskPosition: number,
17-
hintPosition: number, testRun: boolean
18-
}> = ({page, taskPosition, hintPosition, tasks, testRun}) => {
17+
hintPosition: number, testRun: boolean,
18+
progress: CR.Progress, pagePosition: number
19+
}> = ({page, taskPosition, hintPosition, tasks, testRun, progress, pagePosition}) => {
1920
const task = taskPosition <= tasks.length ? tasks[taskPosition] : null;
20-
const completed = page.completed;
21+
const completed = progress.pages[pagePosition];
2122
return (
2223
<section style={styles} className='cr-page'>
2324
<ContentCard

src/reducers/alert/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function alertReducer(
4646
case TEST_RESULT:
4747
const result = action.payload.result;
4848

49-
switch (action.payload.filter) {
49+
switch (action.filter) {
5050

5151
case 'PASS':
5252
return setAlert({

0 commit comments

Comments
 (0)