|
1 | 1 | "use strict";
|
2 | 2 | var _types_1 = require('./_types');
|
| 3 | +var index_1 = require('./index'); |
3 | 4 | var store_1 = require('../store');
|
4 |
| -var tutorial_package_1 = require('../services/tutorial-package'); |
| 5 | +var _position = { |
| 6 | + chapter: 0, |
| 7 | + page: 0, |
| 8 | +}; |
5 | 9 | function pageNext() {
|
6 |
| - var position = store_1.store.getState().position; |
7 |
| - var nextPosition = tutorial_package_1.default.getNextPosition(position); |
8 |
| - return pageSet(nextPosition); |
| 10 | + var position = null; |
| 11 | + var _a = store_1.store.getState().position, page = _a.page, chapter = _a.chapter; |
| 12 | + var chapters = store_1.store.getState().tutorial.chapters; |
| 13 | + if (page < chapters[chapter].pages.length - 1) { |
| 14 | + position = { |
| 15 | + chapter: chapter, |
| 16 | + page: page + 1, |
| 17 | + }; |
| 18 | + } |
| 19 | + else if (chapter < chapters.length - 1) { |
| 20 | + store_1.store.dispatch(index_1.completePage()); |
| 21 | + position = { |
| 22 | + chapter: chapter + 1, |
| 23 | + page: 0, |
| 24 | + }; |
| 25 | + } |
| 26 | + else { |
| 27 | + store_1.store.dispatch(index_1.completeTutorial()); |
| 28 | + position = { |
| 29 | + chapter: chapter, |
| 30 | + page: page |
| 31 | + }; |
| 32 | + } |
| 33 | + return { type: _types_1.PAGE_SET, payload: { position: position } }; |
9 | 34 | }
|
10 | 35 | exports.pageNext = pageNext;
|
11 |
| -function pageSet(selectedPosition) { |
12 |
| - if (selectedPosition === void 0) { selectedPosition = { chapter: 0, page: 0 }; } |
13 |
| - if (selectedPosition.completed) { |
14 |
| - return { type: _types_1.ROUTE_SET, payload: { route: 'final' } }; |
| 36 | +function pageSet(position) { |
| 37 | + if (position === void 0) { position = _position; } |
| 38 | + if (position.completed) { |
| 39 | + return { |
| 40 | + payload: { route: 'final' }, |
| 41 | + type: _types_1.ROUTE_SET, |
| 42 | + }; |
15 | 43 | }
|
16 |
| - var page = tutorial_package_1.default.getPage(selectedPosition); |
17 |
| - var tasks = tutorial_package_1.default.getTasks(selectedPosition); |
18 |
| - var taskTests = [].concat.apply([], tasks.map(function (task) { return task.tests || []; })); |
19 |
| - var actions = tasks.map(function (task) { return task.actions || []; }); |
20 |
| - return { type: _types_1.PAGE_SET, payload: { page: page, tasks: tasks, position: selectedPosition, taskTests: taskTests, actions: actions } }; |
| 44 | + return { |
| 45 | + payload: { position: position }, |
| 46 | + type: _types_1.PAGE_SET, |
| 47 | + }; |
21 | 48 | }
|
22 | 49 | exports.pageSet = pageSet;
|
0 commit comments