Skip to content

Commit b11cd33

Browse files
committed
refactor components to use selectors
1 parent 20fbe11 commit b11cd33

File tree

7 files changed

+65
-48
lines changed

7 files changed

+65
-48
lines changed

lib/components/Start/Checks/index.js

+34-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
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 SystemChecks_1 = require('./SystemChecks');
419
var SetupChecks_1 = require('./SetupChecks');
520
var InstallGuide_1 = require('./InstallGuide');
@@ -8,16 +23,25 @@ var styles = {
823
margin: '5px',
924
padding: '10px',
1025
};
11-
var Checks = function (_a) {
12-
var checks = _a.checks;
13-
if (!checks) {
14-
return React.createElement(index_1.ContentCard, {title: 'Error Loading Package.json', content: ''});
26+
var Checks = (function (_super) {
27+
__extends(Checks, _super);
28+
function Checks() {
29+
_super.apply(this, arguments);
1530
}
16-
return (React.createElement("div", {style: styles}, !checks.system.passed
17-
? React.createElement(SystemChecks_1.default, {checks: checks})
18-
: null, !checks.setup.passed
19-
? React.createElement(SetupChecks_1.default, {checks: checks})
20-
: null, React.createElement(InstallGuide_1.default, {checks: checks})));
21-
};
31+
Checks.prototype.render = function () {
32+
var checks = this.props.checks;
33+
if (!checks) {
34+
return React.createElement(index_1.ContentCard, {title: 'Error Loading Package.json'});
35+
}
36+
return (React.createElement("div", {style: styles}, !checks.system.passed ? React.createElement(SystemChecks_1.default, {checks: checks}) : null, !checks.setup.passed ? React.createElement(SetupChecks_1.default, {checks: checks}) : null, React.createElement(InstallGuide_1.default, {checks: checks})));
37+
};
38+
Checks = __decorate([
39+
react_redux_1.connect(function (state) { return ({
40+
checks: state.checks,
41+
}); }),
42+
__metadata('design:paramtypes', [])
43+
], Checks);
44+
return Checks;
45+
}(React.Component));
2246
Object.defineProperty(exports, "__esModule", { value: true });
2347
exports.default = Checks;

lib/components/Start/index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ var Start = (function (_super) {
2929
_super.apply(this, arguments);
3030
}
3131
Start.prototype.render = function () {
32-
var checks = this.props.checks;
33-
return (React.createElement("section", {className: 'cr-start'}, React.createElement("div", {style: headerStyles}, checks.passed
34-
? React.createElement(Welcome_1.default, null)
35-
: React.createElement(Checks_1.default, {checks: checks}))));
32+
var ready = this.props.ready;
33+
return (React.createElement("section", {className: 'cr-start'}, React.createElement("div", {style: headerStyles}, ready ? React.createElement(Welcome_1.default, null) : React.createElement(Checks_1.default, null))));
3634
};
3735
Start = __decorate([
3836
react_redux_1.connect(function (state) { return ({
39-
checks: state.checks,
37+
ready: state.checks.passed,
4038
}); }),
4139
__metadata('design:paramtypes', [])
4240
], Start);

lib/components/common/ContentCard.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var styles = {
77
};
88
var ContentCard = function (_a) {
99
var title = _a.title, content = _a.content;
10-
return (React.createElement(Card_1.Card, {style: styles}, title ? React.createElement(Card_1.CardHeader, {title: title}) : null, React.createElement(Card_1.CardText, null, React.createElement(index_1.Markdown, null, content))));
10+
return (React.createElement(Card_1.Card, {style: styles}, title ? React.createElement(Card_1.CardHeader, {title: title}) : null, React.createElement(Card_1.CardText, null, React.createElement(index_1.Markdown, null, content || ''))));
1111
};
1212
Object.defineProperty(exports, "__esModule", { value: true });
1313
exports.default = ContentCard;

src/components/Page/PageToolbar/ToggleDevTools/index.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ export default class ToggleDevTools extends React.Component<{
1919
return (
2020
<FlatButton
2121
style={styles}
22-
icon={
23-
<Code />
24-
}
22+
icon={<Code />}
2523
onTouchTap={this.props.toggle}
2624
/>
2725
);

src/components/Start/Checks/index.tsx

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import {connect} from 'react-redux';
23
import SystemChecks from './SystemChecks';
34
import SetupChecks from './SetupChecks';
45
import InstallGuide from './InstallGuide';
@@ -9,25 +10,23 @@ const styles = {
910
padding: '10px',
1011
};
1112

12-
const Checks: React.StatelessComponent<{
13-
checks: CR.Checks
14-
}> = ({checks}) => {
15-
if (!checks) {
16-
return <ContentCard
17-
title='Error Loading Package.json'
18-
content=''
19-
/>;
13+
@connect(state => ({
14+
checks: state.checks,
15+
}))
16+
export default class Checks extends React.Component<{
17+
checks?: CR.Checks
18+
}, {}> {
19+
render() {
20+
const {checks} = this.props;
21+
if (!checks) {
22+
return <ContentCard title='Error Loading Package.json' />;
23+
}
24+
return (
25+
<div style={styles}>
26+
{!checks.system.passed ? <SystemChecks checks={checks} /> : null}
27+
{!checks.setup.passed ? <SetupChecks checks={checks} /> : null}
28+
<InstallGuide checks={checks} />
29+
</div>
30+
);
2031
}
21-
return (
22-
<div style={styles}>
23-
{!checks.system.passed
24-
? <SystemChecks checks={checks} />
25-
: null}
26-
{!checks.setup.passed
27-
? <SetupChecks checks={checks} />
28-
: null}
29-
<InstallGuide checks={checks} />
30-
</div>
31-
);
32-
};
33-
export default Checks;
32+
}

src/components/Start/index.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@ const headerStyles = {
1111
};
1212

1313
@connect(state => ({
14-
checks: state.checks,
14+
ready: state.checks.passed,
1515
}))
1616
export default class Start extends React.Component<{
17-
checks?: CR.Checks
17+
ready?: CR.Checks
1818
}, {}> {
1919
render() {
20-
const {checks} = this.props;
20+
const {ready} = this.props;
2121
return (
2222
<section className='cr-start'>
2323
<div style={headerStyles}>
24-
{checks.passed
25-
? <Welcome />
26-
: <Checks checks={checks} />}
24+
{ready ? <Welcome /> : <Checks />}
2725
</div>
2826
</section>
2927
);

src/components/common/ContentCard.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const styles = {
77
};
88

99
const ContentCard: React.StatelessComponent<{
10-
title: string, content: string
10+
title: string, content?: string
1111
}> = ({title, content}) => (
1212
<Card style={styles}>
1313
{title ? <CardHeader title={title} /> : null}
1414
<CardText>
15-
<Markdown>{content}</Markdown>
15+
<Markdown>{content || ''}</Markdown>
1616
</CardText>
1717
</Card>
1818
);

0 commit comments

Comments
 (0)