remove mybadges integration
This commit is contained in:
+168
-198
@@ -1,290 +1,260 @@
|
||||
import { MYBADGES_CONNECT, MYBADGES_DISCONNECT, GET_STATUS, USER_LOADED, USER_LOADING, AUTH_ERROR, LOGIN_SUCCESS, LOGIN_FAIL, LOGOUT_SUCCESS, LOGOUT_FAIL, REFRESH_TOKEN_SUCCESS } from '../actions/types';
|
||||
import {
|
||||
GET_STATUS,
|
||||
USER_LOADED,
|
||||
USER_LOADING,
|
||||
AUTH_ERROR,
|
||||
LOGIN_SUCCESS,
|
||||
LOGIN_FAIL,
|
||||
LOGOUT_SUCCESS,
|
||||
LOGOUT_FAIL,
|
||||
REFRESH_TOKEN_SUCCESS,
|
||||
} from "../actions/types";
|
||||
|
||||
import axios from 'axios';
|
||||
import { returnErrors, returnSuccess } from './messageActions';
|
||||
import { setLanguage } from './generalActions';
|
||||
import axios from "axios";
|
||||
import { returnErrors, returnSuccess } from "./messageActions";
|
||||
import { setLanguage } from "./generalActions";
|
||||
|
||||
// Check token & load user
|
||||
export const loadUser = () => (dispatch) => {
|
||||
// user loading
|
||||
dispatch({
|
||||
type: USER_LOADING
|
||||
type: USER_LOADING,
|
||||
});
|
||||
const config = {
|
||||
success: res => {
|
||||
success: (res) => {
|
||||
dispatch({
|
||||
type: GET_STATUS,
|
||||
payload: res.data.user.status
|
||||
payload: res.data.user.status,
|
||||
});
|
||||
dispatch(setLanguage(res.data.user.language));
|
||||
dispatch({
|
||||
type: USER_LOADED,
|
||||
payload: res.data.user
|
||||
payload: res.data.user,
|
||||
});
|
||||
},
|
||||
error: err => {
|
||||
if(err.response){
|
||||
error: (err) => {
|
||||
if (err.response) {
|
||||
dispatch(returnErrors(err.response.data.message, err.response.status));
|
||||
}
|
||||
var status = [];
|
||||
if (window.localStorage.getItem('status')) {
|
||||
status = JSON.parse(window.localStorage.getItem('status'));
|
||||
if (window.localStorage.getItem("status")) {
|
||||
status = JSON.parse(window.localStorage.getItem("status"));
|
||||
}
|
||||
dispatch({
|
||||
type: GET_STATUS,
|
||||
payload: status
|
||||
payload: status,
|
||||
});
|
||||
dispatch({
|
||||
type: AUTH_ERROR
|
||||
type: AUTH_ERROR,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
axios.get(`${process.env.REACT_APP_BLOCKLY_API}/user`, config, dispatch(authInterceptor()))
|
||||
.then(res => {
|
||||
axios
|
||||
.get(
|
||||
`${process.env.REACT_APP_BLOCKLY_API}/user`,
|
||||
config,
|
||||
dispatch(authInterceptor())
|
||||
)
|
||||
.then((res) => {
|
||||
res.config.success(res);
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
err.config.error(err);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
var logoutTimerId;
|
||||
const timeToLogout = 14.9*60*1000; // nearly 15 minutes corresponding to the API
|
||||
const timeToLogout = 14.9 * 60 * 1000; // nearly 15 minutes corresponding to the API
|
||||
|
||||
// Login user
|
||||
export const login = ({ email, password }) => (dispatch) => {
|
||||
dispatch({
|
||||
type: USER_LOADING
|
||||
});
|
||||
// Headers
|
||||
const config = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
// Request Body
|
||||
const body = JSON.stringify({ email, password });
|
||||
axios.post(`${process.env.REACT_APP_BLOCKLY_API}/user`, body, config)
|
||||
.then(res => {
|
||||
// Logout automatically if refreshToken "expired"
|
||||
const logoutTimer = () => setTimeout(
|
||||
() => dispatch(logout()),
|
||||
timeToLogout
|
||||
);
|
||||
logoutTimerId = logoutTimer();
|
||||
dispatch(setLanguage(res.data.user.language));
|
||||
export const login =
|
||||
({ email, password }) =>
|
||||
(dispatch) => {
|
||||
dispatch({
|
||||
type: LOGIN_SUCCESS,
|
||||
payload: res.data
|
||||
type: USER_LOADING,
|
||||
});
|
||||
dispatch({
|
||||
type: GET_STATUS,
|
||||
payload: res.data.user.status
|
||||
});
|
||||
dispatch(returnSuccess(res.data.message, res.status, 'LOGIN_SUCCESS'));
|
||||
})
|
||||
.catch(err => {
|
||||
dispatch(returnErrors(err.response.data.message, err.response.status, 'LOGIN_FAIL'));
|
||||
dispatch({
|
||||
type: LOGIN_FAIL
|
||||
});
|
||||
var status = [];
|
||||
if (window.localStorage.getItem('status')) {
|
||||
status = JSON.parse(window.localStorage.getItem('status'));
|
||||
}
|
||||
dispatch({
|
||||
type: GET_STATUS,
|
||||
payload: status
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// Connect to MyBadges-Account
|
||||
export const connectMyBadges = ({ username, password }) => (dispatch, getState) => {
|
||||
const config = {
|
||||
success: res => {
|
||||
var user = getState().auth.user;
|
||||
user.badge = res.data.account;
|
||||
user.badges = res.data.badges;
|
||||
dispatch({
|
||||
type: MYBADGES_CONNECT,
|
||||
payload: user
|
||||
// Headers
|
||||
const config = {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
// Request Body
|
||||
const body = JSON.stringify({ email, password });
|
||||
axios
|
||||
.post(`${process.env.REACT_APP_BLOCKLY_API}/user`, body, config)
|
||||
.then((res) => {
|
||||
// Logout automatically if refreshToken "expired"
|
||||
const logoutTimer = () =>
|
||||
setTimeout(() => dispatch(logout()), timeToLogout);
|
||||
logoutTimerId = logoutTimer();
|
||||
dispatch(setLanguage(res.data.user.language));
|
||||
dispatch({
|
||||
type: LOGIN_SUCCESS,
|
||||
payload: res.data,
|
||||
});
|
||||
dispatch({
|
||||
type: GET_STATUS,
|
||||
payload: res.data.user.status,
|
||||
});
|
||||
dispatch(returnSuccess(res.data.message, res.status, "LOGIN_SUCCESS"));
|
||||
})
|
||||
.catch((err) => {
|
||||
dispatch(
|
||||
returnErrors(
|
||||
err.response.data.message,
|
||||
err.response.status,
|
||||
"LOGIN_FAIL"
|
||||
)
|
||||
);
|
||||
dispatch({
|
||||
type: LOGIN_FAIL,
|
||||
});
|
||||
var status = [];
|
||||
if (window.localStorage.getItem("status")) {
|
||||
status = JSON.parse(window.localStorage.getItem("status"));
|
||||
}
|
||||
dispatch({
|
||||
type: GET_STATUS,
|
||||
payload: status,
|
||||
});
|
||||
});
|
||||
dispatch(returnSuccess(res.data.message, res.status, 'MYBADGES_CONNECT_SUCCESS'));
|
||||
},
|
||||
error: err => {
|
||||
dispatch(returnErrors(err.response.data.message, err.response.status, 'MYBADGES_CONNECT_FAIL'));
|
||||
}
|
||||
};
|
||||
// Request Body
|
||||
const body = JSON.stringify({ username, password });
|
||||
axios.post(`${process.env.REACT_APP_BLOCKLY_API}/user/badge`, body, config)
|
||||
.then(res => {
|
||||
res.config.success(res);
|
||||
})
|
||||
.catch(err => {
|
||||
if(err.response && err.response.status !== 401){
|
||||
err.config.error(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Disconnect MyBadges-Account
|
||||
export const disconnectMyBadges = () => (dispatch, getState) => {
|
||||
const config = {
|
||||
success: res => {
|
||||
var user = getState().auth.user;
|
||||
user.badge = null;
|
||||
user.badges = null;
|
||||
dispatch({
|
||||
type: MYBADGES_DISCONNECT,
|
||||
payload: user
|
||||
});
|
||||
dispatch(returnSuccess(res.data.message, res.status, 'MYBADGES_DISCONNECT_SUCCESS'));
|
||||
},
|
||||
error: err => {
|
||||
dispatch(returnErrors(err.response.data.message, err.response.status, 'MYBADGES_DISCONNECT_FAIL'));
|
||||
}
|
||||
};
|
||||
axios.put(`${process.env.REACT_APP_BLOCKLY_API}/user/badge`, {}, config)
|
||||
.then(res => {
|
||||
res.config.success(res);
|
||||
})
|
||||
.catch(err => {
|
||||
if(err.response && err.response.status !== 401){
|
||||
err.config.error(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// Logout User
|
||||
export const logout = () => (dispatch) => {
|
||||
const config = {
|
||||
success: res => {
|
||||
success: (res) => {
|
||||
dispatch({
|
||||
type: LOGOUT_SUCCESS
|
||||
type: LOGOUT_SUCCESS,
|
||||
});
|
||||
var status = [];
|
||||
if (window.localStorage.getItem('status')) {
|
||||
status = JSON.parse(window.localStorage.getItem('status'));
|
||||
if (window.localStorage.getItem("status")) {
|
||||
status = JSON.parse(window.localStorage.getItem("status"));
|
||||
}
|
||||
dispatch({
|
||||
type: GET_STATUS,
|
||||
payload: status
|
||||
payload: status,
|
||||
});
|
||||
var locale = 'en_US';
|
||||
if (window.localStorage.getItem('locale')) {
|
||||
locale = window.localStorage.getItem('locale');
|
||||
}
|
||||
else if (navigator.language === 'de-DE'){
|
||||
locale = 'de_DE';
|
||||
var locale = "en_US";
|
||||
if (window.localStorage.getItem("locale")) {
|
||||
locale = window.localStorage.getItem("locale");
|
||||
} else if (navigator.language === "de-DE") {
|
||||
locale = "de_DE";
|
||||
}
|
||||
dispatch(setLanguage(locale));
|
||||
dispatch(returnSuccess(res.data.message, res.status, 'LOGOUT_SUCCESS'));
|
||||
dispatch(returnSuccess(res.data.message, res.status, "LOGOUT_SUCCESS"));
|
||||
clearTimeout(logoutTimerId);
|
||||
},
|
||||
error: err => {
|
||||
dispatch(returnErrors(err.response.data.message, err.response.status, 'LOGOUT_FAIL'));
|
||||
error: (err) => {
|
||||
dispatch(
|
||||
returnErrors(
|
||||
err.response.data.message,
|
||||
err.response.status,
|
||||
"LOGOUT_FAIL"
|
||||
)
|
||||
);
|
||||
dispatch({
|
||||
type: LOGOUT_FAIL
|
||||
type: LOGOUT_FAIL,
|
||||
});
|
||||
var status = [];
|
||||
if (window.localStorage.getItem('status')) {
|
||||
status = JSON.parse(window.localStorage.getItem('status'));
|
||||
if (window.localStorage.getItem("status")) {
|
||||
status = JSON.parse(window.localStorage.getItem("status"));
|
||||
}
|
||||
dispatch({
|
||||
type: GET_STATUS,
|
||||
payload: status
|
||||
payload: status,
|
||||
});
|
||||
clearTimeout(logoutTimerId);
|
||||
}
|
||||
},
|
||||
};
|
||||
axios.post('https://api.opensensemap.org/users/sign-out', {}, config)
|
||||
.then(res => {
|
||||
res.config.success(res);
|
||||
})
|
||||
.catch(err => {
|
||||
if(err.response && err.response.status !== 401){
|
||||
err.config.error(err);
|
||||
}
|
||||
});
|
||||
axios
|
||||
.post("https://api.opensensemap.org/users/sign-out", {}, config)
|
||||
.then((res) => {
|
||||
res.config.success(res);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.response && err.response.status !== 401) {
|
||||
err.config.error(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export const authInterceptor = () => (dispatch, getState) => {
|
||||
// Add a request interceptor
|
||||
axios.interceptors.request.use(
|
||||
config => {
|
||||
config.headers['Content-Type'] = 'application/json';
|
||||
(config) => {
|
||||
config.headers["Content-Type"] = "application/json";
|
||||
const token = getState().auth.token;
|
||||
if (token) {
|
||||
config.headers['Authorization'] = `Bearer ${token}`;
|
||||
config.headers["Authorization"] = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
error => {
|
||||
Promise.reject(error);
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// Add a response interceptor
|
||||
axios.interceptors.response.use(
|
||||
response => {
|
||||
(response) => {
|
||||
// request was successfull
|
||||
return response;
|
||||
},
|
||||
error => {
|
||||
(error) => {
|
||||
const originalRequest = error.config;
|
||||
const refreshToken = getState().auth.refreshToken;
|
||||
if(refreshToken){
|
||||
if (refreshToken) {
|
||||
// try to refresh the token failed
|
||||
if (error.response.status === 401 && originalRequest._retry) {
|
||||
// router.push('/login');
|
||||
return Promise.reject(error);
|
||||
// router.push('/login');
|
||||
return Promise.reject(error);
|
||||
}
|
||||
// token was not valid and 1st try to refresh the token
|
||||
if (error.response.status === 401 && !originalRequest._retry) {
|
||||
originalRequest._retry = true;
|
||||
const refreshToken = getState().auth.refreshToken;
|
||||
// request to refresh the token, in request-body is the refreshToken
|
||||
axios.post('https://api.opensensemap.org/users/refresh-auth', {"token": refreshToken})
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
clearTimeout(logoutTimerId);
|
||||
const logoutTimer = () => setTimeout(
|
||||
() => dispatch(logout()),
|
||||
timeToLogout
|
||||
);
|
||||
logoutTimerId = logoutTimer();
|
||||
dispatch({
|
||||
type: REFRESH_TOKEN_SUCCESS,
|
||||
payload: res.data
|
||||
});
|
||||
axios.defaults.headers.common['Authorization'] = 'Bearer ' + getState().auth.token;
|
||||
// request was successfull, new request with the old parameters and the refreshed token
|
||||
return axios(originalRequest)
|
||||
.then(res => {
|
||||
originalRequest.success(res);
|
||||
})
|
||||
.catch(err => {
|
||||
originalRequest.error(err);
|
||||
});
|
||||
}
|
||||
return Promise.reject(error);
|
||||
})
|
||||
.catch(err => {
|
||||
// request failed, token could not be refreshed
|
||||
if(err.response){
|
||||
dispatch(returnErrors(err.response.data.message, err.response.status));
|
||||
}
|
||||
dispatch({
|
||||
type: AUTH_ERROR
|
||||
});
|
||||
return Promise.reject(error);
|
||||
});
|
||||
axios
|
||||
.post("https://api.opensensemap.org/users/refresh-auth", {
|
||||
token: refreshToken,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.status === 200) {
|
||||
clearTimeout(logoutTimerId);
|
||||
const logoutTimer = () =>
|
||||
setTimeout(() => dispatch(logout()), timeToLogout);
|
||||
logoutTimerId = logoutTimer();
|
||||
dispatch({
|
||||
type: REFRESH_TOKEN_SUCCESS,
|
||||
payload: res.data,
|
||||
});
|
||||
axios.defaults.headers.common["Authorization"] =
|
||||
"Bearer " + getState().auth.token;
|
||||
// request was successfull, new request with the old parameters and the refreshed token
|
||||
return axios(originalRequest)
|
||||
.then((res) => {
|
||||
originalRequest.success(res);
|
||||
})
|
||||
.catch((err) => {
|
||||
originalRequest.error(err);
|
||||
});
|
||||
}
|
||||
return Promise.reject(error);
|
||||
})
|
||||
.catch((err) => {
|
||||
// request failed, token could not be refreshed
|
||||
if (err.response) {
|
||||
dispatch(
|
||||
returnErrors(err.response.data.message, err.response.status)
|
||||
);
|
||||
}
|
||||
dispatch({
|
||||
type: AUTH_ERROR,
|
||||
});
|
||||
return Promise.reject(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
// request status was unequal to 401, no possibility to refresh the token
|
||||
|
||||
+158
-129
@@ -1,107 +1,105 @@
|
||||
import { MYBADGES_DISCONNECT, TUTORIAL_PROGRESS, GET_TUTORIAL, GET_TUTORIALS, TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE, TUTORIAL_XML, TUTORIAL_STEP } from './types';
|
||||
import {
|
||||
TUTORIAL_PROGRESS,
|
||||
GET_TUTORIAL,
|
||||
GET_TUTORIALS,
|
||||
TUTORIAL_SUCCESS,
|
||||
TUTORIAL_ERROR,
|
||||
TUTORIAL_CHANGE,
|
||||
TUTORIAL_XML,
|
||||
TUTORIAL_STEP,
|
||||
} from "./types";
|
||||
|
||||
import axios from 'axios';
|
||||
import { returnErrors, returnSuccess } from './messageActions';
|
||||
import axios from "axios";
|
||||
import { returnErrors, returnSuccess } from "./messageActions";
|
||||
|
||||
export const tutorialProgress = () => (dispatch) => {
|
||||
dispatch({type: TUTORIAL_PROGRESS});
|
||||
dispatch({ type: TUTORIAL_PROGRESS });
|
||||
};
|
||||
|
||||
|
||||
export const getTutorial = (id) => (dispatch, getState) => {
|
||||
axios.get(`${process.env.REACT_APP_BLOCKLY_API}/tutorial/${id}`)
|
||||
.then(res => {
|
||||
axios
|
||||
.get(`${process.env.REACT_APP_BLOCKLY_API}/tutorial/${id}`)
|
||||
.then((res) => {
|
||||
var tutorial = res.data.tutorial;
|
||||
existingTutorial(tutorial, getState().tutorial.status).then(status => {
|
||||
existingTutorial(tutorial, getState().tutorial.status).then((status) => {
|
||||
dispatch({
|
||||
type: TUTORIAL_SUCCESS,
|
||||
payload: status
|
||||
payload: status,
|
||||
});
|
||||
dispatch(updateStatus(status));
|
||||
dispatch({
|
||||
type: GET_TUTORIAL,
|
||||
payload: tutorial
|
||||
payload: tutorial,
|
||||
});
|
||||
dispatch({type: TUTORIAL_PROGRESS});
|
||||
dispatch({ type: TUTORIAL_PROGRESS });
|
||||
dispatch(returnSuccess(res.data.message, res.status));
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
if (err.response) {
|
||||
dispatch(returnErrors(err.response.data.message, err.response.status, 'GET_TUTORIAL_FAIL'));
|
||||
dispatch(
|
||||
returnErrors(
|
||||
err.response.data.message,
|
||||
err.response.status,
|
||||
"GET_TUTORIAL_FAIL"
|
||||
)
|
||||
);
|
||||
}
|
||||
dispatch({ type: TUTORIAL_PROGRESS });
|
||||
});
|
||||
};
|
||||
|
||||
export const getTutorials = () => (dispatch, getState) => {
|
||||
axios.get(`${process.env.REACT_APP_BLOCKLY_API}/tutorial`)
|
||||
.then(res => {
|
||||
axios
|
||||
.get(`${process.env.REACT_APP_BLOCKLY_API}/tutorial`)
|
||||
.then((res) => {
|
||||
var tutorials = res.data.tutorials;
|
||||
existingTutorials(tutorials, getState().tutorial.status).then(status => {
|
||||
dispatch({
|
||||
type: TUTORIAL_SUCCESS,
|
||||
payload: status
|
||||
});
|
||||
dispatch(updateStatus(status));
|
||||
dispatch({
|
||||
type: GET_TUTORIALS,
|
||||
payload: tutorials
|
||||
});
|
||||
dispatch({ type: TUTORIAL_PROGRESS });
|
||||
dispatch(returnSuccess(res.data.message, res.status));
|
||||
});
|
||||
existingTutorials(tutorials, getState().tutorial.status).then(
|
||||
(status) => {
|
||||
dispatch({
|
||||
type: TUTORIAL_SUCCESS,
|
||||
payload: status,
|
||||
});
|
||||
dispatch(updateStatus(status));
|
||||
dispatch({
|
||||
type: GET_TUTORIALS,
|
||||
payload: tutorials,
|
||||
});
|
||||
dispatch({ type: TUTORIAL_PROGRESS });
|
||||
dispatch(returnSuccess(res.data.message, res.status));
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
if (err.response) {
|
||||
dispatch(returnErrors(err.response.data.message, err.response.status, 'GET_TUTORIALS_FAIL'));
|
||||
dispatch(
|
||||
returnErrors(
|
||||
err.response.data.message,
|
||||
err.response.status,
|
||||
"GET_TUTORIALS_FAIL"
|
||||
)
|
||||
);
|
||||
}
|
||||
dispatch({ type: TUTORIAL_PROGRESS });
|
||||
});
|
||||
};
|
||||
|
||||
export const assigneBadge = (id) => (dispatch, getState) => {
|
||||
const config = {
|
||||
success: res => {
|
||||
var badge = res.data.badge;
|
||||
var user = getState().auth.user;
|
||||
user.badges.push(badge._id);
|
||||
dispatch({
|
||||
type: MYBADGES_DISCONNECT,
|
||||
payload: user
|
||||
});
|
||||
dispatch(returnSuccess(badge, res.status, 'ASSIGNE_BADGE_SUCCESS'));
|
||||
},
|
||||
error: err => {
|
||||
dispatch(returnErrors(err.response.data.message, err.response.status, 'ASSIGNE_BADGE_FAIL'));
|
||||
}
|
||||
};
|
||||
axios.put(`${process.env.REACT_APP_BLOCKLY_API}/user/badge/${id}`, {}, config)
|
||||
.then(res => {
|
||||
res.config.success(res);
|
||||
})
|
||||
.catch(err => {
|
||||
if(err.response && err.response.status !== 401){
|
||||
err.config.error(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const updateStatus = (status) => (dispatch, getState) => {
|
||||
if(getState().auth.isAuthenticated){
|
||||
if (getState().auth.isAuthenticated) {
|
||||
// update user account in database - sync with redux store
|
||||
axios.put(`${process.env.REACT_APP_BLOCKLY_API}/user/status`, {status: status})
|
||||
.then(res => {
|
||||
// dispatch(returnSuccess(badge, res.status, 'UPDATE_STATUS_SUCCESS'));
|
||||
axios
|
||||
.put(`${process.env.REACT_APP_BLOCKLY_API}/user/status`, {
|
||||
status: status,
|
||||
})
|
||||
.catch(err => {
|
||||
if(err.response){
|
||||
.then((res) => {})
|
||||
.catch((err) => {
|
||||
if (err.response) {
|
||||
// dispatch(returnErrors(err.response.data.message, err.response.status, 'UPDATE_STATUS_FAIL'));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// update locale storage - sync with redux store
|
||||
window.localStorage.setItem('status', JSON.stringify(status));
|
||||
window.localStorage.setItem("status", JSON.stringify(status));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -109,65 +107,77 @@ export const deleteTutorial = (id) => (dispatch, getState) => {
|
||||
var tutorial = getState().tutorial;
|
||||
var id = getState().builder.id;
|
||||
const config = {
|
||||
success: res => {
|
||||
success: (res) => {
|
||||
var tutorials = tutorial.tutorials;
|
||||
var index = tutorials.findIndex(res => res._id === id);
|
||||
tutorials.splice(index, 1)
|
||||
var index = tutorials.findIndex((res) => res._id === id);
|
||||
tutorials.splice(index, 1);
|
||||
dispatch({
|
||||
type: GET_TUTORIALS,
|
||||
payload: tutorials
|
||||
payload: tutorials,
|
||||
});
|
||||
dispatch(returnSuccess(res.data.message, res.status, 'TUTORIAL_DELETE_SUCCESS'));
|
||||
dispatch(
|
||||
returnSuccess(res.data.message, res.status, "TUTORIAL_DELETE_SUCCESS")
|
||||
);
|
||||
},
|
||||
error: (err) => {
|
||||
dispatch(
|
||||
returnErrors(
|
||||
err.response.data.message,
|
||||
err.response.status,
|
||||
"TUTORIAL_DELETE_FAIL"
|
||||
)
|
||||
);
|
||||
},
|
||||
error: err => {
|
||||
dispatch(returnErrors(err.response.data.message, err.response.status, 'TUTORIAL_DELETE_FAIL'));
|
||||
}
|
||||
};
|
||||
axios.delete(`${process.env.REACT_APP_BLOCKLY_API}/tutorial/${id}`, config)
|
||||
.then(res => {
|
||||
axios
|
||||
.delete(`${process.env.REACT_APP_BLOCKLY_API}/tutorial/${id}`, config)
|
||||
.then((res) => {
|
||||
res.config.success(res);
|
||||
})
|
||||
.catch(err => {
|
||||
if(err.response && err.response.status !== 401){
|
||||
.catch((err) => {
|
||||
if (err.response && err.response.status !== 401) {
|
||||
err.config.error(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export const resetTutorial = () => (dispatch) => {
|
||||
dispatch({
|
||||
type: GET_TUTORIALS,
|
||||
payload: []
|
||||
payload: [],
|
||||
});
|
||||
dispatch({
|
||||
type: TUTORIAL_STEP,
|
||||
payload: 0
|
||||
payload: 0,
|
||||
});
|
||||
};
|
||||
|
||||
export const tutorialChange = () => (dispatch) => {
|
||||
dispatch({
|
||||
type: TUTORIAL_CHANGE
|
||||
type: TUTORIAL_CHANGE,
|
||||
});
|
||||
};
|
||||
|
||||
export const tutorialCheck = (status, step) => (dispatch, getState) => {
|
||||
var tutorialsStatus = getState().tutorial.status;
|
||||
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);
|
||||
var tutorialsStatusIndex = tutorialsStatus.findIndex(
|
||||
(tutorialStatus) => tutorialStatus._id === id
|
||||
);
|
||||
var tasksIndex = tutorialsStatus[tutorialsStatusIndex].tasks.findIndex(
|
||||
(task) => task._id === step._id
|
||||
);
|
||||
tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex] = {
|
||||
...tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex],
|
||||
type: status
|
||||
type: status,
|
||||
};
|
||||
dispatch({
|
||||
type: status === 'success' ? TUTORIAL_SUCCESS : TUTORIAL_ERROR,
|
||||
payload: tutorialsStatus
|
||||
type: status === "success" ? TUTORIAL_SUCCESS : TUTORIAL_ERROR,
|
||||
payload: tutorialsStatus,
|
||||
});
|
||||
dispatch(updateStatus(tutorialsStatus));
|
||||
dispatch(tutorialChange());
|
||||
dispatch(returnSuccess('', '', 'TUTORIAL_CHECK_SUCCESS'));
|
||||
dispatch(returnSuccess("", "", "TUTORIAL_CHECK_SUCCESS"));
|
||||
};
|
||||
|
||||
export const storeTutorialXml = (code) => (dispatch, getState) => {
|
||||
@@ -176,17 +186,21 @@ export const storeTutorialXml = (code) => (dispatch, getState) => {
|
||||
var id = tutorial._id;
|
||||
var activeStep = getState().tutorial.activeStep;
|
||||
var steps = tutorial.steps;
|
||||
if (steps && steps[activeStep].type === 'task') {
|
||||
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);
|
||||
var tutorialsStatusIndex = tutorialsStatus.findIndex(
|
||||
(tutorialStatus) => tutorialStatus._id === id
|
||||
);
|
||||
var tasksIndex = tutorialsStatus[tutorialsStatusIndex].tasks.findIndex(
|
||||
(task) => task._id === steps[activeStep]._id
|
||||
);
|
||||
tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex] = {
|
||||
...tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex],
|
||||
xml: code
|
||||
xml: code,
|
||||
};
|
||||
dispatch({
|
||||
type: TUTORIAL_XML,
|
||||
payload: tutorialsStatus
|
||||
payload: tutorialsStatus,
|
||||
});
|
||||
dispatch(updateStatus(tutorialsStatus));
|
||||
}
|
||||
@@ -196,50 +210,65 @@ export const storeTutorialXml = (code) => (dispatch, getState) => {
|
||||
export const tutorialStep = (step) => (dispatch) => {
|
||||
dispatch({
|
||||
type: TUTORIAL_STEP,
|
||||
payload: step
|
||||
payload: step,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const existingTutorials = (tutorials, status) => new Promise(function (resolve, reject) {
|
||||
var newstatus;
|
||||
const existingTutorials = (tutorials, status) =>
|
||||
new Promise(function (resolve, reject) {
|
||||
var existingTutorialIds = tutorials.map((tutorial, i) => {
|
||||
existingTutorial(tutorial, status).then(status => {
|
||||
newstatus = status;
|
||||
var newstatus;
|
||||
new Promise(function (resolve, reject) {
|
||||
var existingTutorialIds = tutorials.map((tutorial, i) => {
|
||||
existingTutorial(tutorial, status).then((status) => {
|
||||
newstatus = status;
|
||||
});
|
||||
return tutorial._id;
|
||||
});
|
||||
return tutorial._id;
|
||||
resolve(existingTutorialIds);
|
||||
}).then((existingTutorialIds) => {
|
||||
// deleting old tutorials which do not longer exist
|
||||
if (existingTutorialIds.length > 0) {
|
||||
status = newstatus.filter(
|
||||
(status) => existingTutorialIds.indexOf(status._id) > -1
|
||||
);
|
||||
}
|
||||
resolve(status);
|
||||
});
|
||||
resolve(existingTutorialIds)
|
||||
}).then(existingTutorialIds => {
|
||||
// deleting old tutorials which do not longer exist
|
||||
if (existingTutorialIds.length > 0) {
|
||||
status = newstatus.filter(status => existingTutorialIds.indexOf(status._id) > -1);
|
||||
});
|
||||
|
||||
const existingTutorial = (tutorial, status) =>
|
||||
new Promise(function (resolve, reject) {
|
||||
var tutorialsId = tutorial._id;
|
||||
var statusIndex = status.findIndex((status) => status._id === tutorialsId);
|
||||
if (statusIndex > -1) {
|
||||
var tasks = tutorial.steps.filter((step) => step.type === "task");
|
||||
var existingTaskIds = tasks.map((task, j) => {
|
||||
var tasksId = task._id;
|
||||
if (
|
||||
status[statusIndex].tasks.findIndex(
|
||||
(task) => task._id === tasksId
|
||||
) === -1
|
||||
) {
|
||||
// task does not exist
|
||||
status[statusIndex].tasks.push({ _id: tasksId });
|
||||
}
|
||||
return tasksId;
|
||||
});
|
||||
// deleting old tasks which do not longer exist
|
||||
if (existingTaskIds.length > 0) {
|
||||
status[statusIndex].tasks = status[statusIndex].tasks.filter(
|
||||
(task) => existingTaskIds.indexOf(task._id) > -1
|
||||
);
|
||||
}
|
||||
} else {
|
||||
status.push({
|
||||
_id: tutorialsId,
|
||||
tasks: tutorial.steps
|
||||
.filter((step) => step.type === "task")
|
||||
.map((task) => {
|
||||
return { _id: task._id };
|
||||
}),
|
||||
});
|
||||
}
|
||||
resolve(status);
|
||||
});
|
||||
});
|
||||
|
||||
const existingTutorial = (tutorial, status) => new Promise(function(resolve, reject){
|
||||
var tutorialsId = tutorial._id;
|
||||
var statusIndex = status.findIndex(status => status._id === tutorialsId);
|
||||
if (statusIndex > -1) {
|
||||
var tasks = tutorial.steps.filter(step => step.type === 'task');
|
||||
var existingTaskIds = tasks.map((task, j) => {
|
||||
var tasksId = task._id;
|
||||
if (status[statusIndex].tasks.findIndex(task => task._id === tasksId) === -1) {
|
||||
// task does not exist
|
||||
status[statusIndex].tasks.push({ _id: tasksId });
|
||||
}
|
||||
return tasksId;
|
||||
});
|
||||
// deleting old tasks which do not longer exist
|
||||
if (existingTaskIds.length > 0) {
|
||||
status[statusIndex].tasks = status[statusIndex].tasks.filter(task => existingTaskIds.indexOf(task._id) > -1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
status.push({ _id: tutorialsId, tasks: tutorial.steps.filter(step => step.type === 'task').map(task => { return { _id: task._id }; }) });
|
||||
}
|
||||
resolve(status);
|
||||
});
|
||||
|
||||
@@ -1,24 +1,36 @@
|
||||
import { PROGRESS, JSON_STRING, BUILDER_CHANGE, BUILDER_ERROR, BUILDER_TITLE, BUILDER_ID, BUILDER_BADGE, BUILDER_ADD_STEP, BUILDER_DELETE_STEP, BUILDER_CHANGE_STEP, BUILDER_CHANGE_ORDER, BUILDER_DELETE_PROPERTY } from './types';
|
||||
import {
|
||||
PROGRESS,
|
||||
JSON_STRING,
|
||||
BUILDER_CHANGE,
|
||||
BUILDER_ERROR,
|
||||
BUILDER_TITLE,
|
||||
BUILDER_ID,
|
||||
BUILDER_ADD_STEP,
|
||||
BUILDER_DELETE_STEP,
|
||||
BUILDER_CHANGE_STEP,
|
||||
BUILDER_CHANGE_ORDER,
|
||||
BUILDER_DELETE_PROPERTY,
|
||||
} from "./types";
|
||||
|
||||
import data from '../data/hardware.json';
|
||||
import data from "../data/hardware.json";
|
||||
|
||||
export const changeTutorialBuilder = () => (dispatch) => {
|
||||
dispatch({
|
||||
type: BUILDER_CHANGE
|
||||
type: BUILDER_CHANGE,
|
||||
});
|
||||
};
|
||||
|
||||
export const jsonString = (json) => (dispatch) => {
|
||||
dispatch({
|
||||
type: JSON_STRING,
|
||||
payload: json
|
||||
payload: json,
|
||||
});
|
||||
};
|
||||
|
||||
export const tutorialTitle = (title) => (dispatch) => {
|
||||
dispatch({
|
||||
type: BUILDER_TITLE,
|
||||
payload: title
|
||||
payload: title,
|
||||
});
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
@@ -26,7 +38,7 @@ export const tutorialTitle = (title) => (dispatch) => {
|
||||
export const tutorialSteps = (steps) => (dispatch) => {
|
||||
dispatch({
|
||||
type: BUILDER_ADD_STEP,
|
||||
payload: steps
|
||||
payload: steps,
|
||||
});
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
@@ -34,15 +46,7 @@ export const tutorialSteps = (steps) => (dispatch) => {
|
||||
export const tutorialId = (id) => (dispatch) => {
|
||||
dispatch({
|
||||
type: BUILDER_ID,
|
||||
payload: id
|
||||
});
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
|
||||
export const tutorialBadge = (badge) => (dispatch) => {
|
||||
dispatch({
|
||||
type: BUILDER_BADGE,
|
||||
payload: badge
|
||||
payload: id,
|
||||
});
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
@@ -51,14 +55,14 @@ export const addStep = (index) => (dispatch, getState) => {
|
||||
var steps = getState().builder.steps;
|
||||
var step = {
|
||||
id: index + 1,
|
||||
type: 'instruction',
|
||||
headline: '',
|
||||
text: ''
|
||||
type: "instruction",
|
||||
headline: "",
|
||||
text: "",
|
||||
};
|
||||
steps.splice(index, 0, step);
|
||||
dispatch({
|
||||
type: BUILDER_ADD_STEP,
|
||||
payload: steps
|
||||
payload: steps,
|
||||
});
|
||||
dispatch(addErrorStep(index));
|
||||
dispatch(changeTutorialBuilder());
|
||||
@@ -69,7 +73,7 @@ export const addErrorStep = (index) => (dispatch, getState) => {
|
||||
error.steps.splice(index, 0, {});
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: error
|
||||
payload: error,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -78,7 +82,7 @@ export const removeStep = (index) => (dispatch, getState) => {
|
||||
steps.splice(index, 1);
|
||||
dispatch({
|
||||
type: BUILDER_DELETE_STEP,
|
||||
payload: steps
|
||||
payload: steps,
|
||||
});
|
||||
dispatch(removeErrorStep(index));
|
||||
dispatch(changeTutorialBuilder());
|
||||
@@ -89,45 +93,47 @@ export const removeErrorStep = (index) => (dispatch, getState) => {
|
||||
error.steps.splice(index, 1);
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: error
|
||||
payload: error,
|
||||
});
|
||||
};
|
||||
|
||||
export const changeContent = (content, index, property1, property2) => (dispatch, getState) => {
|
||||
var steps = getState().builder.steps;
|
||||
var step = steps[index];
|
||||
if (property2) {
|
||||
if (step[property1] && step[property1][property2]) {
|
||||
step[property1][property2] = content;
|
||||
export const changeContent =
|
||||
(content, index, property1, property2) => (dispatch, getState) => {
|
||||
var steps = getState().builder.steps;
|
||||
var step = steps[index];
|
||||
if (property2) {
|
||||
if (step[property1] && step[property1][property2]) {
|
||||
step[property1][property2] = content;
|
||||
} else {
|
||||
step[property1] = { [property2]: content };
|
||||
}
|
||||
} else {
|
||||
step[property1] = { [property2]: content };
|
||||
step[property1] = content;
|
||||
}
|
||||
} else {
|
||||
step[property1] = content;
|
||||
}
|
||||
dispatch({
|
||||
type: BUILDER_CHANGE_STEP,
|
||||
payload: steps
|
||||
});
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
dispatch({
|
||||
type: BUILDER_CHANGE_STEP,
|
||||
payload: steps,
|
||||
});
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
|
||||
export const deleteProperty = (index, property1, property2) => (dispatch, getState) => {
|
||||
var steps = getState().builder.steps;
|
||||
var step = steps[index];
|
||||
if (property2) {
|
||||
if (step[property1] && step[property1][property2]) {
|
||||
delete step[property1][property2];
|
||||
export const deleteProperty =
|
||||
(index, property1, property2) => (dispatch, getState) => {
|
||||
var steps = getState().builder.steps;
|
||||
var step = steps[index];
|
||||
if (property2) {
|
||||
if (step[property1] && step[property1][property2]) {
|
||||
delete step[property1][property2];
|
||||
}
|
||||
} else {
|
||||
delete step[property1];
|
||||
}
|
||||
} else {
|
||||
delete step[property1];
|
||||
}
|
||||
dispatch({
|
||||
type: BUILDER_DELETE_PROPERTY,
|
||||
payload: steps
|
||||
});
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
dispatch({
|
||||
type: BUILDER_DELETE_PROPERTY,
|
||||
payload: steps,
|
||||
});
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
|
||||
export const changeStepIndex = (fromIndex, toIndex) => (dispatch, getState) => {
|
||||
var steps = getState().builder.steps;
|
||||
@@ -136,34 +142,34 @@ export const changeStepIndex = (fromIndex, toIndex) => (dispatch, getState) => {
|
||||
steps.splice(toIndex, 0, step);
|
||||
dispatch({
|
||||
type: BUILDER_CHANGE_ORDER,
|
||||
payload: steps
|
||||
payload: steps,
|
||||
});
|
||||
dispatch(changeErrorStepIndex(fromIndex, toIndex));
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
|
||||
export const changeErrorStepIndex = (fromIndex, toIndex) => (dispatch, getState) => {
|
||||
var error = getState().builder.error;
|
||||
var errorStep = error.steps[fromIndex];
|
||||
error.steps.splice(fromIndex, 1);
|
||||
error.steps.splice(toIndex, 0, errorStep);
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: error
|
||||
});
|
||||
};
|
||||
export const changeErrorStepIndex =
|
||||
(fromIndex, toIndex) => (dispatch, getState) => {
|
||||
var error = getState().builder.error;
|
||||
var errorStep = error.steps[fromIndex];
|
||||
error.steps.splice(fromIndex, 1);
|
||||
error.steps.splice(toIndex, 0, errorStep);
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: error,
|
||||
});
|
||||
};
|
||||
|
||||
export const setError = (index, property) => (dispatch, getState) => {
|
||||
var error = getState().builder.error;
|
||||
if (index !== undefined) {
|
||||
error.steps[index][property] = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
error[property] = true;
|
||||
}
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: error
|
||||
payload: error,
|
||||
});
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
@@ -172,13 +178,12 @@ export const deleteError = (index, property) => (dispatch, getState) => {
|
||||
var error = getState().builder.error;
|
||||
if (index !== undefined) {
|
||||
delete error.steps[index][property];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
delete error[property];
|
||||
}
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: error
|
||||
payload: error,
|
||||
});
|
||||
dispatch(changeTutorialBuilder());
|
||||
};
|
||||
@@ -188,11 +193,11 @@ export const setSubmitError = () => (dispatch, getState) => {
|
||||
// if(builder.id === undefined || builder.id === ''){
|
||||
// dispatch(setError(undefined, 'id'));
|
||||
// }
|
||||
if (builder.title === '') {
|
||||
dispatch(setError(undefined, 'title'));
|
||||
if (builder.title === "") {
|
||||
dispatch(setError(undefined, "title"));
|
||||
}
|
||||
if (builder.title === null) {
|
||||
dispatch(setError(undefined, 'badge'));
|
||||
dispatch(setError(undefined, "title"));
|
||||
}
|
||||
var type = builder.steps.map((step, i) => {
|
||||
// media and xml are directly checked for errors in their components and
|
||||
@@ -200,76 +205,82 @@ export const setSubmitError = () => (dispatch, getState) => {
|
||||
step.id = i + 1;
|
||||
if (i === 0) {
|
||||
if (step.requirements && step.requirements.length > 0) {
|
||||
var requirements = step.requirements.filter(requirement => /^[0-9a-fA-F]{24}$/.test(requirement));
|
||||
var requirements = step.requirements.filter((requirement) =>
|
||||
/^[0-9a-fA-F]{24}$/.test(requirement)
|
||||
);
|
||||
if (requirements.length < step.requirements.length) {
|
||||
dispatch(changeContent(requirements, i, 'requirements'));
|
||||
dispatch(changeContent(requirements, i, "requirements"));
|
||||
}
|
||||
}
|
||||
if (step.hardware === undefined || step.hardware.length < 1) {
|
||||
dispatch(setError(i, 'hardware'));
|
||||
}
|
||||
else {
|
||||
var hardwareIds = data.map(hardware => hardware.id);
|
||||
var hardware = step.hardware.filter(hardware => hardwareIds.includes(hardware));
|
||||
dispatch(setError(i, "hardware"));
|
||||
} else {
|
||||
var hardwareIds = data.map((hardware) => hardware.id);
|
||||
var hardware = step.hardware.filter((hardware) =>
|
||||
hardwareIds.includes(hardware)
|
||||
);
|
||||
if (hardware.length < step.hardware.length) {
|
||||
dispatch(changeContent(hardware, i, 'hardware'));
|
||||
dispatch(changeContent(hardware, i, "hardware"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (step.headline === undefined || step.headline === '') {
|
||||
dispatch(setError(i, 'headline'));
|
||||
if (step.headline === undefined || step.headline === "") {
|
||||
dispatch(setError(i, "headline"));
|
||||
}
|
||||
if (step.text === undefined || step.text === '') {
|
||||
dispatch(setError(i, 'text'));
|
||||
if (step.text === undefined || step.text === "") {
|
||||
dispatch(setError(i, "text"));
|
||||
}
|
||||
return step.type;
|
||||
});
|
||||
if (!(type.filter(item => item === 'task').length > 0 && type.filter(item => item === 'instruction').length > 0)) {
|
||||
dispatch(setError(undefined, 'type'));
|
||||
if (
|
||||
!(
|
||||
type.filter((item) => item === "task").length > 0 &&
|
||||
type.filter((item) => item === "instruction").length > 0
|
||||
)
|
||||
) {
|
||||
dispatch(setError(undefined, "type"));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const checkError = () => (dispatch, getState) => {
|
||||
dispatch(setSubmitError());
|
||||
var error = getState().builder.error;
|
||||
if (error.id || error.title || error.badge ||error.type) {
|
||||
if (error.id || error.title || error.type) {
|
||||
return true;
|
||||
}
|
||||
for (var i = 0; i < error.steps.length; i++) {
|
||||
if (Object.keys(error.steps[i]).length > 0) {
|
||||
return true
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const progress = (inProgress) => (dispatch) => {
|
||||
dispatch({
|
||||
type: PROGRESS,
|
||||
payload: inProgress
|
||||
})
|
||||
payload: inProgress,
|
||||
});
|
||||
};
|
||||
|
||||
export const resetTutorial = () => (dispatch, getState) => {
|
||||
dispatch(jsonString(''));
|
||||
dispatch(tutorialTitle(''));
|
||||
dispatch(tutorialBadge(undefined));
|
||||
dispatch(jsonString(""));
|
||||
dispatch(tutorialTitle(""));
|
||||
var steps = [
|
||||
{
|
||||
type: 'instruction',
|
||||
headline: '',
|
||||
text: '',
|
||||
type: "instruction",
|
||||
headline: "",
|
||||
text: "",
|
||||
hardware: [],
|
||||
requirements: []
|
||||
}
|
||||
requirements: [],
|
||||
},
|
||||
];
|
||||
dispatch(tutorialSteps(steps));
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: {
|
||||
steps: [{}]
|
||||
}
|
||||
steps: [{}],
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -278,8 +289,10 @@ export const readJSON = (json) => (dispatch, getState) => {
|
||||
dispatch({
|
||||
type: BUILDER_ERROR,
|
||||
payload: {
|
||||
steps: json.steps.map(() => { return {}; })
|
||||
}
|
||||
steps: json.steps.map(() => {
|
||||
return {};
|
||||
}),
|
||||
},
|
||||
});
|
||||
// accept only valid attributes
|
||||
var steps = json.steps.map((step, i) => {
|
||||
@@ -287,7 +300,7 @@ export const readJSON = (json) => (dispatch, getState) => {
|
||||
_id: step._id,
|
||||
type: step.type,
|
||||
headline: step.headline,
|
||||
text: step.text
|
||||
text: step.text,
|
||||
};
|
||||
if (i === 0) {
|
||||
object.hardware = step.hardware;
|
||||
@@ -296,19 +309,17 @@ export const readJSON = (json) => (dispatch, getState) => {
|
||||
if (step.xml) {
|
||||
object.xml = step.xml;
|
||||
}
|
||||
if (step.media && step.type === 'instruction') {
|
||||
if (step.media && step.type === "instruction") {
|
||||
object.media = {};
|
||||
if (step.media.picture) {
|
||||
object.media.picture = step.media.picture;
|
||||
}
|
||||
else if (step.media.youtube) {
|
||||
} else if (step.media.youtube) {
|
||||
object.media.youtube = step.media.youtube;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
});
|
||||
dispatch(tutorialTitle(json.title));
|
||||
dispatch(tutorialBadge(json.badge));
|
||||
dispatch(tutorialSteps(steps));
|
||||
dispatch(setSubmitError());
|
||||
dispatch(progress(false));
|
||||
|
||||
+50
-56
@@ -1,65 +1,59 @@
|
||||
// authentication
|
||||
export const USER_LOADING = 'USER_LOADING';
|
||||
export const USER_LOADED = 'USER_LOADED';
|
||||
export const AUTH_ERROR = 'AUTH_ERROR';
|
||||
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
|
||||
export const LOGIN_FAIL = 'LOGIN_FAIL';
|
||||
export const LOGOUT_SUCCESS = 'LOGOUT_SUCCESS';
|
||||
export const LOGOUT_FAIL = 'LOGOUT_FAIL';
|
||||
export const REFRESH_TOKEN_FAIL = 'REFRESH_TOKEN_FAIL';
|
||||
export const REFRESH_TOKEN_SUCCESS = 'REFRESH_TOKEN_SUCCESS';
|
||||
export const MYBADGES_CONNECT = 'MYBADGES_CONNECT';
|
||||
export const MYBADGES_DISCONNECT = 'MYBADGES_DISCONNECT';
|
||||
export const USER_LOADING = "USER_LOADING";
|
||||
export const USER_LOADED = "USER_LOADED";
|
||||
export const AUTH_ERROR = "AUTH_ERROR";
|
||||
export const LOGIN_SUCCESS = "LOGIN_SUCCESS";
|
||||
export const LOGIN_FAIL = "LOGIN_FAIL";
|
||||
export const LOGOUT_SUCCESS = "LOGOUT_SUCCESS";
|
||||
export const LOGOUT_FAIL = "LOGOUT_FAIL";
|
||||
export const REFRESH_TOKEN_FAIL = "REFRESH_TOKEN_FAIL";
|
||||
export const REFRESH_TOKEN_SUCCESS = "REFRESH_TOKEN_SUCCESS";
|
||||
|
||||
export const NEW_CODE = 'NEW_CODE';
|
||||
export const CHANGE_WORKSPACE = 'CHANGE_WORKSPACE';
|
||||
export const CREATE_BLOCK = 'CREATE_BLOCK';
|
||||
export const MOVE_BLOCK = 'MOVE_BLOCK';
|
||||
export const CHANGE_BLOCK = 'CHANGE_BLOCK';
|
||||
export const DELETE_BLOCK = 'DELETE_BLOCK';
|
||||
export const CLEAR_STATS = 'CLEAR_STATS';
|
||||
export const NAME = 'NAME';
|
||||
export const NEW_CODE = "NEW_CODE";
|
||||
export const CHANGE_WORKSPACE = "CHANGE_WORKSPACE";
|
||||
export const CREATE_BLOCK = "CREATE_BLOCK";
|
||||
export const MOVE_BLOCK = "MOVE_BLOCK";
|
||||
export const CHANGE_BLOCK = "CHANGE_BLOCK";
|
||||
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 GET_TUTORIALS = 'GET_TUTORIALS';
|
||||
export const GET_STATUS = 'GET_STATUS';
|
||||
export const TUTORIAL_SUCCESS = 'TUTORIAL_SUCCESS';
|
||||
export const TUTORIAL_ERROR = 'TUTORIAL_ERROR';
|
||||
export const TUTORIAL_CHANGE = 'TUTORIAL_CHANGE';
|
||||
export const TUTORIAL_XML = 'TUTORIAL_XML';
|
||||
export const TUTORIAL_ID = 'TUTORIAL_ID';
|
||||
export const TUTORIAL_STEP = 'TUTORIAL_STEP';
|
||||
export const JSON_STRING = 'JSON_STRING';
|
||||
export const TUTORIAL_PROGRESS = "TUTORIAL_PROGRESS";
|
||||
export const GET_TUTORIAL = "GET_TUTORIAL";
|
||||
export const GET_TUTORIALS = "GET_TUTORIALS";
|
||||
export const GET_STATUS = "GET_STATUS";
|
||||
export const TUTORIAL_SUCCESS = "TUTORIAL_SUCCESS";
|
||||
export const TUTORIAL_ERROR = "TUTORIAL_ERROR";
|
||||
export const TUTORIAL_CHANGE = "TUTORIAL_CHANGE";
|
||||
export const TUTORIAL_XML = "TUTORIAL_XML";
|
||||
export const TUTORIAL_ID = "TUTORIAL_ID";
|
||||
export const TUTORIAL_STEP = "TUTORIAL_STEP";
|
||||
export const JSON_STRING = "JSON_STRING";
|
||||
|
||||
export const BUILDER_CHANGE = "BUILDER_CHANGE";
|
||||
export const BUILDER_TITLE = "BUILDER_TITLE";
|
||||
export const BUILDER_ID = "BUILDER_ID";
|
||||
export const BUILDER_ADD_STEP = "BUILDER_ADD_STEP";
|
||||
export const BUILDER_DELETE_STEP = "BUILDER_DELETE_STEP";
|
||||
export const BUILDER_CHANGE_STEP = "BUILDER_CHANGE_STEP";
|
||||
export const BUILDER_CHANGE_ORDER = "BUILDER_CHANGE_ORDER";
|
||||
export const BUILDER_DELETE_PROPERTY = "BUILDER_DELETE_PROPERTY";
|
||||
export const BUILDER_ERROR = "BUILDER_ERROR";
|
||||
export const PROGRESS = "PROGRESS";
|
||||
|
||||
export const BUILDER_CHANGE = 'BUILDER_CHANGE';
|
||||
export const BUILDER_TITLE = 'BUILDER_TITLE';
|
||||
export const BUILDER_BADGE = 'BUILDER_BADGE';
|
||||
export const BUILDER_ID = 'BUILDER_ID';
|
||||
export const BUILDER_ADD_STEP = 'BUILDER_ADD_STEP';
|
||||
export const BUILDER_DELETE_STEP = 'BUILDER_DELETE_STEP';
|
||||
export const BUILDER_CHANGE_STEP = 'BUILDER_CHANGE_STEP';
|
||||
export const BUILDER_CHANGE_ORDER = 'BUILDER_CHANGE_ORDER';
|
||||
export const BUILDER_DELETE_PROPERTY = 'BUILDER_DELETE_PROPERTY';
|
||||
export const BUILDER_ERROR = 'BUILDER_ERROR';
|
||||
export const PROGRESS = 'PROGRESS';
|
||||
|
||||
|
||||
export const VISIT = 'VISIT';
|
||||
export const LANGUAGE = 'LANGUAGE';
|
||||
export const RENDERER = 'RENDERER';
|
||||
export const STATISTICS = 'STATISTICS';
|
||||
export const VISIT = "VISIT";
|
||||
export const LANGUAGE = "LANGUAGE";
|
||||
export const RENDERER = "RENDERER";
|
||||
export const STATISTICS = "STATISTICS";
|
||||
|
||||
// messages
|
||||
export const GET_ERRORS = 'GET_ERRORS';
|
||||
export const GET_SUCCESS = 'GET_SUCCESS';
|
||||
export const CLEAR_MESSAGES = 'CLEAR_MESSAGES';
|
||||
|
||||
export const GET_ERRORS = "GET_ERRORS";
|
||||
export const GET_SUCCESS = "GET_SUCCESS";
|
||||
export const CLEAR_MESSAGES = "CLEAR_MESSAGES";
|
||||
|
||||
// projects: share, gallery, project
|
||||
export const PROJECT_PROGRESS = 'PROJECT_PROGRESS';
|
||||
export const GET_PROJECT = 'GET_PROJECT';
|
||||
export const GET_PROJECTS = 'GET_PROJECTS';
|
||||
export const PROJECT_TYPE = 'PROJECT_TYPE';
|
||||
export const PROJECT_DESCRIPTION = 'PROJECT_DESCRIPTION';
|
||||
export const PROJECT_PROGRESS = "PROJECT_PROGRESS";
|
||||
export const GET_PROJECT = "GET_PROJECT";
|
||||
export const GET_PROJECTS = "GET_PROJECTS";
|
||||
export const PROJECT_TYPE = "PROJECT_TYPE";
|
||||
export const PROJECT_DESCRIPTION = "PROJECT_DESCRIPTION";
|
||||
|
||||
Reference in New Issue
Block a user