Skip to content

Commit 419e3d8

Browse files
committed
progress changing position to page-position
1 parent 2ea2b07 commit 419e3d8

File tree

9 files changed

+21
-26
lines changed

9 files changed

+21
-26
lines changed

lib/actions/page.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function pageNext() {
1313
}
1414
else {
1515
pagePosition = pagePosition + 1;
16-
store_1.default.dispatch(test_1.testsLoad(pagePosition));
16+
setTimeout(function () { return store_1.default.dispatch(test_1.testsLoad(pagePosition)); });
1717
return {
1818
payload: { pagePosition: pagePosition },
1919
type: _types_1.PAGE_SET,
@@ -23,7 +23,7 @@ function pageNext() {
2323
exports.pageNext = pageNext;
2424
function pageSet(pagePosition) {
2525
if (pagePosition === void 0) { pagePosition = 0; }
26-
if (store_1.default.getState().progress.pages[pagePosition]) {
26+
if (pagePosition >= store_1.default.getState().progress.pages.length) {
2727
return {
2828
payload: { route: 'final' },
2929
type: _types_1.ROUTE_SET,

lib/components/Progress/ProgressPage/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ var ProgressPage = (function (_super) {
3131
ProgressPage.prototype.render = function () {
3232
var _a = this.props, page = _a.page, pagePosition = _a.pagePosition, index = _a.index, progress = _a.progress, selectPage = _a.selectPage;
3333
var isCompleted = progress.pages[index] || false;
34-
var canActivate = index >= pagePosition;
35-
return (React.createElement(List_1.ListItem, {key: index, style: Object.assign({}, styles, !canActivate ? { color: colors_1.grey400 } : {}), primaryText: (index + 1) + ". " + page.title, secondaryText: page.description, leftIcon: progressIcon_1.progressIcon(isCompleted, index === pagePosition), onClick: canActivate
34+
var canActivate = index <= pagePosition + 1;
35+
var isCurrentPage = index === pagePosition;
36+
return (React.createElement(List_1.ListItem, {key: index, style: Object.assign({}, styles, !canActivate ? { color: colors_1.grey400 } : {}), primaryText: (index + 1) + ". " + page.title, secondaryText: page.description, leftIcon: progressIcon_1.progressIcon(isCompleted, isCurrentPage), onClick: canActivate
3637
? selectPage.bind(this, index)
3738
: function () { return; }}));
3839
};

lib/components/Progress/progressIcon.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ var colors_1 = require('material-ui/styles/colors');
44
var check_box_1 = require('material-ui/svg-icons/toggle/check-box');
55
var play_circle_filled_1 = require('material-ui/svg-icons/av/play-circle-filled');
66
var check_box_outline_blank_1 = require('material-ui/svg-icons/toggle/check-box-outline-blank');
7-
function progressIcon(completed, current) {
8-
if (completed) {
7+
function progressIcon(isCompleted, current) {
8+
if (isCompleted) {
99
return React.createElement(check_box_1.default, {style: { fill: colors_1.green300 }});
1010
}
1111
else if (current) {

lib/reducers/page-position/index.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ function pagePositionReducer(pagePosition, action) {
66
switch (action.type) {
77
case _types_1.PAGE_POSITION_LOAD:
88
var pages = store_1.default.getState().progress.pages;
9-
pagePosition = pages.indexOf(function (x) { return x; }) + 1;
10-
console.log('expected pagePosition', pagePosition, pages);
11-
if (pagePosition >= pages.length) {
12-
pagePosition = pages.length - 1;
13-
}
14-
return pagePosition;
9+
var firstFail = pages.indexOf(function (x) { return !x; });
10+
return firstFail > 0 ? firstFail : pages.length - 1;
1511
case _types_1.PAGE_SET:
1612
case _types_1.PAGE_POSITION_SET:
1713
return action.payload.pagePosition;

src/actions/page.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function pageNext(): Action {
1414
};
1515
} else {
1616
pagePosition = pagePosition + 1;
17-
store.dispatch(testsLoad(pagePosition));
17+
setTimeout(() => store.dispatch(testsLoad(pagePosition)));
1818
return {
1919
payload: { pagePosition },
2020
type: PAGE_SET,
@@ -23,7 +23,8 @@ export function pageNext(): Action {
2323
}
2424

2525
export function pageSet(pagePosition = 0): Action {
26-
if (store.getState().progress.pages[pagePosition]) {
26+
// beyond the final page
27+
if (pagePosition >= store.getState().progress.pages.length) {
2728
return {
2829
payload: { route: 'final' },
2930
type: ROUTE_SET,

src/components/Progress/ProgressPage/index.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ export class ProgressPage extends React.Component<{
2525
pagePosition: CR.PagePosition, index: number, selectPage?: () => void}, {}> {
2626
render() {
2727
const {page, pagePosition, index, progress, selectPage} = this.props;
28-
const isCompleted = progress.pages[index] || false;
29-
const canActivate = index >= pagePosition;
28+
const isCompleted: boolean = progress.pages[index] || false;
29+
const canActivate: boolean = index <= pagePosition + 1;
30+
const isCurrentPage: boolean = index === pagePosition;
3031
return (
3132
<ListItem
3233
key={index}
3334
style={Object.assign({}, styles, !canActivate ? {color: grey400} : {})}
3435
primaryText={`${index + 1}. ${page.title}`}
3536
secondaryText={page.description}
36-
leftIcon={progressIcon(isCompleted, index === pagePosition)}
37+
leftIcon={progressIcon(isCompleted, isCurrentPage)}
3738
onClick={
3839
canActivate
3940
? selectPage.bind(this, index)

src/components/Progress/progressIcon.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import CheckBox from 'material-ui/svg-icons/toggle/check-box';
44
import PlayCircleFilled from 'material-ui/svg-icons/av/play-circle-filled';
55
import CheckBoxOutlineBlank from 'material-ui/svg-icons/toggle/check-box-outline-blank';
66

7-
export function progressIcon(completed: boolean, current?: boolean) {
8-
if (completed) {
7+
export function progressIcon(isCompleted: boolean, current?: boolean) {
8+
if (isCompleted) {
99
return <CheckBox style={{fill: green300}} />;
1010
} else if (current) {
1111
return <PlayCircleFilled style={{fill: pink500}} />;

src/reducers/editor-actions/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default function editorActionsReducer(
3737
currentTaskPosition = nextTaskPosition;
3838
}
3939
return actions;
40+
4041
default:
4142
return editorActions;
4243
}

src/reducers/page-position/index.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ export default function pagePositionReducer(
99
switch (action.type) {
1010
case PAGE_POSITION_LOAD:
1111
const pages = store.getState().progress.pages;
12-
pagePosition = pages.indexOf(x => x) + 1;
13-
console.log('expected pagePosition', pagePosition, pages);
14-
// all pages complete ? page = -1
15-
if (pagePosition >= pages.length) {
16-
pagePosition = pages.length - 1;
17-
}
18-
return pagePosition;
12+
const firstFail = pages.indexOf(x => !x);
13+
return firstFail > 0 ? firstFail : pages.length - 1;
1914
case PAGE_SET:
2015
case PAGE_POSITION_SET:
2116
return action.payload.pagePosition;

0 commit comments

Comments
 (0)