public route

This commit is contained in:
Delucse 2020-12-14 19:26:07 +01:00
parent 4588e2a69b
commit 49730f51ac
6 changed files with 89 additions and 26 deletions

View File

@ -16,11 +16,11 @@ export const loadUser = () => (dispatch) => {
type: GET_STATUS, type: GET_STATUS,
payload: res.data.user.status payload: res.data.user.status
}); });
dispatch(setLanguage(res.data.user.language));
dispatch({ dispatch({
type: USER_LOADED, type: USER_LOADED,
payload: res.data.user payload: res.data.user
}); });
dispatch(setLanguage(res.data.user.language));
}, },
error: err => { error: err => {
if(err.response){ if(err.response){
@ -74,11 +74,11 @@ export const login = ({ email, password }) => (dispatch) => {
type: LOGIN_SUCCESS, type: LOGIN_SUCCESS,
payload: res.data payload: res.data
}); });
dispatch(setLanguage(res.data.user.language));
dispatch({ dispatch({
type: GET_STATUS, type: GET_STATUS,
payload: res.data.user.status payload: res.data.user.status
}); });
dispatch(setLanguage(res.data.user.language));
dispatch(returnSuccess(res.data.message, res.status, 'LOGIN_SUCCESS')); dispatch(returnSuccess(res.data.message, res.status, 'LOGIN_SUCCESS'));
}) })
.catch(err => { .catch(err => {
@ -172,10 +172,13 @@ export const logout = () => (dispatch) => {
type: GET_STATUS, type: GET_STATUS,
payload: status payload: status
}); });
var locale = 'de_DE'; var locale = 'en_US';
if (window.localStorage.getItem('locale')) { if (window.localStorage.getItem('locale')) {
locale = window.localStorage.getItem('locale'); locale = window.localStorage.getItem('locale');
} }
else if (navigator.language === 'de-DE'){
locale = 'de_DE';
}
dispatch(setLanguage(locale)); dispatch(setLanguage(locale));
dispatch(returnSuccess(res.data.message, res.status, 'LOGOUT_SUCCESS')); dispatch(returnSuccess(res.data.message, res.status, 'LOGOUT_SUCCESS'));
clearTimeout(logoutTimerId); clearTimeout(logoutTimerId);

View File

@ -2,15 +2,15 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { onChangeWorkspace, clearStats } from '../../actions/workspaceActions'; import { onChangeWorkspace, clearStats } from '../../actions/workspaceActions';
import { De } from './msg/de';
import { En } from './msg/en';
import BlocklyComponent from './BlocklyComponent'; import BlocklyComponent from './BlocklyComponent';
import BlocklySvg from './BlocklySvg'; import BlocklySvg from './BlocklySvg';
import * as Blockly from 'blockly/core'; import * as Blockly from 'blockly/core';
import './blocks/index'; import './blocks/index';
import './generator/index'; import './generator/index';
import { initialXml } from './initialXml.js';
import { initialXml } from './initialXml.js';
class BlocklyWindow extends Component { class BlocklyWindow extends Component {
@ -18,11 +18,6 @@ class BlocklyWindow extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.simpleWorkspace = React.createRef(); this.simpleWorkspace = React.createRef();
if (this.props.language === 'de_DE') {
Blockly.setLocale(De);
} else if (this.props.language === 'en_US') {
Blockly.setLocale(En);
}
} }
componentDidMount() { componentDidMount() {
@ -50,6 +45,15 @@ class BlocklyWindow extends Component {
if (!xml) xml = initialXml; if (!xml) xml = initialXml;
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), workspace); Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), workspace);
} }
if(props.language !== this.props.language){
// change language
if (!xml) xml = initialXml;
var xmlDom = Blockly.Xml.textToDom(xml);
Blockly.Xml.clearWorkspaceAndLoadFromXml(xmlDom, workspace);
// var toolbox = workspace.getToolbox();
// console.log(toolbox);
// workspace.updateToolbox(toolbox.toolboxDef_);
}
Blockly.svgResize(workspace); Blockly.svgResize(workspace);
} }

View File

@ -0,0 +1,32 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Route } from 'react-router-dom';
class PublicRoute extends Component {
render() {
return (
!this.props.progress ?
<Route
{...this.props.exact}
render={({ location }) =>
this.props.children
}
/>
: null
);
}
}
PublicRoute.propTypes = {
progress: PropTypes.bool.isRequired
};
const mapStateToProps = state => ({
progress: state.auth.progress
});
export default connect(mapStateToProps, null)(PublicRoute);

View File

