Merge branch 'add-translations' into backend-connection

This commit is contained in:
Delucse
2020-12-14 15:23:01 +01:00
45 changed files with 1033 additions and 548 deletions
+9 -2
View File
@@ -1,8 +1,8 @@
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 axios from 'axios';
import { returnErrors, returnSuccess } from './messageActions'
import { returnErrors, returnSuccess } from './messageActions';
import { setLanguage } from './generalActions';
// Check token & load user
export const loadUser = () => (dispatch) => {
@@ -20,6 +20,7 @@ export const loadUser = () => (dispatch) => {
type: USER_LOADED,
payload: res.data.user
});
dispatch(setLanguage(res.data.user.language));
},
error: err => {
if(err.response){
@@ -77,6 +78,7 @@ export const login = ({ email, password }) => (dispatch) => {
type: GET_STATUS,
payload: res.data.user.status
});
dispatch(setLanguage(res.data.user.language));
dispatch(returnSuccess(res.data.message, res.status, 'LOGIN_SUCCESS'));
})
.catch(err => {
@@ -170,6 +172,11 @@ export const logout = () => (dispatch) => {
type: GET_STATUS,
payload: status
});
var locale = 'de_DE';
if (window.localStorage.getItem('locale')) {
locale = window.localStorage.getItem('locale');
}
dispatch(setLanguage(locale));
dispatch(returnSuccess(res.data.message, res.status, 'LOGOUT_SUCCESS'));
clearTimeout(logoutTimerId);
},
+25 -1
View File
@@ -1,4 +1,4 @@
import { VISIT } from './types';
import { VISIT, LANGUAGE, RENDERER, STATISTICS } from './types';
export const visitPage = () => (dispatch) => {
@@ -6,3 +6,27 @@ export const visitPage = () => (dispatch) => {
type: VISIT
});
};
export const setLanguage = (language) => (dispatch, getState) => {
if(!getState().auth.isAuthenticated){
window.localStorage.setItem('locale', language);
}
dispatch({
type: LANGUAGE,
payload: language
});
};
export const setRenderer = (renderer) => (dispatch) => {
dispatch({
type: RENDERER,
payload: renderer
});
};
export const setStatistics = (showStatistics) => (dispatch) => {
dispatch({
type: STATISTICS,
payload: showStatistics
});
};
+12 -13
View File
@@ -1,7 +1,6 @@
import { PROJECT_PROGRESS, GET_PROJECT, GET_PROJECTS, PROJECT_TYPE, PROJECT_DESCRIPTION } from './types';
import axios from 'axios';
import { workspaceName } from './workspaceActions';
import { returnErrors, returnSuccess } from './messageActions';
export const setType = (type) => (dispatch) => {
@@ -19,13 +18,13 @@ export const setDescription = (description) => (dispatch) => {
};
export const getProject = (type, id) => (dispatch) => {
dispatch({type: PROJECT_PROGRESS});
dispatch({ type: PROJECT_PROGRESS });
dispatch(setType(type));
const config = {
success: res => {
var data = type === 'share' ? 'content' : type;
var project = res.data[data];
if(project){
if (project) {
dispatch({
type: GET_PROJECT,
payload: project
@@ -34,11 +33,11 @@ export const getProject = (type, id) => (dispatch) => {
type: PROJECT_DESCRIPTION,
payload: project.description
});
dispatch({type: PROJECT_PROGRESS});
dispatch({ type: PROJECT_PROGRESS });
dispatch(returnSuccess(res.data.message, res.status, 'GET_PROJECT_SUCCESS'));
}
else{
dispatch({type: PROJECT_PROGRESS});
else {
dispatch({ type: PROJECT_PROGRESS });
dispatch(returnErrors(res.data.message, res.status, 'PROJECT_EMPTY'));
}
},
@@ -68,7 +67,7 @@ export const getProjects = (type) => (dispatch) => {
type: GET_PROJECTS,
payload: projects
});
dispatch({type: PROJECT_PROGRESS});
dispatch({ type: PROJECT_PROGRESS });
dispatch(returnSuccess(res.data.message, res.status));
},
error: err => {
@@ -94,7 +93,7 @@ export const updateProject = (type, id) => (dispatch, getState) => {
title: workspace.name
};
var project = getState().project;
if(type==='gallery'){
if (type === 'gallery') {
body.description = project.description;
}
const config = {
@@ -107,7 +106,7 @@ export const updateProject = (type, id) => (dispatch, getState) => {
type: GET_PROJECTS,
payload: projects
});
if(type === 'project'){
if (type === 'project') {
dispatch(returnSuccess(res.data.message, res.status, 'PROJECT_UPDATE_SUCCESS'));
} else {
dispatch(returnSuccess(res.data.message, res.status, 'GALLERY_UPDATE_SUCCESS'));
@@ -143,7 +142,7 @@ export const deleteProject = (type, id) => (dispatch, getState) => {
type: GET_PROJECTS,
payload: projects
});
if(type === 'project'){
if (type === 'project') {
dispatch(returnSuccess(res.data.message, res.status, 'PROJECT_DELETE_SUCCESS'));
} else {
dispatch(returnSuccess(res.data.message, res.status, 'GALLERY_DELETE_SUCCESS'));
@@ -169,7 +168,7 @@ export const shareProject = (title, type, id) => (dispatch, getState) => {
var body = {
title: title
};
if(type === 'project'){
if (type === 'project') {
body.projectId = id;
} else {
body.xml = getState().workspace.code.xml;
@@ -177,7 +176,7 @@ export const shareProject = (title, type, id) => (dispatch, getState) => {
axios.post(`${process.env.REACT_APP_BLOCKLY_API}/share`, body)
.then(res => {
var shareContent = res.data.content;
if(body.projectId){
if (body.projectId) {
var projects = getState().project.projects;
var index = projects.findIndex(res => res._id === id);
projects[index].shared = shareContent.expiresAt;
@@ -189,7 +188,7 @@ export const shareProject = (title, type, id) => (dispatch, getState) => {
dispatch(returnSuccess(res.data.message, shareContent._id, 'SHARE_SUCCESS'));
})
.catch(err => {
if(err.response){
if (err.response) {
dispatch(returnErrors(err.response.data.message, err.response.status, 'SHARE_FAIL'));
}
});
+9 -14
View File
@@ -1,4 +1,4 @@
import { MYBADGES_DISCONNECT, TUTORIAL_PROGRESS, GET_TUTORIAL, GET_TUTORIALS, TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE, TUTORIAL_XML, TUTORIAL_ID, TUTORIAL_STEP } from './types';
import { MYBADGES_DISCONNECT, 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';
@@ -12,15 +12,11 @@ export const getTutorial = (id) => (dispatch, getState) => {
axios.get(`${process.env.REACT_APP_BLOCKLY_API}/tutorial/${id}`)
.then(res => {
var tutorial = res.data.tutorial;
console.log('status', getState().tutorial.status);
existingTutorial(tutorial, getState().tutorial.status).then(status => {
console.log('progress',getState().auth.progress);
console.log('status');
dispatch({
type: TUTORIAL_SUCCESS,
payload: status
});
console.log('eins');
dispatch(updateStatus(status));
dispatch({
type: GET_TUTORIAL,
@@ -31,10 +27,10 @@ export const getTutorial = (id) => (dispatch, getState) => {
});
})
.catch(err => {
if(err.response){
if (err.response) {
dispatch(returnErrors(err.response.data.message, err.response.status, 'GET_TUTORIAL_FAIL'));
}
dispatch({type: TUTORIAL_PROGRESS});
dispatch({ type: TUTORIAL_PROGRESS });
});
};
@@ -54,15 +50,15 @@ export const getTutorials = () => (dispatch, getState) => {
type: GET_TUTORIALS,
payload: tutorials
});
dispatch({type: TUTORIAL_PROGRESS});
dispatch({ type: TUTORIAL_PROGRESS });
dispatch(returnSuccess(res.data.message, res.status));
});
})
.catch(err => {
if(err.response){
if (err.response) {
dispatch(returnErrors(err.response.data.message, err.response.status, 'GET_TUTORIALS_FAIL'));
}
dispatch({type: TUTORIAL_PROGRESS});
dispatch({ type: TUTORIAL_PROGRESS });
});
};
@@ -174,7 +170,7 @@ export const tutorialCheck = (status, step) => (dispatch, getState) => {
console.log('drei');
dispatch(updateStatus(tutorialsStatus));
dispatch(tutorialChange());
dispatch(returnSuccess('','','TUTORIAL_CHECK_SUCCESS'));
dispatch(returnSuccess('', '', 'TUTORIAL_CHECK_SUCCESS'));
};
export const storeTutorialXml = (code) => (dispatch, getState) => {
@@ -208,9 +204,9 @@ export const tutorialStep = (step) => (dispatch) => {
};
const existingTutorials = (tutorials, status) => new Promise(function(resolve, reject){
const existingTutorials = (tutorials, status) => new Promise(function (resolve, reject) {
var newstatus;
new Promise(function(resolve, reject){
new Promise(function (resolve, reject) {
var existingTutorialIds = tutorials.map((tutorial, i) => {
existingTutorial(tutorial, status).then(status => {
newstatus = status;
@@ -228,7 +224,6 @@ const existingTutorials = (tutorials, status) => new Promise(function(resolve, r
});
const existingTutorial = (tutorial, status) => new Promise(function(resolve, reject){
console.log('st',status);
var tutorialsId = tutorial._id;
var statusIndex = status.findIndex(status => status._id === tutorialsId);
if (statusIndex > -1) {
+3
View File
@@ -47,6 +47,9 @@ export const PROGRESS = 'PROGRESS';
export const VISIT = 'VISIT';
export const LANGUAGE = 'LANGUAGE';
export const RENDERER = 'RENDERER';
export const STATISTICS = 'STATISTICS';
// messages
export const GET_ERRORS = 'GET_ERRORS';