Skip to content

Commit 9e774ce

Browse files
committed
update tutorial button
1 parent 9584ca9 commit 9e774ce

File tree

13 files changed

+58
-7
lines changed

13 files changed

+58
-7
lines changed

lib/actions/actionTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ exports.SET_PROJECT = 'SET_PROJECT';
33
exports.VERIFY_SETUP = 'VERIFY_SETUP';
44
exports.SET_GLOBALS = 'SET_GLOBALS';
55
exports.LOAD_TUTORIALS = 'LOAD_TUTORIALS';
6+
exports.UPDATE_TUTORIAL = 'UPDATE_TUTORIAL';
67
exports.SET_ROUTE = 'SET_ROUTE';
78
exports.SET_PAGE = 'SET_PAGE';
89
exports.NEXT_PAGE = 'NEXT_PAGE';

lib/actions/actions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ exports.testResult = task_actions_1.testResult;
5353
exports.setHintPosition = task_actions_1.setHintPosition;
5454
var tutorials_1 = require('./tutorials');
5555
exports.loadTutorials = tutorials_1.loadTutorials;
56+
exports.updateTutorial = tutorials_1.updateTutorial;
5657
var alert_1 = require('./alert');
5758
exports.toggleAlert = alert_1.toggleAlert;
5859
exports.replayAlert = alert_1.replayAlert;

lib/actions/tutorials.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ function loadTutorials() {
44
return { type: Type.LOAD_TUTORIALS };
55
}
66
exports.loadTutorials = loadTutorials;
7+
function updateTutorial(name) {
8+
return { type: Type.UPDATE_TUTORIAL, payload: { name: name } };
9+
}
10+
exports.updateTutorial = updateTutorial;

