Skip to content

Commit 8f1954c

Browse files
committed
save progress to localStorage
1 parent 0b1ffd7 commit 8f1954c

File tree

32 files changed

+186
-141
lines changed

32 files changed

+186
-141
lines changed

lib/actions/_types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ exports.HINT_POSITION_SET = 'HINT_POSITION_SET';
88
exports.HINT_SHOW = 'HINT_SHOW';
99
exports.PACKAGE_SET = 'PACKAGE_SET';
1010
exports.PAGE_SET = 'PAGE_SET';
11+
exports.POSITION_LOAD = 'POSITION_LOAD';
1112
exports.POSITION_SET = 'POSITION_SET';
1213
exports.PROGRESS_LOAD = 'PROGRESS_LOAD';
1314
exports.ROUTE_SET = 'ROUTE_SET';

lib/actions/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var page_1 = require('./page');
1414
exports.pageSet = page_1.pageSet;
1515
exports.pageNext = page_1.pageNext;
1616
var position_1 = require('./position');
17+
exports.positionLoad = position_1.positionLoad;
1718
exports.positionSet = position_1.positionSet;
1819
var route_1 = require('./route');
1920
exports.routeSet = route_1.routeSet;

lib/actions/position.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"use strict";
22
var _types_1 = require('./_types');
3+
function positionLoad() {
4+
return { type: _types_1.POSITION_LOAD };
5+
}
6+
exports.positionLoad = positionLoad;
37
function positionSet(position) {
48
return {
59
payload: { position: position },

lib/actions/progress.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
"use strict";
22
var _types_1 = require('./_types');
3+
var position_1 = require('./position');
34
var store_1 = require('../store');
45
function progressLoad() {
6+
setTimeout(function () {
7+
store_1.default.dispatch(position_1.positionLoad());
8+
});
59
return { type: _types_1.PROGRESS_LOAD };
610
}
711
exports.progressLoad = progressLoad;
12+
function isTrue(x) {
13+
return x === true;
14+
}
815
function completePage() {
916
var position = store_1.default.getState().position;
10-
var pageLength = store_1.default.getState().progress.chapters[position.chapter].pages.length;
11-
if (position.page >= pageLength - 1) {
17+
var chapter = store_1.default.getState().progress.chapters[position.chapter];
18+
if (chapter.pages.every(function (x) { return x; })) {
1219
store_1.default.dispatch(completeChapter());
1320
}
1421
return {
@@ -19,8 +26,8 @@ function completePage() {
1926
exports.completePage = completePage;
2027
function completeChapter() {
2128
var chapter = store_1.default.getState().position.chapter;
22-
var chapterLength = store_1.default.getState().progress.chapters.length;
23-
if (chapter >= chapterLength - 1) {
29+
var progress = store_1.default.getState().progress;
30+
if (progress.chapters.every(function (x) { return x.completed; })) {
2431
store_1.default.dispatch(completeTutorial());
2532
}
2633
return {

lib/components/Page/Hints/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var help_1 = require('material-ui/svg-icons/action/help');
77
var styles = {
88
position: 'relative',
99
margin: '-5px 20px',
10+
right: '10px',
1011
width: '360px',
1112
textAlign: 'center',
1213
zIndex: '0',

lib/components/Page/PageToolbar/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var styles = {
1111
right: '0px',
1212
height: '60px',
1313
width: '400px',
14+
margin: '0px',
1415
};
1516
exports.PageToolbar = function (_a) {
1617
var tasks = _a.tasks, taskPosition = _a.taskPosition, children = _a.children;

lib/components/Progress/ProgressChapter/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var descriptionStyles = {
1010
fontSize: '14px'
1111
};
1212
exports.ProgressChapter = function (_a) {
13-
var chapter = _a.chapter, chapterIndex = _a.chapterIndex, position = _a.position;
13+
var progress = _a.progress, chapter = _a.chapter, chapterIndex = _a.chapterIndex, position = _a.position;
1414
var isActive = chapterIndex === position.chapter;
15-
return (React.createElement(List_1.ListItem, {key: chapterIndex, className: isActive ? 'isActive' : null, style: styles, initiallyOpen: chapterIndex === 0, primaryTogglesNestedList: chapterIndex === position.chapter && !chapter.completed, nestedItems: chapter.pages.map(function (page, pageIndex) { return (React.createElement(ProgressPage_1.ProgressPage, {key: pageIndex, pageIndex: pageIndex, page: page, chapterIndex: chapterIndex, position: position})); })}, React.createElement("h3", null, chapterIndex + 1, ". ", chapter.title), React.createElement("span", {style: descriptionStyles}, React.createElement(index_1.Markdown, null, chapter.description))));
15+
return (React.createElement(List_1.ListItem, {key: chapterIndex, className: isActive ? 'isActive' : null, style: styles, initiallyOpen: chapterIndex === 0, primaryTogglesNestedList: chapterIndex === position.chapter && !progress.chapters[chapterIndex].completed, nestedItems: chapter.pages.map(function (page, pageIndex) { return (React.createElement(ProgressPage_1.ProgressPage, {key: pageIndex, pageIndex: pageIndex, page: page, chapterIndex: chapterIndex, position: position, progress: progress})); })}, React.createElement("h3", null, chapterIndex + 1, ". ", chapter.title), React.createElement("span", {style: descriptionStyles}, React.createElement(index_1.Markdown, null, chapter.description))));
1616
};

lib/components/Progress/ProgressPage/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +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;
33-
var earlierChapter = chapterIndex < position.chapter;
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];
3434
var currentChapter = chapterIndex === position.chapter;
3535
var earlierOrCurrentPage = pageIndex <= position.page;
36-
return isActive || earlierChapter ||
36+
return isActive || completed ||
3737
(currentChapter && earlierOrCurrentPage);
3838
};
3939
ProgressPage.prototype.render = function () {
40-
var _a = this.props, page = _a.page, position = _a.position, chapterIndex = _a.chapterIndex, pageIndex = _a.pageIndex, selectPage = _a.selectPage;
40+
var _a = this.props, page = _a.page, position = _a.position, chapterIndex = _a.chapterIndex, pageIndex = _a.pageIndex, progress = _a.progress, selectPage = _a.selectPage;
4141
var isActive = chapterIndex === position.chapter && pageIndex === position.page;
4242
var canActivate = this.canActivate(isActive);
43-
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(page.completed, isActive), onClick: canActivate
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
4445
? selectPage.bind(this, {
4546
chapter: chapterIndex,
4647
page: pageIndex

lib/components/Progress/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ var pageStyle = {
99
margin: '0px',
1010
};
1111
exports.Progress = function (_a) {
12-
var progress = _a.progress, position = _a.position, info = _a.info;
13-
return (React.createElement(Paper_1.default, {style: pageStyle}, React.createElement(List_1.List, null, React.createElement(Subheader_1.default, null, info.title), progress.chapters.map(function (chapter, chapterIndex) { return (React.createElement(ProgressChapter_1.ProgressChapter, {key: chapterIndex, chapter: chapter, chapterIndex: chapterIndex, position: position})); }))));
12+
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})); }))));
1414
};

lib/components/mount.js

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

0 commit comments

Comments
 (0)