From 2d29b8d7bd64e2e0f2b6b2861b48fc3501ceb9e1 Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Fri, 27 Nov 2020 13:31:03 +0100 Subject: [PATCH] load tutorial only once --- src/actions/tutorialActions.js | 6 ++++-- src/components/Tutorial/Tutorial.js | 9 +++------ src/components/Tutorial/TutorialHome.js | 1 - src/data/tutorials.js | 22 +++++++++++----------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/actions/tutorialActions.js b/src/actions/tutorialActions.js index 58e67d4..0358d5f 100644 --- a/src/actions/tutorialActions.js +++ b/src/actions/tutorialActions.js @@ -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}); }); }; diff --git a/src/components/Tutorial/Tutorial.js b/src/components/Tutorial/Tutorial.js index 784d2a4..e524f6d 100644 --- a/src/components/Tutorial/Tutorial.js +++ b/src/components/Tutorial/Tutorial.js @@ -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 (