Skip to content

Commit eb7dc89

Browse files
committed
setup add actions, tasks, hints events
1 parent f1705b2 commit eb7dc89

File tree

10 files changed

+180
-53
lines changed

10 files changed

+180
-53
lines changed

lib/components/Page/Hints/index.js

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,59 @@
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+
};
16+
var _this = this;
217
var React = require('react');
18+
var react_redux_1 = require('react-redux');
319
var List_1 = require('material-ui/List');
4-
var AddButton_1 = require('../AddButton');
20+
var actions_1 = require('../../../actions');
21+
var TextField_1 = require('material-ui/TextField');
522
var styles = {
6-
add: {
7-
textAlign: 'center',
23+
text: {
24+
margin: '10px',
825
},
926
};
10-
var Hints = function (_a) {
11-
var hints = _a.hints;
12-
return (React.createElement(List_1.List, null, !hints || !hints.length
13-
? []
14-
: hints.map(function (hint, index) { return (React.createElement(List_1.ListItem, {secondaryText: React.createElement("p", null, index + 1, ". ", hint)})); }), React.createElement(AddButton_1.default, null)));
15-
};
27+
var Hints = (function (_super) {
28+
__extends(Hints, _super);
29+
function Hints(props) {
30+
_super.call(this, props);
31+
this.state = {
32+
text: '',
33+
};
34+
}
35+
Hints.prototype.handleChange = function (event) {
36+
console.log(event);
37+
this.setState({
38+
text: event.target.value,
39+
});
40+
};
41+
Hints.prototype.render = function () {
42+
var hints = this.props.hints;
43+
var text = this.state.text;
44+
return (React.createElement(List_1.List, null, !hints || !hints.length
45+
? []
46+
: hints.map(function (hint, index) { return (React.createElement(List_1.ListItem, {secondaryText: React.createElement("p", null, index + 1, ". ", hint)})); }), React.createElement(TextField_1.default, {style: styles.text, hintText: 'Hint text', multiLine: true, value: text, onChange: this.handleChange.bind(this)})));
47+
};
48+
Hints = __decorate([
49+
react_redux_1.connect(null, function (dispatch) {
50+
return {
51+
addHint: function () { return dispatch(actions_1.tutorialHintAdd(_this.props.taskPosition, _this.state.text)); }
52+
};
53+
}),
54+
__metadata('design:paramtypes', [Object])
55+
], Hints);
56+
return Hints;
57+
}(React.Component));
1658
Object.defineProperty(exports, "__esModule", { value: true });
1759
exports.default = Hints;

lib/components/Page/TaskActions/index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ var __extends = (this && this.__extends) || function (d, b) {
44
function __() { this.constructor = d; }
55
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
66
};
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+
};
16+
var _this = this;
717
var React = require('react');
18+
var react_redux_1 = require('react-redux');
819
var Stepper_1 = require('material-ui/Stepper');
920
var index_1 = require('../../index');
1021
var AddButton_1 = require('../AddButton');
1122
var task_object_1 = require('./task-object');
23+
var actions_1 = require('../../../actions');
1224
var TaskActions = (function (_super) {
1325
__extends(TaskActions, _super);
1426
function TaskActions(props) {
@@ -19,12 +31,20 @@ var TaskActions = (function (_super) {
1931
}
2032
TaskActions.prototype.render = function () {
2133
var _this = this;
22-
var actions = this.props.actions;
34+
var _a = this.props, actions = _a.actions, addAction = _a.addAction;
2335
var stepIndex = this.state.stepIndex;
2436
var actionList = actions.map(function (a) { return task_object_1.default(a); });
2537
return (React.createElement(Stepper_1.Stepper, {activeStep: stepIndex, linear: false, orientation: 'vertical'}, actionList.map(function (a, index) { return (React.createElement(Stepper_1.Step, null, React.createElement(Stepper_1.StepButton, {onClick: function () { return _this.setState({ stepIndex: index }); }}, a.action + (a.singleLine ? ' ' + a.content : '')), React.createElement(Stepper_1.StepContent, null, a.singleLine ? ''
26-
: React.createElement(index_1.Markdown, null, '```js\n' + a.content + '\n```')))); }), React.createElement(AddButton_1.default, null)));
38+
: React.createElement(index_1.Markdown, null, '```js\n' + a.content + '\n```')))); }), React.createElement(AddButton_1.default, {callback: addAction.bind(this, 'test(`test`)')})));
2739
};
40+
TaskActions = __decorate([
41+
react_redux_1.connect(null, function (dispatch) {
42+
return {
43+
addAction: function (actionString) { return dispatch(actions_1.tutorialActionAdd(_this.props.taskPosition, actionString)); }
44+
};
45+
}),
46+
__metadata('design:paramtypes', [Object])
47+
], TaskActions);
2848
return TaskActions;
2949
}(React.Component));
3050
Object.defineProperty(exports, "__esModule", { value: true });

