get a tutorial about the API

This commit is contained in:
Delucse
2020-11-27 08:41:34 +01:00
parent 28d674b6cd
commit ea00d173c5
13 changed files with 220 additions and 82 deletions
+41 -12
View File
@@ -1,6 +1,34 @@
import { TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE, TUTORIAL_XML, TUTORIAL_ID, TUTORIAL_STEP } from './types';
import { TUTORIAL_PROGRESS, GET_TUTORIAL, TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE, TUTORIAL_XML, TUTORIAL_ID, TUTORIAL_STEP } from './types';
import tutorials from '../data/tutorials';
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}`)
.then(res => {
dispatch({type: TUTORIAL_PROGRESS});
dispatch({
type: GET_TUTORIAL,
payload: res.data
});
})
.catch(err => {
dispatch({type: TUTORIAL_PROGRESS});
if(err.response){
dispatch(returnErrors(err.response.data.message, err.response.status, 'GET_TUTORIAL_FAIL'));
}
});
};
export const resetTutorial = () => (dispatch) => {
dispatch({
type: GET_TUTORIAL,
payload: {}
});
};
export const tutorialChange = () => (dispatch) => {
dispatch({
@@ -10,7 +38,7 @@ export const tutorialChange = () => (dispatch) => {
export const tutorialCheck = (status, step) => (dispatch, getState) => {
var tutorialsStatus = getState().tutorial.status;
var id = getState().tutorial.currentId;
var id = getState().tutorial.tutorial.id;
var tutorialsStatusIndex = tutorialsStatus.findIndex(tutorialStatus => tutorialStatus.id === id);
var tasksIndex = tutorialsStatus[tutorialsStatusIndex].tasks.findIndex(task => task.id === step.id);
tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex] = {
@@ -25,11 +53,12 @@ export const tutorialCheck = (status, step) => (dispatch, getState) => {
};
export const storeTutorialXml = (code) => (dispatch, getState) => {
var id = getState().tutorial.currentId;
var tutorial = getState().tutorial.tutorial;
var id = tutorial.id;
if (id !== null) {
var activeStep = getState().tutorial.activeStep;
var steps = tutorials.filter(tutorial => tutorial.id === id)[0].steps;
if (steps[activeStep].type === 'task') {
var steps = tutorial.steps;//tutorials.filter(tutorial => tutorial.id === id)[0].steps;
if (steps && steps[activeStep].type === 'task') {
var tutorialsStatus = getState().tutorial.status;
var tutorialsStatusIndex = tutorialsStatus.findIndex(tutorialStatus => tutorialStatus.id === id);
var tasksIndex = tutorialsStatus[tutorialsStatusIndex].tasks.findIndex(task => task.id === steps[activeStep].id);
@@ -46,12 +75,12 @@ export const storeTutorialXml = (code) => (dispatch, getState) => {
};
export const tutorialId = (id) => (dispatch) => {
dispatch({
type: TUTORIAL_ID,
payload: id
});
};
// export const tutorialId = (id) => (dispatch) => {
// dispatch({
// type: TUTORIAL_ID,
// payload: id
// });
// };
export const tutorialStep = (step) => (dispatch) => {
dispatch({