load tutorial only once

This commit is contained in:
Delucse
2020-11-27 13:31:03 +01:00
parent 28720edeea
commit 2d29b8d7bd
4 changed files with 18 additions and 20 deletions
+4 -2
View File
@@ -18,13 +18,14 @@ export const getTutorial = (id) => (dispatch, getState) => {
type: GET_TUTORIAL,
payload: tutorial
});
dispatch(returnSuccess(res.data.message, res.status));
});
})
.catch(err => {
dispatch({type: TUTORIAL_PROGRESS});
if(err.response){
dispatch(returnErrors(err.response.data.message, err.response.status, 'GET_TUTORIAL_FAIL'));
}
dispatch({type: TUTORIAL_PROGRESS});
});
};
@@ -43,13 +44,14 @@ export const getTutorials = () => (dispatch, getState) => {
payload: tutorials
});
dispatch({type: TUTORIAL_PROGRESS});
dispatch(returnSuccess(res.data.message, res.status));
});
})
.catch(err => {
dispatch({type: TUTORIAL_PROGRESS});
if(err.response){
dispatch(returnErrors(err.response.data.message, err.response.status, 'GET_TUTORIALS_FAIL'));
}
dispatch({type: TUTORIAL_PROGRESS});
});
};
+3 -6
View File
@@ -22,17 +22,14 @@ class Tutorial extends Component {
componentDidMount() {
this.props.getTutorial(this.props.match.params.tutorialId);
// this.props.tutorialId(Number(this.props.match.params.tutorialId));
}
componentDidUpdate(props, state) {
if (props.tutorial && props.tutorial.id && !props.isLoading && Number(props.tutorial.id) !== Number(this.props.match.params.tutorialId)) {
if(this.props.tutorial && !this.props.isLoading && this.props.tutorial.id != this.props.match.params.tutorialId) {
this.props.getTutorial(this.props.match.params.tutorialId);
// this.props.tutorialId(Number(this.props.match.params.tutorialId));
}
if(this.props.message.id === 'GET_TUTORIAL_FAIL'){
alert(this.props.message.msg);
this.props.clearMessages();
}
}
@@ -45,11 +42,11 @@ class Tutorial extends Component {
}
render() {
console.log(this.props.tutorial);
return (
<div>
{this.props.isLoading ? null :
!this.props.tutorial ? <NotFound button={{ title: 'Zurück zur Tutorials-Übersicht', link: '/tutorial' }} />
!this.props.tutorial ?
this.props.message.id === 'GET_TUTORIAL_FAIL' ? <NotFound button={{ title: 'Zurück zur Tutorials-Übersicht', link: '/tutorial' }} /> : null
: (() => {
var tutorial = this.props.tutorial;
var steps = this.props.tutorial.steps;
-1
View File
@@ -58,7 +58,6 @@ class TutorialHome extends Component {
componentDidUpdate(props, state) {
if(this.props.message.id === 'GET_TUTORIALS_FAIL'){
alert(this.props.message.msg);
this.props.clearMessages();
}
}
+11 -11
View File
@@ -1,11 +1,11 @@
let tutorials = [
require('./tutorial/ErsteSchritte.json'),
require('./tutorial/Schleifen.json'),
require('./tutorial/Wenn-DannBedingungen.json'),
require('./tutorial/VerwendungVonVariablen.json'),
require('./tutorial/SendenVonMesswertenUeberLoRa.json'),
require('./tutorial/AnzeigeVonMesswertenAufDemDisplay.json'),
require('./tutorial/MesswerteAnDieOpenSenseMapSenden.json')
]
module.exports = tutorials;
// let tutorials = [
// require('./tutorial/ErsteSchritte.json'),
// require('./tutorial/Schleifen.json'),
// require('./tutorial/Wenn-DannBedingungen.json'),
// require('./tutorial/VerwendungVonVariablen.json'),
// require('./tutorial/SendenVonMesswertenUeberLoRa.json'),
// require('./tutorial/AnzeigeVonMesswertenAufDemDisplay.json'),
// require('./tutorial/MesswerteAnDieOpenSenseMapSenden.json')
// ]
//
// module.exports = tutorials;