lib/components/Page/Tasks/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var styles = {
3333
};
3434
var Tasks = function (_a) {
3535
var tasks = _a.tasks, page = _a.page, config = _a.config;
36-
return (React.createElement("div", null, tasks.map(function (task, index) { return (React.createElement(Card_1.Card, {style: styles.card, initiallyExpanded: index === 0}, React.createElement(Card_1.CardHeader, {actAsExpander: true, showExpandableButton: true}, React.createElement("span", {style: styles.title}, "Task ", index + 1), React.createElement(Tests_1.default, {style: styles.test, tests: task.tests, config: config})), React.createElement(Card_1.CardText, {expandable: true, style: styles.cardContent}, React.createElement(Tabs_1.Tabs, {tabItemContainerStyle: styles.tabBar}, React.createElement(Tabs_1.Tab, {label: 'Description'}, React.createElement(Task_1.default, {key: index.toString(), index: index, task: task})), React.createElement(Tabs_1.Tab, {label: 'Actions'}, React.createElement(TaskActions_1.default, {actions: task.actions})), React.createElement(Tabs_1.Tab, {label: 'Hints'}, React.createElement(Hints_1.default, {hints: task.hints})))))); }), React.createElement(AddButton_1.default, null), React.createElement(TasksComplete_1.default, {page: page})));
36+
return (React.createElement("div", null, tasks.map(function (task, index) { return (React.createElement(Card_1.Card, {style: styles.card, initiallyExpanded: index === 0}, React.createElement(Card_1.CardHeader, {actAsExpander: true, showExpandableButton: true}, React.createElement("span", {style: styles.title}, "Task ", index + 1), React.createElement(Tests_1.default, {style: styles.test, tests: task.tests, config: config})), React.createElement(Card_1.CardText, {expandable: true, style: styles.cardContent}, React.createElement(Tabs_1.Tabs, {tabItemContainerStyle: styles.tabBar}, React.createElement(Tabs_1.Tab, {label: 'Description'}, React.createElement(Task_1.default, {key: index.toString(), index: index, task: task})), React.createElement(Tabs_1.Tab, {label: 'Actions'}, React.createElement(TaskActions_1.default, {actions: task.actions, taskPosition: index})), React.createElement(Tabs_1.Tab, {label: 'Hints'}, React.createElement(Hints_1.default, {hints: task.hints, taskPosition: index})))))); }), React.createElement(AddButton_1.default, null), React.createElement(TasksComplete_1.default, {page: page})));
3737
};
3838
Object.defineProperty(exports, "__esModule", { value: true });
3939
exports.default = Tasks;

