Skip to content

Commit d6096ff

Browse files
committedMay 2, 2016
remove chapters, pages only
·
v0.10.9v0.9.0
1 parent 0ba8a5b commit d6096ff

File tree

35 files changed

+159
-355
lines changed

35 files changed

+159
-355
lines changed
 

‎CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [0.9]
6+
- remove chapters, now only pages
7+
- bug fixes
8+
59
## [0.8.0] - 2016-04-27
610
- save tutorial progress to localStorage
711
- check for tutorial package updates

‎lib/actions/_types.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22
exports.ALERT_REPLAY = 'ALERT_REPLAY';
33
exports.ALERT_TOGGLE = 'ALERT_TOGGLE';
4-
exports.COMPLETE_CHAPTER = 'COMPLETE_CHAPTER';
54
exports.COMPLETE_PAGE = 'COMPLETE_PAGE';
65
exports.COMPLETE_TUTORIAL = 'COMPLETE_TUTORIAL';
76
exports.HINT_POSITION_SET = 'HINT_POSITION_SET';

‎lib/actions/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ exports.alertReplay = alert_1.alertReplay;
55
var progress_1 = require('./progress');
66
exports.progressLoad = progress_1.progressLoad;
77
exports.completePage = progress_1.completePage;
8-
exports.completeChapter = progress_1.completeChapter;
98
exports.completeTutorial = progress_1.completeTutorial;
109
var hint_1 = require('./hint');
1110
exports.hintShow = hint_1.hintShow;