@ -5,6 +5,7 @@ import { visitPage } from '../../actions/generalActions';
import { Route, Switch, withRouter } from 'react-router-dom'; import { Route, Switch, withRouter } from 'react-router-dom';
import PublicRoute from './PublicRoute';
import PrivateRoute from './PrivateRoute'; import PrivateRoute from './PrivateRoute';
import PrivateRouteCreator from './PrivateRouteCreator'; import PrivateRouteCreator from './PrivateRouteCreator';
import IsLoggedRoute from './IsLoggedRoute'; import IsLoggedRoute from './IsLoggedRoute';
@ -34,18 +35,30 @@ class Routes extends Component {
return ( return (
<div style={{ margin: '0 22px' }}> <div style={{ margin: '0 22px' }}>
<Switch> <Switch>
<Route path="/" exact component={Home} /> <PublicRoute path="/" exact>
<Home/>
</PublicRoute>
{/* Tutorials */} {/* Tutorials */}
<Route path="/tutorial" exact component={TutorialHome} /> <PublicRoute path="/tutorial" exact>
<TutorialHome />
</PublicRoute>
<PrivateRouteCreator path="/tutorial/builder" exact> <PrivateRouteCreator path="/tutorial/builder" exact>
<Builder/> <Builder />
</PrivateRouteCreator> </PrivateRouteCreator>
<Route path="/tutorial/:tutorialId" exact component={Tutorial} /> <Route path="/tutorial/:tutorialId" exact>
<Tutorial />
</Route>
{/* Sharing */} {/* Sharing */}
<Route path="/share/:shareId" exact component={Project} /> <PublicRoute path="/share/:shareId" exact>
<Project />
</PublicRoute>
{/* Gallery-Projects */} {/* Gallery-Projects */}
<Route path="/gallery" exact component={ProjectHome} /> <PublicRoute path="/gallery" exact>
<Route path="/gallery/:galleryId" exact component={Project} /> <ProjectHome />
</PublicRoute>
<PublicRoute path="/gallery/:galleryId" exact>
<Project />
</PublicRoute>
{/* User-Projects */} {/* User-Projects */}
<PrivateRoute path="/project" exact> <PrivateRoute path="/project" exact>
<ProjectHome/> <ProjectHome/>
@ -64,12 +77,20 @@ class Routes extends Component {
<MyBadges /> <MyBadges />
</PrivateRoute> </PrivateRoute>
{/* settings */} {/* settings */}
<Route path="/settings" exact component={Settings} /> <PublicRoute path="/settings" exact>
<Settings />
</PublicRoute>
{/* privacy */} {/* privacy */}
<Route path="/impressum" exact component={Impressum} /> <PublicRoute path="/impressum" exact>
<Route path="/privacy" exact component={Privacy} /> <Impressum />
</PublicRoute>
<PublicRoute path="/privacy" exact>
<Privacy />
</PublicRoute>
{/* Not Found */} {/* Not Found */}
<Route component={NotFound} /> <PublicRoute>
<NotFound />
</PublicRoute>
</Switch> </Switch>
</div> </div>
); );

View File

@ -5,6 +5,8 @@ import { workspaceName } from '../../actions/workspaceActions';
import { clearMessages } from '../../actions/messageActions'; import { clearMessages } from '../../actions/messageActions';
import { getTutorial, resetTutorial, tutorialStep,tutorialProgress } from '../../actions/tutorialActions'; import { getTutorial, resetTutorial, tutorialStep,tutorialProgress } from '../../actions/tutorialActions';
import { withRouter } from 'react-router-dom';
import Breadcrumbs from '../Breadcrumbs'; import Breadcrumbs from '../Breadcrumbs';
import StepperHorizontal from './StepperHorizontal'; import StepperHorizontal from './StepperHorizontal';
import StepperVertical from './StepperVertical'; import StepperVertical from './StepperVertical';
@ -26,6 +28,7 @@ class Tutorial extends Component {
// retrieve tutorial only if a potential user is loaded - authentication // retrieve tutorial only if a potential user is loaded - authentication
// is finished (success or failed) // is finished (success or failed)
if(!this.props.progress){ if(!this.props.progress){
console.log(this.props);
this.props.getTutorial(this.props.match.params.tutorialId); this.props.getTutorial(this.props.match.params.tutorialId);
} }
} }
@ -120,4 +123,4 @@ const mapStateToProps = state => ({
progress: state.auth.progress progress: state.auth.progress
}); });
export default connect(mapStateToProps, { getTutorial, resetTutorial, tutorialStep, tutorialProgress, clearMessages, workspaceName })(Tutorial); export default connect(mapStateToProps, { getTutorial, resetTutorial, tutorialStep, tutorialProgress, clearMessages, workspaceName })(withRouter(Tutorial));

View File

@ -100,8 +100,8 @@ class SaveProject extends Component {
success: res => { success: res => {
var project = res.data[this.state.projectType]; var project = res.data[this.state.projectType];
this.props.history.push(`/${this.state.projectType}/${project._id}`); this.props.history.push(`/${this.state.projectType}/${project._id}`);
}) },
.catch(err => { error: err => {
this.setState({ snackbar: true, key: Date.now(), message: `${Blockly.Msg.messages_gallery_save_fail_1} ${this.state.projectType === 'gallery' ? 'Galerie-' : ''} ${Blockly.Msg.messages_gallery_save_fail_2}`, type: 'error' }); this.setState({ snackbar: true, key: Date.now(), message: `${Blockly.Msg.messages_gallery_save_fail_1} ${this.state.projectType === 'gallery' ? 'Galerie-' : ''} ${Blockly.Msg.messages_gallery_save_fail_2}`, type: 'error' });
window.scrollTo(0, 0); window.scrollTo(0, 0);
} }