lib/modules/tutorial/actions.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,24 @@ function tutorialPageAdd() {
2727
return { type: types_1.TUTORIAL_PAGE_ADD };
2828
}
2929
exports.tutorialPageAdd = tutorialPageAdd;
30-
function tutorialTaskAdd(pagePosition, taskPosition) {
31-
return { type: types_1.TUTORIAL_TASK_ADD, payload: { pagePosition: pagePosition, taskPosition: taskPosition } };
30+
function tutorialTaskAdd(taskPosition) {
31+
return function (dispatch, getState) {
32+
var pagePosition = getState().pagePosition;
33+
dispatch({ type: types_1.TUTORIAL_TASK_ADD, payload: { pagePosition: pagePosition, taskPosition: taskPosition } });
34+
};
3235
}
3336
exports.tutorialTaskAdd = tutorialTaskAdd;
34-
function tutorialActionAdd(pagePosition, taskPosition, tutorialAction) {
35-
return { type: types_1.TUTORIAL_ACTION_ADD, payload: { pagePosition: pagePosition, taskPosition: taskPosition, tutorialAction: tutorialAction } };
37+
function tutorialActionAdd(taskPosition, tutorialAction) {
38+
return function (dispatch, getState) {
39+
var pagePosition = getState().pagePosition;
40+
dispatch({ type: types_1.TUTORIAL_ACTION_ADD, payload: { pagePosition: pagePosition, taskPosition: taskPosition, tutorialAction: tutorialAction } });
41+
};
3642
}
3743
exports.tutorialActionAdd = tutorialActionAdd;
38-
function tutorialHintAdd(pagePosition, taskPosition) {
39-
return { type: types_1.TUTORIAL_HINT_ADD, payload: { pagePosition: pagePosition, taskPosition: taskPosition } };
44+
function tutorialHintAdd(taskPosition, hint) {
45+
return function (dispatch, getState) {
46+
var pagePosition = getState().pagePosition;
47+
dispatch({ type: types_1.TUTORIAL_HINT_ADD, payload: { pagePosition: pagePosition, taskPosition: taskPosition, hint: hint } });
48+
};
4049
}
4150
exports.tutorialHintAdd = tutorialHintAdd;

lib/modules/tutorial/reducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function tutorial(t, action) {
4545
var tut = taskUpdate_1.default(t, pagePosition, taskPosition, 'actions', tutorialAction);
4646
return tut;
4747
case types_1.TUTORIAL_HINT_ADD:
48-
var _c = action.payload, pagePosition = _c.pagePosition, taskPosition = _c.taskPosition;
49-
var tut = taskUpdate_1.default(t, pagePosition, taskPosition, 'hints', '');
48+
var _c = action.payload, pagePosition = _c.pagePosition, taskPosition = _c.taskPosition, hint = _c.hint;
49+
var tut = taskUpdate_1.default(t, pagePosition, taskPosition, 'hints', hint);
5050
return tut;
5151
default:
5252
return t;
Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,61 @@
11
import * as React from 'react';
2+
import {connect} from 'react-redux';
23
import {List, ListItem} from 'material-ui/List';
34
import FontIcon from 'material-ui/FontIcon';
45
import AddButton from '../AddButton';
6+
import {tutorialHintAdd} from '../../../actions';
7+
import TextField from 'material-ui/TextField';
58

69
const styles = {
7-
add: {
8-
textAlign: 'center',
10+
text: {
11+
margin: '10px',
912
},
1013
};
1114

12-
const Hints: React.StatelessComponent<{
13-
hints: string[]
14-
}> = ({hints}) => (
15-
<List>
16-
{!hints || !hints.length
17-
? []
18-
: hints.map((hint, index) => (
19-
<ListItem secondaryText={
20-
<p>{index + 1}. {hint}</p>
21-
} />
22-
))
23-
}
24-
<AddButton />
25-
</List>
26-
);
27-
export default Hints;
15+
@connect(null, dispatch => {
16+
return {
17+
addHint: () => dispatch(tutorialHintAdd(this.props.taskPosition, this.state.text))
18+
};
19+
})
20+
export default class Hints extends React.Component<{
21+
hints: string[], taskPosition: number, addHint?: any
22+
}, {
23+
text: string;
24+
}> {
25+
constructor(props) {
26+
super(props);
27+
this.state = {
28+
text: '',
29+
};
30+
}
31+
handleChange(event) {
32+
console.log(event);
33+
this.setState({
34+
text: event.target.value,
35+
});
36+
}
37+
render() {
38+
const {hints} = this.props;
39+
const {text} = this.state;
40+
return (
41+
<List>
42+
{!hints || !hints.length
43+
? []
44+
: hints.map((hint, index) => (
45+
<ListItem secondaryText={
46+
<p>{index + 1}. {hint}</p>
47+
} />
48+
))
49+
}
50+
<TextField
51+
style={styles.text}
52+
hintText='Hint text'
53+
multiLine={true}
54+
value={text}
55+
onChange={this.handleChange.bind(this)}
56+
/>
57+
58+
</List>
59+
);
60+
}
61+
}

src/components/Page/TaskActions/index.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import * as React from 'react';
2+
import {connect} from 'react-redux';
23
import {
34
Step, Stepper, StepButton, StepContent, StepLabel
45
} from 'material-ui/Stepper';
56
import {Markdown} from '../../index';
67
import AddButton from '../AddButton';
78
import getTaskObject from './task-object';
9+
import {tutorialActionAdd} from '../../../actions';
810

11+
@connect(null, dispatch => {
12+
return {
13+
addAction: (actionString: string) => dispatch(tutorialActionAdd(this.props.taskPosition, actionString))
14+
};
15+
})
916
export default class TaskActions extends React.Component<{
10-
actions: string[]
17+
actions: string[], taskPosition: number, addAction?: any
1118
}, {
1219
stepIndex: number
1320
}> {
@@ -18,7 +25,7 @@ export default class TaskActions extends React.Component<{
1825
};
1926
}
2027
render() {
21-
const {actions} = this.props;
28+
const {actions, addAction} = this.props;
2229
const {stepIndex} = this.state;
2330
// TODO: sort actions with higher accuracy
2431
const actionList: Builder.ActionObject[] = actions.map(a => getTaskObject(a));
@@ -40,7 +47,7 @@ export default class TaskActions extends React.Component<{
4047
</StepContent>
4148
</Step>
4249
))}
43-
<AddButton />
50+
<AddButton callback={addAction.bind(this, 'test(`test`)')}/>
4451
</Stepper>
4552
);
4653
}

src/components/Page/Tasks/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const Tasks: React.StatelessComponent<{
4444
<Card
4545
style={styles.card}
4646
initiallyExpanded={index === 0}
47-
>
47+
>
4848
<CardHeader
4949
actAsExpander={true}
5050
showExpandableButton={true}
@@ -68,11 +68,17 @@ const Tasks: React.StatelessComponent<{
6868
</Tab>
6969

7070
<Tab label='Actions'>
71-
<TaskActions actions={task.actions}/>
71+
<TaskActions
72+
actions={task.actions}
73+
taskPosition={index}
74+
/>
7275
</Tab>
7376

7477
<Tab label='Hints'>
75-
<Hints hints={task.hints} />
78+
<Hints
79+
hints={task.hints}
80+
taskPosition={index}
81+
/>
7682
</Tab>
7783

7884
</Tabs>

src/modules/tutorial/actions.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,23 @@ export function tutorialPageAdd() {
3030
return { type: TUTORIAL_PAGE_ADD };
3131
}
3232

33-
export function tutorialTaskAdd(pagePosition: number, taskPosition: number) {
34-
return { type: TUTORIAL_TASK_ADD, payload: { pagePosition, taskPosition } };
33+
export function tutorialTaskAdd(taskPosition: number) {
34+
return (dispatch, getState) => {
35+
const {pagePosition} = getState();
36+
dispatch({ type: TUTORIAL_TASK_ADD, payload: { pagePosition, taskPosition } });
37+
};
3538
}
3639

37-
export function tutorialActionAdd(pagePosition: number, taskPosition: number, tutorialAction: Object) {
38-
return { type: TUTORIAL_ACTION_ADD, payload: { pagePosition, taskPosition, tutorialAction } };
40+
export function tutorialActionAdd(taskPosition: number, tutorialAction: Object) {
41+
return (dispatch, getState) => {
42+
const {pagePosition} = getState();
43+
dispatch({ type: TUTORIAL_ACTION_ADD, payload: { pagePosition, taskPosition, tutorialAction } });
44+
};
3945
}
4046

41-
export function tutorialHintAdd(pagePosition: number, taskPosition: number) {
42-
return { type: TUTORIAL_HINT_ADD, payload: { pagePosition, taskPosition } };
47+
export function tutorialHintAdd(taskPosition: number, hint: string) {
48+
return (dispatch, getState) => {
49+
const {pagePosition} = getState();
50+
dispatch({ type: TUTORIAL_HINT_ADD, payload: { pagePosition, taskPosition, hint }});
51+
};
4352
}

src/modules/tutorial/reducer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default function tutorial(t = _tutorial, action: Action): CR.Tutorial {
5454
// add task
5555
const tasks = t.pages[pagePosition].tasks;
5656
tasks.push(taskGet(pagePosition, tasks.length));
57-
// TODO: remove mutation, use merge
57+
// TODO: remove mutation, use merge`
5858
// update page tasks
5959
const updatedPage = Object.assign({}, t.pages[pagePosition], {tasks});
6060
t.pages[pagePosition] = updatedPage;
@@ -67,8 +67,8 @@ export default function tutorial(t = _tutorial, action: Action): CR.Tutorial {
6767
return tut;
6868

6969
case TUTORIAL_HINT_ADD:
70-
const {pagePosition, taskPosition} = action.payload;
71-
const tut = taskUpdate(t, pagePosition, taskPosition, 'hints', '');
70+
const {pagePosition, taskPosition, hint} = action.payload;
71+
const tut = taskUpdate(t, pagePosition, taskPosition, 'hints', hint);
7272
return tut;
7373

7474

0 commit comments

Comments
 (0)