diff --git a/src/containers/Countdown.js b/src/containers/Countdown.js index 71dc443..08504e1 100644 --- a/src/containers/Countdown.js +++ b/src/containers/Countdown.js @@ -32,11 +32,9 @@ class Countdown extends Component { } componentDidMount() { - const { result, isGamePaused } = this.props; - if ( - (result.length === 0 && this.timer === 0) || - (result.length === 0 && isGamePaused) - ) { + const { result } = this.props; + + if (result.length === 0) { this.startTimer(); } } diff --git a/src/containers/PlayScreen/index.js b/src/containers/PlayScreen/index.js index b1bf2bb..4c115f4 100644 --- a/src/containers/PlayScreen/index.js +++ b/src/containers/PlayScreen/index.js @@ -30,20 +30,18 @@ class PlayScreen extends Component { constructor(props) { super(props); - const { initNewGame, clearGame, push, history } = this.props; + const { push, history } = this.props; if (history.action === "POP") { push("/"); - } else { - // clear all jarvig state (set defaults) - clearGame(); - // init new jarvig; - initNewGame(); } } componentDidMount() { - const { resetSidebars } = this.props; + const { initNewGame, resetSidebars } = this.props; + // init new jarvig; + initNewGame(); + resetSidebars(); } @@ -79,6 +77,15 @@ class PlayScreen extends Component { } } + componentWillUnmount() { + const { history, clearGame } = this.props; + + if (history.location.pathname !== "/result") { + // clear all jarvig state (set defaults) + clearGame(); + } + } + render() { const { game, diff --git a/src/containers/ResultScreen/index.js b/src/containers/ResultScreen/index.js index ba7193d..914af84 100644 --- a/src/containers/ResultScreen/index.js +++ b/src/containers/ResultScreen/index.js @@ -1,3 +1,4 @@ +import { clearGame } from "actions/GameActions"; import { Card, FlexSection } from "components"; import PropTypes from "prop-types"; import React, { Component } from "react"; @@ -22,6 +23,12 @@ class ResultScreen extends Component { } } + componentWillUnmount() { + const { clearGame } = this.props; + // clear all jarvig state (set defaults) + clearGame(); + } + render() { const { numberOfQuestions, gameResult, difficulty } = this.props; @@ -94,6 +101,7 @@ ResultScreen.propTypes = { history: PropTypes.shape({ action: PropTypes.string }).isRequired, + clearGame: PropTypes.func.isRequired, push: PropTypes.func.isRequired }; @@ -106,6 +114,7 @@ const mapStateToProps = state => ({ const mapDispatchToProps = dispatch => bindActionCreators( { + clearGame, push }, dispatch