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
+32
View File
@@ -0,0 +1,32 @@
import { GET_ERRORS, CLEAR_MESSAGES, GET_SUCCESS } from './types';
// RETURN Errors
export const returnErrors = (msg, status, id = null) => {
return {
type: GET_ERRORS,
payload: {
msg: msg,
status: status,
id: id
}
};
};
// RETURN Success
export const returnSuccess = (msg, status, id = null) => {
return {
type: GET_SUCCESS,
payload: {
msg: msg,
status: status,
id: id
}
};
};
// CLEAR_MESSAGES
export const clearMessages = () => {
return {
type: CLEAR_MESSAGES
};
};
+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({
+7 -1
View File
@@ -7,7 +7,8 @@ export const DELETE_BLOCK = 'DELETE_BLOCK';
export const CLEAR_STATS = 'CLEAR_STATS';
export const NAME = 'NAME';
export const TUTORIAL_PROGRESS = 'TUTORIAL_PROGRESS';
export const GET_TUTORIAL = 'GET_TUTORIAL';
export const TUTORIAL_SUCCESS = 'TUTORIAL_SUCCESS';
export const TUTORIAL_ERROR = 'TUTORIAL_ERROR';
export const TUTORIAL_CHANGE = 'TUTORIAL_CHANGE';
@@ -30,3 +31,8 @@ export const PROGRESS = 'PROGRESS';
export const VISIT = 'VISIT';
// messages
export const GET_ERRORS = 'GET_ERRORS';
export const GET_SUCCESS = 'GET_SUCCESS';
export const CLEAR_MESSAGES = 'CLEAR_MESSAGES';