lib/components/tutorials/tutorials.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var table_row_1 = require('material-ui/lib/table/table-row');
2121
var table_header_1 = require('material-ui/lib/table/table-header');
2222
var table_row_column_1 = require('material-ui/lib/table/table-row-column');
2323
var table_body_1 = require('material-ui/lib/table/table-body');
24+
var file_upload_1 = require('material-ui/lib/svg-icons/file/file-upload');
2425
var react_redux_1 = require('react-redux');
2526
var Action = require('../../actions/actions');
2627
var TutorialList = (function (_super) {
@@ -39,9 +40,11 @@ var TutorialList = (function (_super) {
3940
};
4041
TutorialList.prototype.render = function () {
4142
var _this = this;
42-
var _a = this.props, tutorials = _a.tutorials, loadTutorials = _a.loadTutorials, selectTutorial = _a.selectTutorial, toggleAlert = _a.toggleAlert;
43+
var _a = this.props, tutorials = _a.tutorials, loadTutorials = _a.loadTutorials, selectTutorial = _a.selectTutorial, toggleAlert = _a.toggleAlert, updateTutorial = _a.updateTutorial;
4344
return (React.createElement("div", {className: 'cr-tutorials'}, React.createElement(table_1.default, null, React.createElement(table_header_1.default, {displaySelectAll: false, adjustForCheckbox: false}, React.createElement(table_row_1.default, null, React.createElement(table_header_column_1.default, null, "Tutorial"), React.createElement(table_header_column_1.default, null, "Version"))), React.createElement(table_body_1.default, {displayRowCheckbox: false}, tutorials.map(function (tutorial, index) {
44-
return (React.createElement(table_row_1.default, null, React.createElement(table_row_column_1.default, null, React.createElement(flat_button_1.default, {label: _this.trim(tutorial.name), primary: true, onTouchTap: selectTutorial.bind(_this, tutorial)})), React.createElement(table_row_column_1.default, null, tutorial.version), "/>"));
45+
return (React.createElement(table_row_1.default, null, React.createElement(table_row_column_1.default, null, React.createElement(flat_button_1.default, {label: _this.trim(tutorial.name), primary: true, onTouchTap: selectTutorial.bind(_this, tutorial)})), React.createElement(table_row_column_1.default, null, tutorial.version, " ", tutorial.latest
46+
? React.createElement(file_upload_1.default, {onClick: updateTutorial(tutorial.name)})
47+
: null), "/>"));
4548
}))), React.createElement("br", null), React.createElement(flat_button_1.default, {style: { margin: '0 auto' }, label: 'Check for Tutorials', secondary: true, onTouchTap: loadTutorials})));
4649
};
4750
TutorialList = __decorate([
@@ -56,6 +59,9 @@ var TutorialList = (function (_super) {
5659
},
5760
loadTutorials: function () {
5861
dispatch(Action.loadTutorials());
62+
},
63+
updateTutorial: function (name) {
64+
dispatch(Action.updateTutorial(name));
5965
}
6066
};
6167
}),

lib/reducers/tutorials/tutorials.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"use strict";
22
var Type = require('../../actions/actionTypes');
33
var check_tutorials_1 = require('./check-tutorials');
4+
var update_tutorial_1 = require('./update-tutorial');
45
function tutorialsReducer(tutorials, action) {
56
if (tutorials === void 0) { tutorials = []; }
67
switch (action.type) {
8+
case Type.UPDATE_TUTORIAL:
9+
update_tutorial_1.updateTutorial(action.payload.name);
710
case Type.LOAD_TUTORIALS:
811
var packageJson = check_tutorials_1.loadRootPackageJson();
912
if (!!packageJson) {

lib/reducers/tutorials/update-tutorial.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use strict";
22
var command_line_1 = require('../../services/command-line');
3+
var store_1 = require('../../store/store');
4+
var Action = require('../../actions/actions');
35
function canUpdateTutorial(name, currentVersion) {
46
var isLatest = command_line_1.default('npm', "outdated " + name)
57
.then(function (res) {
@@ -12,3 +14,10 @@ function canUpdateTutorial(name, currentVersion) {
1214
});
1315
}
1416
exports.canUpdateTutorial = canUpdateTutorial;
17+
function updateTutorial(name) {
18+
command_line_1.default('npm', "install --save-dev " + name)
19+
.then(function () {
20+
store_1.store.dispatch(Action.loadTutorials());
21+
});
22+
}
23+
exports.updateTutorial = updateTutorial;

src/actions/actionTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const SET_PROJECT = 'SET_PROJECT';
33
export const VERIFY_SETUP = 'VERIFY_SETUP';
44
export const SET_GLOBALS = 'SET_GLOBALS';
55
export const LOAD_TUTORIALS = 'LOAD_TUTORIALS';
6+
export const UPDATE_TUTORIAL = 'UPDATE_TUTORIAL';
67

78
// Navigation
89
export const SET_ROUTE = 'SET_ROUTE';

src/actions/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export {pageComplete, chapterComplete, projectComplete} from './progress-actions
5151
export {showHint, runTests, testComplete, testResult, setHintPosition} from './task-actions';
5252

5353
/* Tutorials */
54-
export {loadTutorials} from './tutorials';
54+
export {loadTutorials, updateTutorial} from './tutorials';
5555

5656
/* Alert */
5757
export {toggleAlert, replayAlert} from './alert';

src/actions/tutorials.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ import * as Type from './actionTypes';
33
export function loadTutorials(): CR.Action {
44
return { type: Type.LOAD_TUTORIALS };
55
}
6+
7+
export function updateTutorial(name: string): CR.Action {
8+
return { type: Type.UPDATE_TUTORIAL, payload: { name } };
9+
}

src/components/page/toolbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import RaisedButton from 'material-ui/lib/raised-button';
88
import FlatButton from 'material-ui/lib/flat-button';
99
import {save} from '../../atom/editor';
1010
import {toggleDevTools} from '../../atom/actions';
11-
import {store} from '../store/store';
11+
import {store} from '../../store/store';
1212
import Code from 'material-ui/lib/svg-icons/action/code';
1313

1414
const ProgressBar = ({progress}) => <LinearProgress mode='determinate'

src/components/tutorials/tutorials.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import TableRow from 'material-ui/lib/table/table-row';
66
import TableHeader from 'material-ui/lib/table/table-header';
77
import TableRowColumn from 'material-ui/lib/table/table-row-column';
88
import TableBody from 'material-ui/lib/table/table-body';
9+
import FileUpload from 'material-ui/lib/svg-icons/file/file-upload';
910
import {MarkdownText} from '../_components';
1011
import {connect} from 'react-redux';
1112
import * as Action from '../../actions/actions';
@@ -21,12 +22,16 @@ import * as Action from '../../actions/actions';
2122
},
2223
loadTutorials: () => {
2324
dispatch(Action.loadTutorials());
25+
},
26+
updateTutorial: (name: string) => {
27+
dispatch(Action.updateTutorial(name));
2428
}
2529
};
2630
})
2731
class TutorialList extends React.Component<{
2832
tutorials: CR.Tutorial[], loadTutorials?: () => void,
29-
selectTutorial?: (tutorial: CR.Tutorial) => void, toggleAlert?: (item: CR.Alert) => void
33+
selectTutorial?: (tutorial: CR.Tutorial) => void,
34+
toggleAlert?: (item: CR.Alert) => void, updateTutorial?: any
3035
}, {}> {
3136
trim(name: string): string {
3237
if (name.match(/^coderoad-tutorial-/)) {
@@ -38,7 +43,7 @@ class TutorialList extends React.Component<{
3843
return name;
3944
}
4045
render() {
41-
const {tutorials, loadTutorials, selectTutorial, toggleAlert} = this.props;
46+
const {tutorials, loadTutorials, selectTutorial, toggleAlert, updateTutorial} = this.props;
4247
return (
4348
<div className='cr-tutorials'>
4449
<Table>
@@ -58,7 +63,11 @@ class TutorialList extends React.Component<{
5863
<TableRowColumn>
5964
<FlatButton label={this.trim(tutorial.name)} primary={true} onTouchTap={selectTutorial.bind(this, tutorial)} />
6065
</TableRowColumn>
61-
<TableRowColumn>{tutorial.version}</TableRowColumn>
66+
<TableRowColumn>
67+
{tutorial.version} {tutorial.latest
68+
? <FileUpload onClick={updateTutorial(tutorial.name)} />
69+
: null}
70+
</TableRowColumn>
6271
/>
6372
</TableRow>
6473
);

src/reducers/tutorials/tutorials.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import * as Type from '../../actions/actionTypes';
22
import {loadRootPackageJson, searchForTutorials} from './check-tutorials';
3+
import {updateTutorial} from './update-tutorial';
34

45
export default function tutorialsReducer(tutorials = [], action: CR.Action): CR.Tutorial[] {
56
switch (action.type) {
7+
case Type.UPDATE_TUTORIAL:
8+
updateTutorial(action.payload.name);
9+
/* jshint: fall through */
610
case Type.LOAD_TUTORIALS:
711
let packageJson: PackageJson = loadRootPackageJson();
812
if (!!packageJson) {

src/reducers/tutorials/update-tutorial.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import commandLine from '../../services/command-line';
2+
import {store} from '../../store/store';
3+
import * as Action from '../../actions/actions';
24

35
export function canUpdateTutorial(name: string, currentVersion: string): string|void {
46
let isLatest = commandLine('npm', `outdated ${name}`)
@@ -10,3 +12,10 @@ export function canUpdateTutorial(name: string, currentVersion: string): string|
1012
}
1113
});
1214
}
15+
16+
export function updateTutorial(name: string): void {
17+
commandLine('npm', `install --save-dev ${name}`)
18+
.then(() => {
19+
store.dispatch(Action.loadTutorials());
20+
});
21+
}

0 commit comments

Comments
 (0)