‎lib/actions/page.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,18 @@ var test_1 = require('./test');
33
var _types_1 = require('./_types');
44
var store_1 = require('../store');
55
var _position = {
6-
chapter: 0,
76
page: 0,
87
};
98
function pageNext() {
109
var position = null;
11-
var _a = store_1.default.getState().position, page = _a.page, chapter = _a.chapter;
12-
var chapters = store_1.default.getState().tutorial.chapters;
13-
if (page < chapters[chapter].pages.length - 1) {
10+
var page = store_1.default.getState().position.page;
11+
var pages = store_1.default.getState().tutorial.pages;
12+
if (page < pages.length - 1) {
1413
store_1.default.dispatch(test_1.testsLoad());
1514
position = {
16-
chapter: chapter,
1715
page: page + 1,
1816
};
1917
}
20-
else if (chapter < chapters.length - 1) {
21-
store_1.default.dispatch(test_1.testsLoad());
22-
position = {
23-
chapter: chapter + 1,
24-
page: 0,
25-
};
26-
}
2718
else {
2819
return {
2920
payload: { route: 'final' },

‎lib/actions/progress.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,16 @@ function isTrue(x) {
1414
}
1515
function completePage() {
1616
var position = store_1.default.getState().position;
17-
var chapter = store_1.default.getState().progress.chapters[position.chapter];
18-
if (chapter.pages.every(function (x) { return x; })) {
19-
store_1.default.dispatch(completeChapter());
17+
var progress = store_1.default.getState().progress;
18+
if (progress.pages.every(function (x) { return x.completed; })) {
19+
store_1.default.dispatch(completeTutorial());
2020
}
2121
return {
2222
payload: { position: position },
2323
type: _types_1.COMPLETE_PAGE,
2424
};
2525
}
2626
exports.completePage = completePage;
27-
function completeChapter() {
28-
var chapter = store_1.default.getState().position.chapter;
29-
var progress = store_1.default.getState().progress;
30-
if (progress.chapters.every(function (x) { return x.completed; })) {
31-
store_1.default.dispatch(completeTutorial());
32-
}
33-
return {
34-
payload: { chapter: chapter },
35-
type: _types_1.COMPLETE_CHAPTER,
36-
};
37-
}
38-
exports.completeChapter = completeChapter;
3927
function completeTutorial() {
4028
return { type: _types_1.COMPLETE_TUTORIAL };
4129
}

‎lib/components/App.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ var App = (function (_super) {
3535
_super.apply(this, arguments);
3636
}
3737
App.prototype.render = function () {
38-
return (React.createElement("section", {className: 'cr', key: 'main', style: { height: height }}, React.createElement(index_1.AppMenu, __assign({}, this.props.store)), React.createElement(Routes_1.Routes, __assign({}, this.props.store)), React.createElement(index_1.Alert, __assign({}, this.props.store))));
38+
var store = this.props.store;
39+
console.log(store);
40+
return (React.createElement("section", {className: 'cr', key: 'main', style: { height: height }}, React.createElement(index_1.AppMenu, __assign({}, store)), React.createElement(Routes_1.Routes, __assign({}, store)), React.createElement(index_1.Alert, __assign({}, store))));
3941
};
4042
App = __decorate([
4143
react_redux_1.connect(function (store) {

‎lib/components/Page/Chapter/index.js

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

‎lib/components/Progress/ProgressChapter/index.js

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

‎lib/components/Progress/ProgressPage/index.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,19 @@ var ProgressPage = (function (_super) {
2929
_super.apply(this, arguments);
3030
}
3131
ProgressPage.prototype.canActivate = function (isActive) {
32-
var _a = this.props, chapterIndex = _a.chapterIndex, pageIndex = _a.pageIndex, position = _a.position, progress = _a.progress;
33-
var completed = progress.chapters[chapterIndex].pages[pageIndex];
34-
var currentChapter = chapterIndex === position.chapter;
35-
var earlierOrCurrentPage = pageIndex <= position.page;
36-
return isActive || completed ||
37-
(currentChapter && earlierOrCurrentPage);
32+
var _a = this.props, index = _a.index, position = _a.position, progress = _a.progress;
33+
var completed = progress.pages[index];
34+
return isActive || completed;
3835
};
3936
ProgressPage.prototype.render = function () {
40-
var _a = this.props, page = _a.page, position = _a.position, chapterIndex = _a.chapterIndex, pageIndex = _a.pageIndex, progress = _a.progress, selectPage = _a.selectPage;
41-
var isActive = chapterIndex === position.chapter && pageIndex === position.page;
37+
console.log(this.props);
38+
var _a = this.props, page = _a.page, position = _a.position, index = _a.index, progress = _a.progress, selectPage = _a.selectPage;
39+
var isActive = index === position.page;
4240
var canActivate = this.canActivate(isActive);
43-
var completed = progress.chapters[chapterIndex].pages[pageIndex];
44-
return (React.createElement(List_1.ListItem, {key: pageIndex, style: Object.assign({}, styles, !canActivate ? { color: colors_1.grey400 } : {}), primaryText: (pageIndex + 1) + ". " + page.title, secondaryText: canActivate ? page.description : '', leftIcon: progressIcon_1.progressIcon(completed, isActive), onClick: canActivate
41+
var completed = progress.pages[index];
42+
return (React.createElement(List_1.ListItem, {key: index, style: Object.assign({}, styles, !canActivate ? { color: colors_1.grey400 } : {}), primaryText: (index + 1) + ". " + page.title, secondaryText: canActivate ? page.description : '', leftIcon: progressIcon_1.progressIcon(completed, isActive), onClick: canActivate
4543
? selectPage.bind(this, {
46-
chapter: chapterIndex,
47-
page: pageIndex
44+
page: index
4845
})
4946
: function () { return; }}));
5047
};

‎lib/components/Progress/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ var React = require('react');
33
var Paper_1 = require('material-ui/Paper');
44
var List_1 = require('material-ui/List');
55
var Subheader_1 = require('material-ui/Subheader');
6-
var ProgressChapter_1 = require('./ProgressChapter');
6+
var ProgressPage_1 = require('./ProgressPage');
77
var pageStyle = {
88
width: '100%',
99
margin: '0px',
1010
};
1111
exports.Progress = function (_a) {
1212
var progress = _a.progress, position = _a.position, info = _a.info, tutorial = _a.tutorial;
13-
return (React.createElement(Paper_1.default, {style: pageStyle}, React.createElement(List_1.List, null, React.createElement(Subheader_1.default, null, info.name), tutorial.chapters.map(function (chapter, chapterIndex) { return (React.createElement(ProgressChapter_1.ProgressChapter, {key: chapterIndex, chapter: chapter, chapterIndex: chapterIndex, position: position, progress: progress})); }))));
13+
return (React.createElement(Paper_1.default, {style: pageStyle}, React.createElement(List_1.List, null, React.createElement(Subheader_1.default, null, info.name), tutorial.pages.map(function (page, index) { return (React.createElement(ProgressPage_1.ProgressPage, {key: index, index: index, page: page, position: position, progress: progress})); }))));
1414
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var SelectTutorial = (function (_super) {
4141
return {
4242
selectTutorial: function (name) {
4343
dispatch(actions_1.tutorialSet(name));
44-
dispatch(actions_1.positionSet({ chapter: 0, page: 0 }));
44+
dispatch(actions_1.positionSet({ page: 0 }));
4545
dispatch(actions_1.progressLoad());
4646
dispatch(actions_1.routeSet('progress'));
4747
},

‎lib/reducers/alert/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ function alertReducer(alert, action) {
5555
return setAlert({
5656
message: "Page " + (action.payload.position.page + 1) + " Complete",
5757
});
58-
case _types_1.COMPLETE_CHAPTER:
59-
return setAlert({
60-
message: "Chapter " + (action.payload.chapter + 1) + " Complete",
61-
});
6258
case _types_1.COMPLETE_TUTORIAL:
6359
return setAlert({
6460
message: 'Tutorial Complete',

‎lib/reducers/page/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ function pageReducer(p, action) {
1111
if (p === void 0) { p = _page; }
1212
switch (action.type) {
1313
case _types_1.PAGE_SET:
14-
var _a = action.payload.position, chapter = _a.chapter, page = _a.page;
15-
var _b = store_1.default.getState().tutorial
16-
.chapters[chapter].pages[page], title = _b.title, description = _b.description, onPageComplete = _b.onPageComplete, completed = _b.completed;
14+
var page = action.payload.position.page;
15+
var _a = store_1.default.getState().tutorial.pages[page], title = _a.title, description = _a.description, onPageComplete = _a.onPageComplete, completed = _a.completed;
1716
editor_1.clearConsole();
1817
return {
1918
title: title,

‎lib/reducers/position/index.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@
22
var _types_1 = require('../../actions/_types');
33
var store_1 = require('../../store');
44
var _position = {
5-
chapter: 0,
65
page: 0,
76
};
87
function positionReducer(position, action) {
98
if (position === void 0) { position = _position; }
109
switch (action.type) {
1110
case _types_1.POSITION_LOAD:
12-
var chapters = store_1.default.getState().progress.chapters;
13-
var chapter = chapters.indexOf(function (x) { return !x.completed; });
14-
if (chapter < 0) {
15-
chapter = chapters.length - 1;
16-
}
17-
var progressPage = chapters[chapter].pages;
18-
var page = progressPage.indexOf(function (x) { return !x; });
11+
var pages = store_1.default.getState().progress.pages;
12+
var page = pages.indexOf(function (x) { return !x; });
1913
if (page < 0) {
20-
page = progressPage.length - 1;
14+
page = pages.length - 1;
2115
}
22-
return { chapter: chapter, page: page };
16+
return { page: page };
2317
case _types_1.PAGE_SET:
2418
case _types_1.POSITION_SET:
2519
return action.payload.position;

‎lib/reducers/progress/index.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,23 @@ var local_storage_1 = require('./local-storage');
44
var store_1 = require('../../store');
55
var _progress = {
66
completed: false,
7-
chapters: []
7+
pages: []
88
};
99
function progressReducer(progress, action) {
1010
if (progress === void 0) { progress = _progress; }
1111
switch (action.type) {
1212
case _types_1.PROGRESS_LOAD:
13-
var tutorial = store_1.default.getState().tutorial;
1413
var saved = local_storage_1.loadProgressFromLocalStorage();
1514
if (saved) {
1615
return saved;
1716
}
1817
return {
1918
completed: false,
20-
chapters: !tutorial.chapters
21-
? []
22-
: tutorial.chapters.map(function (chapter) {
23-
return {
24-
completed: false,
25-
pages: chapter.pages.map(function () { return false; })
26-
};
27-
})
19+
pages: store_1.default.getState().tutorial.pages.map(function () { return false; })
2820
};
2921
case _types_1.COMPLETE_PAGE:
30-
var _a = action.payload.position, chapter = _a.chapter, page = _a.page;
31-
progress.chapters[chapter].pages[page] = true;
32-
local_storage_1.saveToLocalStorage(progress);
33-
return progress;
34-
case _types_1.COMPLETE_CHAPTER:
35-
progress.chapters[action.payload.chapter].completed = true;
22+
var page = action.payload.position.page;
23+
progress.pages[page] = true;
3624
local_storage_1.saveToLocalStorage(progress);
3725
return progress;
3826
case _types_1.COMPLETE_TUTORIAL:

‎lib/reducers/tasks/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function tasksReducer(tasks, action) {
1313
if (tasks === void 0) { tasks = _tasks; }
1414
switch (action.type) {
1515
case _types_1.PAGE_SET:
16-
var _a = action.payload.position, chapter = _a.chapter, page = _a.page;
17-
return config_task_tests_1.configTaskTests(store_1.default.getState().tutorial.chapters[chapter].pages[page].tasks || []);
16+
var page = action.payload.position.page;
17+
return config_task_tests_1.configTaskTests(store_1.default.getState().tutorial.pages[page].tasks || []);
1818
default:
1919
return tasks;
2020
}

‎lib/reducers/tutorial/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var store_1 = require('../../store');
66
var _tutorial = {
77
name: null,
88
info: null,
9-
chapters: [],
9+
pages: [],
1010
packageJson: null,
1111
config: null,
1212
};
@@ -19,11 +19,11 @@ function tutorialReducer(tutorial, action) {
1919
var packagePath = path_1.join(dir, 'node_modules', name_1);
2020
var packageJson = require(path_1.join(packagePath, 'package.json'));
2121
var config = tutorial_config_1.tutorialConfig(packageJson);
22-
var _a = require(path_1.join(packagePath, packageJson.main)), info = _a.info, chapters = _a.chapters;
22+
var _a = require(path_1.join(packagePath, packageJson.main)), info = _a.info, pages = _a.pages;
2323
return {
2424
name: packageJson.name,
2525
info: info,
26-
chapters: chapters,
26+
pages: pages,
2727
packageJson: packageJson,
2828
config: config,
2929
};

‎src/actions/_types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export const ALERT_REPLAY = 'ALERT_REPLAY';
22
export const ALERT_TOGGLE = 'ALERT_TOGGLE';
3-
export const COMPLETE_CHAPTER = 'COMPLETE_CHAPTER';
43
export const COMPLETE_PAGE = 'COMPLETE_PAGE';
54
export const COMPLETE_TUTORIAL = 'COMPLETE_TUTORIAL';
65
export const HINT_POSITION_SET = 'HINT_POSITION_SET';

‎src/actions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export {alertToggle, alertReplay} from './alert';
22
export {
3-
progressLoad, completePage, completeChapter, completeTutorial
3+
progressLoad, completePage, completeTutorial
44
} from './progress';
55
export {hintShow, hintPositionSet} from './hint';
66
export {pageSet, pageNext} from './page';

‎src/actions/page.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,18 @@ import {ROUTE_SET, PAGE_SET} from './_types';
33
import store from '../store';
44

55
const _position = {
6-
chapter: 0,
76
page: 0,
87
};
98

109
export function pageNext(): Action {
1110
let position = null;
12-
const {page, chapter} = store.getState().position;
13-
const {chapters} = store.getState().tutorial;
14-
if (page < chapters[chapter].pages.length - 1) {
11+
const {page} = store.getState().position;
12+
const {pages} = store.getState().tutorial;
13+
if (page < pages.length - 1) {
1514
store.dispatch(testsLoad());
1615
position = {
17-
chapter,
1816
page: page + 1,
1917
};
20-
} else if (chapter < chapters.length - 1) {
21-
store.dispatch(testsLoad());
22-
position = {
23-
chapter: chapter + 1,
24-
page: 0,
25-
};
2618
} else {
2719
return {
2820
payload: { route: 'final' },

‎src/actions/progress.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
PROGRESS_LOAD, COMPLETE_PAGE, COMPLETE_CHAPTER, COMPLETE_TUTORIAL
2+
PROGRESS_LOAD, COMPLETE_PAGE, COMPLETE_TUTORIAL
33
} from './_types';
44
import {positionLoad} from './position';
55
import store from '../store';
@@ -17,27 +17,14 @@ function isTrue(x) {
1717

1818
export function completePage(): Action {
1919
const position: CR.Position = store.getState().position;
20-
const chapter = store.getState().progress.chapters[position.chapter];
21-
// all pages are true, chapter complete
22-
if (chapter.pages.every(x => x)) {
23-
store.dispatch(completeChapter());
24-
}
25-
return {
26-
payload: { position },
27-
type: COMPLETE_PAGE,
28-
};
29-
}
30-
31-
export function completeChapter(): Action {
32-
const chapter: number = store.getState().position.chapter;
3320
const progress = store.getState().progress;
34-
// all chapters complete, tutorial complete
35-
if (progress.chapters.every(x => x.completed)) {
21+
// all pages are true, tutorial complete
22+
if (progress.pages.every(x => x.completed)) {
3623
store.dispatch(completeTutorial());
3724
}
3825
return {
39-
payload: { chapter },
40-
type: COMPLETE_CHAPTER,
26+
payload: { position },
27+
type: COMPLETE_PAGE,
4128
};
4229
}
4330

‎src/components/App.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ window.onresize = function() {
1313
})
1414
export class App extends React.Component<{store?: CR.State}, {}> {
1515
render(): React.ReactElement<{}> {
16+
const store = this.props.store;
17+
console.log(store);
1618
return (
1719
<section
1820
className='cr'
1921
key='main'
2022
style={{height}}
2123
>
22-
<AppMenu {...this.props.store} />
23-
<Routes {...this.props.store} />
24-
<Alert {...this.props.store} />
24+
<AppMenu {...store} />
25+
<Routes {...store} />
26+
<Alert {...store} />
2527
</section>
2628
);
2729
}

‎src/components/Page/Chapter/index.tsx

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

‎src/components/Progress/ProgressChapter/index.tsx

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

‎src/components/Progress/ProgressPage/index.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,30 @@ const styles = {
2121
};
2222
})
2323
export class ProgressPage extends React.Component<{
24-
page: CR.Page, chapterIndex: number, progress: CR.Progress,
25-
position: CR.Position, pageIndex: number, selectPage?: () => void}, {}> {
24+
page: CR.Page, progress: CR.Progress,
25+
position: CR.Position, index: number, selectPage?: () => void}, {}> {
2626
canActivate(isActive: boolean) {
27-
const {chapterIndex, pageIndex, position, progress} = this.props;
28-
const completed = progress.chapters[chapterIndex].pages[pageIndex];
29-
const currentChapter = chapterIndex === position.chapter;
30-
const earlierOrCurrentPage = pageIndex <= position.page;
31-
return isActive || completed ||
32-
(currentChapter && earlierOrCurrentPage);
27+
const {index, position, progress} = this.props;
28+
const completed = progress.pages[index];
29+
return isActive || completed;
3330
}
3431
render() {
35-
const {page, position, chapterIndex, pageIndex, progress, selectPage} = this.props;
36-
const isActive = chapterIndex === position.chapter && pageIndex === position.page;
32+
console.log(this.props);
33+
const {page, position, index, progress, selectPage} = this.props;
34+
const isActive = index === position.page;
3735
const canActivate = this.canActivate(isActive);
38-
const completed = progress.chapters[chapterIndex].pages[pageIndex];
36+
const completed = progress.pages[index];
3937
return (
4038
<ListItem
41-
key={pageIndex}
39+
key={index}
4240
style={Object.assign({}, styles, !canActivate ? {color: grey400} : {})}
43-
primaryText={`${pageIndex + 1}. ${page.title}`}
41+
primaryText={`${index + 1}. ${page.title}`}
4442
secondaryText={canActivate ? page.description : ''}
4543
leftIcon={progressIcon(completed, isActive)}
4644
onClick={
4745
canActivate
4846
? selectPage.bind(this, {
49-
chapter: chapterIndex,
50-
page: pageIndex
47+
page: index
5148
})
5249
: function () { return; }
5350
}

‎src/components/Progress/index.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import Paper from 'material-ui/Paper';
33
import {List} from 'material-ui/List';
44
import Subheader from 'material-ui/Subheader';
5-
import {ProgressChapter} from './ProgressChapter';
5+
import {ProgressPage} from './ProgressPage';
66

77
const pageStyle = {
88
width: '100%',
@@ -16,15 +16,16 @@ export const Progress: React.StatelessComponent<{
1616
<Paper style={pageStyle}>
1717
<List>
1818
<Subheader>{info.name}</Subheader>
19-
{tutorial.chapters.map((chapter: CR.Chapter, chapterIndex: number) => (
20-
<ProgressChapter
21-
key={chapterIndex}
22-
chapter={chapter}
23-
chapterIndex={chapterIndex}
19+
{tutorial.pages.map((page: CR.Page, index: number) => (
20+
<ProgressPage
21+
key={index}
22+
index={index}
23+
page={page}
2424
position={position}
2525
progress={progress}
2626
/>
27-
))}
27+
))
28+
}
2829
</List>
2930
</Paper>
3031
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function displayName(name: string): string {
1818
return {
1919
selectTutorial: (name: string) => {
2020
dispatch(tutorialSet(name));
21-
dispatch(positionSet({chapter: 0, page: 0}));
21+
dispatch(positionSet({page: 0}));
2222
dispatch(progressLoad());
2323
dispatch(routeSet('progress'));
2424
},

‎src/reducers/alert/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
ALERT_REPLAY, ALERT_TOGGLE, TEST_RESULT,
3-
COMPLETE_PAGE, COMPLETE_CHAPTER, COMPLETE_TUTORIAL,
3+
COMPLETE_PAGE, COMPLETE_TUTORIAL,
44
TUTORIAL_UPDATE
55
} from '../../actions/_types';
66

@@ -65,10 +65,6 @@ export default function alertReducer(
6565
return setAlert({
6666
message: `Page ${action.payload.position.page + 1} Complete`,
6767
});
68-
case COMPLETE_CHAPTER:
69-
return setAlert({
70-
message: `Chapter ${action.payload.chapter + 1} Complete`,
71-
});
7268
case COMPLETE_TUTORIAL:
7369
return setAlert({
7470
message: 'Tutorial Complete',

‎src/reducers/page/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ export default function pageReducer(
1313
): CR.Page {
1414
switch (action.type) {
1515
case PAGE_SET:
16-
const {chapter, page} = action.payload.position;
17-
const {title, description, onPageComplete, completed} = store.getState().tutorial
18-
.chapters[chapter].pages[page];
16+
const {page} = action.payload.position;
17+
const {title, description, onPageComplete, completed} = store.getState().tutorial.pages[page];
1918
// clear dev console
2019
clearConsole();
2120
return {

‎src/reducers/position/index.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
import store from '../../store';
55

66
const _position: CR.Position = {
7-
chapter: 0,
87
page: 0,
98
};
109

@@ -13,17 +12,13 @@ export default function positionReducer(
1312
): CR.Position {
1413
switch (action.type) {
1514
case POSITION_LOAD:
16-
const chapters = store.getState().progress.chapters;
17-
let chapter = chapters.indexOf(x => !x.completed);
18-
if (chapter < 0) {
19-
chapter = chapters.length - 1;
20-
}
21-
const progressPage = chapters[chapter].pages;
22-
let page = progressPage.indexOf(x => !x);
15+
const pages = store.getState().progress.pages;
16+
let page = pages.indexOf(x => !x);
17+
// all pages complete ? page = -1
2318
if (page < 0) {
24-
page = progressPage.length - 1;
19+
page = pages.length - 1;
2520
}
26-
return { chapter, page };
21+
return { page };
2722
case PAGE_SET:
2823
case POSITION_SET:
2924
return action.payload.position;

‎src/reducers/progress/index.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,30 @@
11
import {
2-
PROGRESS_LOAD, COMPLETE_PAGE, COMPLETE_CHAPTER, COMPLETE_TUTORIAL
2+
PROGRESS_LOAD, COMPLETE_PAGE, COMPLETE_TUTORIAL
33
} from '../../actions/_types';
44
import {loadProgressFromLocalStorage, saveToLocalStorage} from './local-storage';
55
import store from '../../store';
66

77
const _progress: CR.Progress = {
88
completed: false,
9-
chapters: []
9+
pages: []
1010
};
1111

1212
export default function progressReducer(
1313
progress = _progress, action: Action
1414
): CR.Progress {
1515
switch (action.type) {
1616
case PROGRESS_LOAD:
17-
const tutorial = store.getState().tutorial;
1817
// load saved progress
1918
const saved = loadProgressFromLocalStorage();
2019
if (saved) { return saved; }
2120
// set progress defaults
2221
return {
2322
completed: false,
24-
chapters: !tutorial.chapters
25-
? []
26-
: tutorial.chapters.map((chapter) => {
27-
return {
28-
completed: false,
29-
pages: chapter.pages.map(() => false)
30-
};
31-
})
23+
pages: store.getState().tutorial.pages.map(() => false)
3224
};
3325
case COMPLETE_PAGE:
34-
const {chapter, page} = action.payload.position;
35-
progress.chapters[chapter].pages[page] = true;
36-
saveToLocalStorage(progress);
37-
return progress;
38-
case COMPLETE_CHAPTER:
39-
progress.chapters[action.payload.chapter].completed = true;
26+
const {page} = action.payload.position;
27+
progress.pages[page] = true;
4028
saveToLocalStorage(progress);
4129
return progress;
4230
case COMPLETE_TUTORIAL:

‎src/reducers/tasks/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export default function tasksReducer(tasks = _tasks,
1414
action: Action): CR.Task[] {
1515
switch (action.type) {
1616
case PAGE_SET:
17-
const {chapter, page} = action.payload.position;
17+
const {page} = action.payload.position;
1818
return configTaskTests(
19-
store.getState().tutorial.chapters[chapter].pages[page].tasks || []
19+
store.getState().tutorial.pages[page].tasks || []
2020
);
2121
default:
2222
return tasks;

‎src/reducers/tutorial/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {join} from 'path';
33
import {tutorialConfig} from './tutorial-config';
44
import store from '../../store';
55

6-
const _tutorial = {
6+
const _tutorial: CR.Tutorial = {
77
name: null,
88
info: null,
9-
chapters: [],
9+
pages: [],
1010
packageJson: null,
1111
config: null,
1212
};
@@ -21,11 +21,11 @@ export default function tutorialReducer(
2121
const packagePath: string = join(dir, 'node_modules', name);
2222
const packageJson: PackageJson = require(join(packagePath, 'package.json'));
2323
const config: Tutorial.Config = tutorialConfig(packageJson);
24-
const {info, chapters} = require(join(packagePath, packageJson.main));
24+
const {info, pages} = require(join(packagePath, packageJson.main));
2525
return {
2626
name: packageJson.name,
2727
info,
28-
chapters,
28+
pages,
2929
packageJson,
3030
config,
3131
};

‎src/typings/cr/cr.d.ts

Lines changed: 65 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,80 @@
11
declare namespace CR {
22

3-
interface Info {
4-
title: string;
5-
description: string;
6-
completed: boolean;
7-
}
3+
interface Info {
4+
title: string;
5+
description: string;
6+
completed: boolean;
7+
}
88

9-
interface Chapter extends Info {
10-
pages: Page[];
11-
}
12-
interface Page extends Info {
13-
tasks?: Task[];
14-
onPageComplete?: string;
15-
}
16-
interface Task {
17-
description: string;
18-
tests?: string[];
19-
hints?: string[];
20-
actions?: string[];
21-
completed?: boolean;
22-
}
9+
interface Page extends Info {
10+
tasks?: Task[];
11+
onPageComplete?: string;
12+
}
13+
interface Task {
14+
description: string;
15+
tests?: string[];
16+
hints?: string[];
17+
actions?: string[];
18+
completed?: boolean;
19+
}
2320

24-
interface State {
25-
dir: string;
26-
route: string;
27-
tutorialInfo: Tutorial.Info;
28-
position: Position;
29-
package: PackageJson;
30-
page: Page;
31-
progress: Progress;
32-
tasks: Task[];
33-
taskTests: string[];
34-
taskPosition: number;
35-
hintPosition: number;
36-
editorActions: string[];
37-
alert: Alert;
38-
tutorial: Tutorial;
39-
tutorials: Tutorial.Info[];
40-
testRun: boolean;
41-
checks: Checks;
42-
}
21+
interface State {
22+
dir: string;
23+
route: string;
24+
tutorialInfo: Tutorial.Info;
25+
position: Position;
26+
package: PackageJson;
27+
page: Page;
28+
progress: Progress;
29+
tasks: Task[];
30+
taskTests: string[];
31+
taskPosition: number;
32+
hintPosition: number;
33+
editorActions: string[];
34+
alert: Alert;
35+
tutorial: Tutorial;
36+
tutorials: Tutorial.Info[];
37+
testRun: boolean;
38+
checks: Checks;
39+
}
4340

44-
interface Tutorial {
45-
name: string;
46-
info: Tutorial.Info;
47-
chapters: CR.Chapter[];
48-
packageJson: PackageJson;
49-
config: Tutorial.Config;
50-
}
41+
interface Tutorial {
42+
name: string;
43+
info: Tutorial.Info;
44+
pages: CR.Page[];
45+
packageJson: PackageJson;
46+
config: Tutorial.Config;
47+
}
5148

49+
type Position = number;
5250

53-
interface Position {
54-
chapter: number;
55-
page: number;
56-
completed?: boolean;
57-
}
58-
59-
interface Progress {
60-
completed: boolean;
61-
chapters: {
51+
interface Progress {
6252
completed: boolean;
6353
pages: boolean[];
64-
}[];
65-
}
54+
}
6655

67-
type TaskTest = string[];
56+
type TaskTest = string[];
6857

69-
interface Alert {
70-
message: string;
71-
action: string;
72-
open?: boolean;
73-
duration?: number;
74-
}
58+
interface Alert {
59+
message: string;
60+
action: string;
61+
open?: boolean;
62+
duration?: number;
63+
}
7564

76-
interface Checks {
77-
passed?: boolean;
78-
system: {
79-
passed?: boolean;
80-
node: boolean;
81-
npm: boolean;
82-
};
83-
setup: {
65+
interface Checks {
8466
passed?: boolean;
85-
dir: boolean;
86-
packageJson: boolean;
87-
tutorial: boolean;
88-
};
89-
}
67+
system: {
68+
passed?: boolean;
69+
node: boolean;
70+
npm: boolean;
71+
};
72+
setup: {
73+
passed?: boolean;
74+
dir: boolean;
75+
packageJson: boolean;
76+
tutorial: boolean;
77+
};
78+
}
9079

9180
}

‎tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@
129129
"src/components/Common/RouteButton.tsx",
130130
"src/components/FinalPage/index.tsx",
131131
"src/components/Markdown/index.tsx",
132-
"src/components/Page/Chapter/index.tsx",
133132
"src/components/Page/EditPage/index.tsx",
134133
"src/components/Page/Hints/HintButton.tsx",
135134
"src/components/Page/Hints/index.tsx",
@@ -145,7 +144,6 @@
145144
"src/components/Page/Tasks/index.tsx",
146145
"src/components/Page/TasksComplete/index.tsx",
147146
"src/components/Progress/index.tsx",
148-
"src/components/Progress/ProgressChapter/index.tsx",
149147
"src/components/Progress/progressIcon.tsx",
150148
"src/components/Progress/ProgressPage/index.tsx",
151149
"src/components/render.tsx",

0 commit comments

Comments
 (0)
Please sign in to comment.