get all tutorials about the API
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import { TUTORIAL_PROGRESS, GET_TUTORIAL, TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE, TUTORIAL_XML, TUTORIAL_ID, TUTORIAL_STEP } from './types';
|
||||
import { TUTORIAL_PROGRESS, GET_TUTORIAL, GET_TUTORIALS, TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE, TUTORIAL_XML, TUTORIAL_ID, TUTORIAL_STEP } from './types';
|
||||
|
||||
import axios from 'axios';
|
||||
import { returnErrors, returnSuccess } from './messageActions';
|
||||
|
||||
// import tutorials from '../data/tutorials';
|
||||
|
||||
export const getTutorial = (id) => (dispatch) => {
|
||||
dispatch({type: TUTORIAL_PROGRESS});
|
||||
axios.get(`https://api.blockly.sensebox.de/tutorial/${id}`)
|
||||
@@ -23,10 +21,28 @@ export const getTutorial = (id) => (dispatch) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const getTutorials = () => (dispatch) => {
|
||||
dispatch({type: TUTORIAL_PROGRESS});
|
||||
axios.get(`https://api.blockly.sensebox.de/tutorial`)
|
||||
.then(res => {
|
||||
dispatch({type: TUTORIAL_PROGRESS});
|
||||
dispatch({
|
||||
type: GET_TUTORIALS,
|
||||
payload: res.data
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
dispatch({type: TUTORIAL_PROGRESS});
|
||||
if(err.response){
|
||||
dispatch(returnErrors(err.response.data.message, err.response.status, 'GET_TUTORIALS_FAIL'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const resetTutorial = () => (dispatch) => {
|
||||
dispatch({
|
||||
type: GET_TUTORIAL,
|
||||
payload: {}
|
||||
type: GET_TUTORIALS,
|
||||
payload: []
|
||||
});
|
||||
};
|
||||
|
||||
@@ -38,7 +54,7 @@ export const tutorialChange = () => (dispatch) => {
|
||||
|
||||
export const tutorialCheck = (status, step) => (dispatch, getState) => {
|
||||
var tutorialsStatus = getState().tutorial.status;
|
||||
var id = getState().tutorial.tutorial.id;
|
||||
var id = getState().tutorial.tutorials[0].id;
|
||||
var tutorialsStatusIndex = tutorialsStatus.findIndex(tutorialStatus => tutorialStatus.id === id);
|
||||
var tasksIndex = tutorialsStatus[tutorialsStatusIndex].tasks.findIndex(task => task.id === step.id);
|
||||
tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex] = {
|
||||
@@ -53,11 +69,11 @@ export const tutorialCheck = (status, step) => (dispatch, getState) => {
|
||||
};
|
||||
|
||||
export const storeTutorialXml = (code) => (dispatch, getState) => {
|
||||
var tutorial = getState().tutorial.tutorial;
|
||||
var id = tutorial.id;
|
||||
if (id !== null) {
|
||||
var tutorial = getState().tutorial.tutorials[0];
|
||||
if (tutorial) {
|
||||
var id = tutorial.id;
|
||||
var activeStep = getState().tutorial.activeStep;
|
||||
var steps = tutorial.steps;//tutorials.filter(tutorial => tutorial.id === id)[0].steps;
|
||||
var steps = tutorial.steps;
|
||||
if (steps && steps[activeStep].type === 'task') {
|
||||
var tutorialsStatus = getState().tutorial.status;
|
||||
var tutorialsStatusIndex = tutorialsStatus.findIndex(tutorialStatus => tutorialStatus.id === id);
|
||||
@@ -74,14 +90,6 @@ export const storeTutorialXml = (code) => (dispatch, getState) => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// export const tutorialId = (id) => (dispatch) => {
|
||||
// dispatch({
|
||||
// type: TUTORIAL_ID,
|
||||
// payload: id
|
||||
// });
|
||||
// };
|
||||
|
||||
export const tutorialStep = (step) => (dispatch) => {
|
||||
dispatch({
|
||||
type: TUTORIAL_STEP,
|
||||
|
||||
@@ -9,6 +9,7 @@ export const NAME = 'NAME';
|
||||
|
||||
export const TUTORIAL_PROGRESS = 'TUTORIAL_PROGRESS';
|
||||
export const GET_TUTORIAL = 'GET_TUTORIAL';
|
||||
export const GET_TUTORIALS = 'GET_TUTORIALS';
|
||||
export const TUTORIAL_SUCCESS = 'TUTORIAL_SUCCESS';
|
||||
export const TUTORIAL_ERROR = 'TUTORIAL_ERROR';
|
||||
export const TUTORIAL_CHANGE = 'TUTORIAL_CHANGE';
|
||||
|
||||
Reference in New Issue
Block a user