Skip to content

Commit cab4125

Browse files
committed
create task object function
1 parent 23665bf commit cab4125

File tree

7 files changed

+53
-30
lines changed

7 files changed

+53
-30
lines changed

Diff for: lib/components/Page/TaskActions/index.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var React = require('react');
88
var Stepper_1 = require('material-ui/Stepper');
99
var index_1 = require('../../index');
1010
var AddButton_1 = require('../AddButton');
11+
var task_object_1 = require('./task-object');
1112
var TaskActions = (function (_super) {
1213
__extends(TaskActions, _super);
1314
function TaskActions(props) {
@@ -20,16 +21,7 @@ var TaskActions = (function (_super) {
2021
var _this = this;
2122
var actions = this.props.actions;
2223
var stepIndex = this.state.stepIndex;
23-
var actionList = actions.map(function (a) {
24-
var obj = {
25-
action: a.substring(0, a.indexOf('(')),
26-
content: a.substring(a.indexOf('(') + 2, a.length - 2)
27-
};
28-
if (obj.action === 'open') {
29-
obj.singleLine = true;
30-
}
31-
return obj;
32-
});
24+
var actionList = actions.map(function (a) { return task_object_1.default(a); });
3325
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 ? ''
3426
: React.createElement(index_1.Markdown, null, '```js\n' + a.content + '\n```')))); }), React.createElement(AddButton_1.default, null)));
3527
};

Diff for: lib/components/Page/TaskActions/task-object.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
function getTaskObject(a) {
3+
var obj = {
4+
action: a.substring(0, a.indexOf('(')),
5+
content: a.substring(a.indexOf('(') + 2, a.length - 2)
6+
};
7+
if (obj.action === 'open') {
8+
obj.singleLine = true;
9+
}
10+
var cursor = /::>/g;
11+
if (!!obj.content.match(cursor)) {
12+
obj.content = obj.content.replace(cursor, '→');
13+
}
14+
return obj;
15+
}
16+
Object.defineProperty(exports, "__esModule", { value: true });
17+
exports.default = getTaskObject;

Diff for: lib/modules/editor-paths/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ function twoDigitify(n) {
66
return n > 9 ? '' + n : '0' + n;
77
}
88
function editorOpenPage(index) {
9-
var filePath = path_1.join('tutorial', twoDigitify(index + 1), 'index.md');
10-
return function (dispatch) { return actions_1.editorOpen(filePath); };
9+
return function (dispatch) {
10+
var filePath = path_1.join('tutorial', twoDigitify(index + 1), 'index.md');
11+
dispatch(actions_1.editorOpen(filePath));
12+
};
1113
}
1214
exports.editorOpenPage = editorOpenPage;
1315
function editorOpenTest(pageIndex, testIndex) {
1416
return function (dispatch, getState) {
1517
var suffix = config_options_1.default[getState().packageJson.config].suffix;
1618
var filePath = path_1.join('tutorial', twoDigitify(pageIndex), twoDigitify(testIndex) + '.' + suffix);
17-
actions_1.editorOpen(filePath);
19+
dispatch(actions_1.editorOpen(filePath));
1820
};
1921
}
2022
exports.editorOpenTest = editorOpenTest;

Diff for: src/components/Page/TaskActions/index.tsx

+2-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from 'material-ui/Stepper';
55
import {Markdown} from '../../index';
66
import AddButton from '../AddButton';
7+
import getTaskObject from './task-object';
78

89
export default class TaskActions extends React.Component<{
910
actions: string[]
@@ -20,16 +21,7 @@ export default class TaskActions extends React.Component<{
2021
const {actions} = this.props;
2122
const {stepIndex} = this.state;
2223
// TODO: sort actions with higher accuracy
23-
const actionList = actions.map(a => {
24-
const obj: Builder.ActionObject = {
25-
action: a.substring(0, a.indexOf('(')),
26-
content: a.substring(a.indexOf('(') + 2, a.length - 2)
27-
};
28-
if (obj.action === 'open') {
29-
obj.singleLine = true;
30-
}
31-
return obj;
32-
});
24+
const actionList: Builder.ActionObject[] = actions.map(a => getTaskObject(a));
3325
return (
3426
<Stepper
3527
activeStep={stepIndex}

Diff for: src/components/Page/TaskActions/task-object.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default function getTaskObject(a: string): Builder.ActionObject {
2+
const obj: Builder.ActionObject = {
3+
action: a.substring(0, a.indexOf('(')),
4+
content: a.substring(a.indexOf('(') + 2, a.length - 2)
5+
};
6+
7+
if (obj.action === 'open') {
8+
obj.singleLine = true;
9+
}
10+
11+
const cursor = /::>/g;
12+
if (!!obj.content.match(cursor)) {
13+
obj.content = obj.content.replace(cursor, '→');
14+
}
15+
16+
return obj;
17+
}

Diff for: src/modules/editor-paths/index.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ function twoDigitify(n: number): string {
77
}
88

99
export function editorOpenPage(index: number) {
10-
const filePath = join(
11-
'tutorial',
12-
twoDigitify(index + 1),
13-
'index.md'
14-
);
15-
return dispatch => editorOpen(filePath);
10+
return dispatch => {
11+
const filePath = join(
12+
'tutorial',
13+
twoDigitify(index + 1),
14+
'index.md'
15+
);
16+
dispatch(editorOpen(filePath));
17+
};
1618
}
1719

1820
export function editorOpenTest(pageIndex: number, testIndex: number) {
@@ -24,6 +26,6 @@ export function editorOpenTest(pageIndex: number, testIndex: number) {
2426
twoDigitify(pageIndex),
2527
twoDigitify(testIndex) + '.' + suffix
2628
);
27-
editorOpen(filePath);
29+
dispatch(editorOpen(filePath));
2830
};
2931
}

Diff for: tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"files": [
2424
"src/actions.ts",
2525
"src/components/index.ts",
26+
"src/components/Page/TaskActions/task-object.ts",
2627
"src/components/remove-later.ts",
2728
"src/components/Root.ts",
2829
"src/components/styles/theme.ts",

0 commit comments

Comments
 (0)