Skip to content

Commit 20fbe11

Browse files
committed
refactor TaskCheckbox using selectors
1 parent f24a0bd commit 20fbe11

File tree

5 files changed

+65
-25
lines changed

5 files changed

+65
-25
lines changed

lib/components/Page/Task/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ var Task = (function (_super) {
4646
Task.prototype.render = function () {
4747
var _a = this.props, testRun = _a.testRun, task = _a.task, index = _a.index, isCurrentTask = _a.isCurrentTask, isCompletedTask = _a.isCompletedTask;
4848
var backgroundColor = isCompletedTask ? colors_1.lightGreen200 : 'inherit';
49-
return (React.createElement(List_1.ListItem, {key: index, style: Object.assign({}, styles.task, { backgroundColor: backgroundColor })}, taskCheckbox_1.default(isCurrentTask, testRun), React.createElement("span", {style: styles.index}, index + 1, "."), React.createElement("div", {style: styles.description}, React.createElement(index_1.Markdown, null, task.description))));
49+
return (React.createElement(List_1.ListItem, {key: index, style: Object.assign({}, styles.task, { backgroundColor: backgroundColor })}, React.createElement(taskCheckbox_1.default, {index: index}), React.createElement("span", {style: styles.index}, index + 1, "."), React.createElement("div", {style: styles.description}, React.createElement(index_1.Markdown, null, task.description))));
5050
};
5151
Task = __decorate([
5252
react_redux_1.connect(function (state, props) { return ({
5353
testRun: state.testRun,
54-
isCurrentTask: state.taskPosition === props.index,
5554
isCompletedTask: state.taskPosition > props.index,
5655
}); }),
5756
__metadata('design:paramtypes', [])
+40-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,48 @@
11
"use strict";
2+
var __extends = (this && this.__extends) || function (d, b) {
3+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4+
function __() { this.constructor = d; }
5+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6+
};
7+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
8+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11+
return c > 3 && r && Object.defineProperty(target, key, r), r;
12+
};
13+
var __metadata = (this && this.__metadata) || function (k, v) {
14+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
15+
};
216
var React = require('react');
17+
var react_redux_1 = require('react-redux');
318
var colors_1 = require('material-ui/styles/colors');
419
var indeterminate_check_box_1 = require('material-ui/svg-icons/toggle/indeterminate-check-box');
520
var styles = {
6-
position: 'absolute',
7-
top: '15px'
21+
checkbox: {
22+
position: 'absolute',
23+
top: '15px',
24+
},
825
};
9-
function taskCheckbox(isCurrentTask, testRun) {
10-
if (!isCurrentTask || !testRun) {
11-
return null;
26+
var TaskCheckbox = (function (_super) {
27+
__extends(TaskCheckbox, _super);
28+
function TaskCheckbox() {
29+
_super.apply(this, arguments);
1230
}
13-
return (React.createElement("span", {style: styles}, React.createElement(indeterminate_check_box_1.default, {color: colors_1.orange500})));
14-
}
31+
TaskCheckbox.prototype.render = function () {
32+
var _a = this.props, testRun = _a.testRun, isCurrentTask = _a.isCurrentTask;
33+
if (!isCurrentTask || !testRun) {
34+
return null;
35+
}
36+
return React.createElement(indeterminate_check_box_1.default, {color: colors_1.orange500, style: styles.checkbox});
37+
};
38+
TaskCheckbox = __decorate([
39+
react_redux_1.connect(function (state, props) { return ({
40+
testRun: state.testRun,
41+
isCurrentTask: state.taskPosition === props.index,
42+
}); }),
43+
__metadata('design:paramtypes', [])
44+
], TaskCheckbox);
45+
return TaskCheckbox;
46+
}(React.Component));
1547
Object.defineProperty(exports, "__esModule", { value: true });
16-
exports.default = taskCheckbox;
17-
;
48+
exports.default = TaskCheckbox;

src/components/Page/Task/index.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import {connect} from 'react-redux';
33
import {Markdown} from '../../index';
4-
import taskCheckbox from './taskCheckbox';
4+
import TaskCheckbox from './taskCheckbox';
55
import {ListItem} from 'material-ui/List';
66
import {lightGreen200, orange200} from 'material-ui/styles/colors';
77

@@ -27,7 +27,6 @@ const styles = {
2727

2828
@connect((state, props) => ({
2929
testRun: state.testRun,
30-
isCurrentTask: state.taskPosition === props.index,
3130
isCompletedTask: state.taskPosition > props.index,
3231
}))
3332
export default class Task extends React.Component<{
@@ -42,7 +41,7 @@ export default class Task extends React.Component<{
4241
key={index}
4342
style={Object.assign({}, styles.task, {backgroundColor})}
4443
>
45-
{taskCheckbox(isCurrentTask, testRun)}
44+
<TaskCheckbox index={index} />
4645
<span style={styles.index}>{index + 1}.</span>
4746
<div style={styles.description}>
4847
<Markdown >{task.description}</Markdown>
+21-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
import * as React from 'react';
2+
import {connect} from 'react-redux';
23
import {green500, orange500} from 'material-ui/styles/colors';
34
import CheckBox from 'material-ui/svg-icons/toggle/check-box';
45
import CheckBoxOutlineBlank from 'material-ui/svg-icons/toggle/check-box-outline-blank';
56
import IndeterminateCheckBox from 'material-ui/svg-icons/toggle/indeterminate-check-box';
67

78
const styles = {
8-
position: 'absolute',
9-
top: '15px'
9+
checkbox: {
10+
position: 'absolute',
11+
top: '15px',
12+
},
1013
};
1114

12-
export default function taskCheckbox(isCurrentTask: boolean, testRun: boolean) {
13-
if (!isCurrentTask || !testRun) { return null; }
14-
return (
15-
<span style={styles}>
16-
<IndeterminateCheckBox color={orange500} />
17-
</span>
18-
);
19-
};
15+
@connect((state, props) => ({
16+
testRun: state.testRun,
17+
isCurrentTask: state.taskPosition === props.index,
18+
}))
19+
export default class TaskCheckbox extends React.Component<{
20+
testRun?: boolean, isCurrentTask?: boolean, index: number
21+
}, {}> {
22+
render() {
23+
const {testRun, isCurrentTask} = this.props;
24+
if (!isCurrentTask || !testRun) { return null; }
25+
return <IndeterminateCheckBox
26+
color={orange500}
27+
style={styles.checkbox}
28+
/>;
29+
}
30+
}

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"src/components/Page/PageToolbar/ToggleDevTools/index.tsx",
110110
"src/components/Page/ProgressBar/index.tsx",
111111
"src/components/Page/Task/index.tsx",
112-
"src/components/Page/Task/taskCheckbox.tsx",
112+
"src/components/Page/Task/TaskCheckbox.tsx",
113113
"src/components/Page/Tasks/index.tsx",
114114
"src/components/Page/TasksComplete/index.tsx",
115115
"src/components/Progress/index.tsx",

0 commit comments

Comments
 (0)