Skip to content

Commit 3b8ac42

Browse files
committed
progress icon fixes
1 parent da9fb15 commit 3b8ac42

File tree

7 files changed

+36
-28
lines changed

7 files changed

+36
-28
lines changed

lib/components/Progress/ProgressPage/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ var ProgressPage = (function (_super) {
3030
}
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;
33-
var isCompleted = progress.pages[index] || false;
3433
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
34+
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(progress.pages, pagePosition, index), onClick: canActivate
3735
? selectPage.bind(this, index)
3836
: function () { return; }}));
3937
};

lib/components/Progress/progressIcon.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ 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(isCompleted, current) {
8-
if (isCompleted) {
9-
return React.createElement(check_box_1.default, {style: { fill: colors_1.green300 }});
10-
}
11-
else if (current) {
12-
return React.createElement(play_circle_filled_1.default, {style: { fill: colors_1.pink500 }});
13-
}
14-
else {
15-
return React.createElement(check_box_outline_blank_1.default, null);
7+
function progressIcon(pages, index, pagePosition) {
8+
console.log(index, pagePosition);
9+
switch (true) {
10+
case index === pagePosition:
11+
return React.createElement(play_circle_filled_1.default, {style: { fill: colors_1.pink500 }});
12+
case pages[pagePosition]:
13+
return React.createElement(check_box_1.default, {style: { fill: colors_1.green300 }});
14+
default:
15+
return React.createElement(check_box_outline_blank_1.default, null);
1616
}
1717
}
1818
exports.progressIcon = progressIcon;
19-
;

lib/reducers/page-position/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function pagePositionReducer(pagePosition, action) {
77
case _types_1.PAGE_POSITION_LOAD:
88
var pages = store_1.default.getState().progress.pages;
99
var firstFail = pages.indexOf(function (x) { return !x; });
10-
return firstFail > 0 ? firstFail : pages.length - 1;
10+
return firstFail >= 0 ? firstFail : pages.length - 1;
1111
case _types_1.PAGE_SET:
1212
case _types_1.PAGE_POSITION_SET:
1313
return action.payload.pagePosition;

src/components/Progress/ProgressPage/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@ export class ProgressPage extends React.Component<{
2424
pagePosition: CR.PagePosition, index: number, selectPage?: () => void}, {}> {
2525
render() {
2626
const {page, pagePosition, index, progress, selectPage} = this.props;
27-
const isCompleted: boolean = progress.pages[index] || false;
2827
const canActivate: boolean = index <= pagePosition + 1;
29-
const isCurrentPage: boolean = index === pagePosition;
3028
return (
3129
<ListItem
3230
key={index}
33-
style={Object.assign({}, styles, !canActivate ? {color: grey400} : {})}
31+
style={
32+
Object.assign(
33+
{},
34+
styles,
35+
canActivate ? {} : {color: grey400}
36+
)
37+
}
3438
primaryText={`${index + 1}. ${page.title}`}
3539
secondaryText={page.description}
36-
leftIcon={progressIcon(isCompleted, isCurrentPage)}
40+
leftIcon={progressIcon(progress.pages, pagePosition, index)}
3741
onClick={
3842
canActivate
3943
? selectPage.bind(this, index)

src/components/Progress/progressIcon.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ 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(isCompleted: boolean, current?: boolean) {
8-
if (isCompleted) {
9-
return <CheckBox style={{fill: green300}} />;
10-
} else if (current) {
11-
return <PlayCircleFilled style={{fill: pink500}} />;
12-
} else {
13-
return <CheckBoxOutlineBlank />;
7+
export function progressIcon(
8+
pages: boolean[], index: number, pagePosition: number
9+
) {
10+
console.log(index, pagePosition);
11+
switch (true) {
12+
// current
13+
case index === pagePosition:
14+
return <PlayCircleFilled style={{fill: pink500}} />;
15+
// completed
16+
case pages[pagePosition]:
17+
return <CheckBox style={{fill: green300}} />;
18+
// other
19+
default:
20+
return <CheckBoxOutlineBlank />;
1421
}
15-
};
22+
}

src/reducers/page-position/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function pagePositionReducer(
1111
case PAGE_POSITION_LOAD:
1212
const pages = store.getState().progress.pages;
1313
const firstFail = pages.indexOf(x => !x);
14-
return firstFail > 0 ? firstFail : pages.length - 1;
14+
return firstFail < 0 ? pages.length - 1 : firstFail;
1515

1616
case PAGE_SET:
1717
case PAGE_POSITION_SET:

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"src/components/Page/Tasks/index.tsx",
145145
"src/components/Page/TasksComplete/index.tsx",
146146
"src/components/Progress/index.tsx",
147-
"src/components/Progress/progressIcon.tsx",
147+
"src/components/Progress/ProgressIcon.tsx",
148148
"src/components/Progress/ProgressPage/index.tsx",
149149
"src/components/render.tsx",
150150
"src/components/Routes/index.tsx",

0 commit comments

Comments
 (0)