Skip to content

Commit

Permalink
fix(countdown): make timer countdown after one game - fixes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinedoghri committed May 26, 2018
1 parent 15f0c1b commit dfda547
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/containers/Countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
21 changes: 14 additions & 7 deletions src/containers/PlayScreen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/containers/ResultScreen/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { clearGame } from "actions/GameActions";
import { Card, FlexSection } from "components";
import PropTypes from "prop-types";
import React, { Component } from "react";
Expand All @@ -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;

Expand Down Expand Up @@ -94,6 +101,7 @@ ResultScreen.propTypes = {
history: PropTypes.shape({
action: PropTypes.string
}).isRequired,
clearGame: PropTypes.func.isRequired,
push: PropTypes.func.isRequired
};

Expand All @@ -106,6 +114,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
clearGame,
push
},
dispatch
Expand Down

0 comments on commit dfda547

Please sign in to comment.