public route
This commit is contained in:
parent
4588e2a69b
commit
49730f51ac
@ -16,11 +16,11 @@ export const loadUser = () => (dispatch) => {
|
||||
type: GET_STATUS,
|
||||
payload: res.data.user.status
|
||||
});
|
||||
dispatch(setLanguage(res.data.user.language));
|
||||
dispatch({
|
||||
type: USER_LOADED,
|
||||
payload: res.data.user
|
||||
});
|
||||
dispatch(setLanguage(res.data.user.language));
|
||||
},
|
||||
error: err => {
|
||||
if(err.response){
|
||||
@ -74,11 +74,11 @@ export const login = ({ email, password }) => (dispatch) => {
|
||||
type: LOGIN_SUCCESS,
|
||||
payload: res.data
|
||||
});
|
||||
dispatch(setLanguage(res.data.user.language));
|
||||
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 => {
|
||||
@ -172,10 +172,13 @@ export const logout = () => (dispatch) => {
|
||||
type: GET_STATUS,
|
||||
payload: status
|
||||
});
|
||||
var 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'));
|
||||
clearTimeout(logoutTimerId);
|
||||
|
@ -2,15 +2,15 @@ import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { connect } from 'react-redux';
|
||||
import { onChangeWorkspace, clearStats } from '../../actions/workspaceActions';
|
||||
import { De } from './msg/de';
|
||||
import { En } from './msg/en';
|
||||
|
||||
import BlocklyComponent from './BlocklyComponent';
|
||||
import BlocklySvg from './BlocklySvg';
|
||||
|
||||
import * as Blockly from 'blockly/core';
|
||||
import './blocks/index';
|
||||
import './generator/index';
|
||||
import { initialXml } from './initialXml.js';
|
||||
|
||||
import { initialXml } from './initialXml.js';
|
||||
|
||||
|
||||
class BlocklyWindow extends Component {
|
||||
@ -18,11 +18,6 @@ class BlocklyWindow extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.simpleWorkspace = React.createRef();
|
||||
if (this.props.language === 'de_DE') {
|
||||
Blockly.setLocale(De);
|
||||
} else if (this.props.language === 'en_US') {
|
||||
Blockly.setLocale(En);
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@ -50,6 +45,15 @@ class BlocklyWindow extends Component {
|
||||
if (!xml) xml = initialXml;
|
||||
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);
|
||||
}
|
||||
|
||||
|
32
src/components/Route/PublicRoute.js
Normal file
32
src/components/Route/PublicRoute.js
Normal 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);
|
@ -5,6 +5,7 @@ import { visitPage } from '../../actions/generalActions';
|
||||
|
||||
import { Route, Switch, withRouter } from 'react-router-dom';
|
||||
|
||||
import PublicRoute from './PublicRoute';
|
||||
import PrivateRoute from './PrivateRoute';
|
||||
import PrivateRouteCreator from './PrivateRouteCreator';
|
||||
import IsLoggedRoute from './IsLoggedRoute';
|
||||
@ -34,18 +35,30 @@ class Routes extends Component {
|
||||
return (
|
||||
<div style={{ margin: '0 22px' }}>
|
||||
<Switch>
|
||||
<Route path="/" exact component={Home} />
|
||||
<PublicRoute path="/" exact>
|
||||
<Home/>
|
||||
</PublicRoute>
|
||||
{/* Tutorials */}
|
||||
<Route path="/tutorial" exact component={TutorialHome} />
|
||||
<PublicRoute path="/tutorial" exact>
|
||||
<TutorialHome />
|
||||
</PublicRoute>
|
||||
<PrivateRouteCreator path="/tutorial/builder" exact>
|
||||
<Builder/>
|
||||
<Builder />
|
||||
</PrivateRouteCreator>
|
||||
<Route path="/tutorial/:tutorialId" exact component={Tutorial} />
|
||||
<Route path="/tutorial/:tutorialId" exact>
|
||||
<Tutorial />
|
||||
</Route>
|
||||
{/* Sharing */}
|
||||
<Route path="/share/:shareId" exact component={Project} />
|
||||
<PublicRoute path="/share/:shareId" exact>
|
||||
<Project />
|
||||
</PublicRoute>
|
||||
{/* Gallery-Projects */}
|
||||
<Route path="/gallery" exact component={ProjectHome} />
|
||||
<Route path="/gallery/:galleryId" exact component={Project} />
|
||||
<PublicRoute path="/gallery" exact>
|
||||
<ProjectHome />
|
||||
</PublicRoute>
|
||||
<PublicRoute path="/gallery/:galleryId" exact>
|
||||
<Project />
|
||||
</PublicRoute>
|
||||
{/* User-Projects */}
|
||||
<PrivateRoute path="/project" exact>
|
||||
<ProjectHome/>
|
||||
@ -64,12 +77,20 @@ class Routes extends Component {
|
||||
<MyBadges />
|
||||
</PrivateRoute>
|
||||
{/* settings */}
|
||||
<Route path="/settings" exact component={Settings} />
|
||||
<PublicRoute path="/settings" exact>
|
||||
<Settings />
|
||||
</PublicRoute>
|
||||
{/* privacy */}
|
||||
<Route path="/impressum" exact component={Impressum} />
|
||||
<Route path="/privacy" exact component={Privacy} />
|
||||
<PublicRoute path="/impressum" exact>
|
||||
<Impressum />
|
||||
</PublicRoute>
|
||||
<PublicRoute path="/privacy" exact>
|
||||
<Privacy />
|
||||
</PublicRoute>
|
||||
{/* Not Found */}
|
||||
<Route component={NotFound} />
|
||||
<PublicRoute>
|
||||
<NotFound />
|
||||
</PublicRoute>
|
||||
</Switch>
|
||||
</div>
|
||||
);
|
||||
|
@ -5,6 +5,8 @@ import { workspaceName } from '../../actions/workspaceActions';
|
||||
import { clearMessages } from '../../actions/messageActions';
|
||||
import { getTutorial, resetTutorial, tutorialStep,tutorialProgress } from '../../actions/tutorialActions';
|
||||
|
||||
import { withRouter } from 'react-router-dom';
|
||||
|
||||
import Breadcrumbs from '../Breadcrumbs';
|
||||
import StepperHorizontal from './StepperHorizontal';
|
||||
import StepperVertical from './StepperVertical';
|
||||
@ -26,6 +28,7 @@ class Tutorial extends Component {
|
||||
// retrieve tutorial only if a potential user is loaded - authentication
|
||||
// is finished (success or failed)
|
||||
if(!this.props.progress){
|
||||
console.log(this.props);
|
||||
this.props.getTutorial(this.props.match.params.tutorialId);
|
||||
}
|
||||
}
|
||||
@ -120,4 +123,4 @@ const mapStateToProps = state => ({
|
||||
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));
|
||||
|
@ -100,10 +100,10 @@ class SaveProject extends Component {
|
||||
success: res => {
|
||||
var project = res.data[this.state.projectType];
|
||||
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' });
|
||||
window.scrollTo(0, 0);
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
};
|
||||
axios.post(`${process.env.REACT_APP_BLOCKLY_API}/${this.state.projectType}`, body, config)
|
||||
|
Loading…
x
Reference in New Issue
Block a user