Skip to content

Commit

Permalink
Restarting the counter
Browse files Browse the repository at this point in the history
  • Loading branch information
serranoarevalo committed Oct 28, 2017
1 parent 90b392b commit 2065b1e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 35 deletions.
1 change: 0 additions & 1 deletion components/Timer/index.js
Expand Up @@ -15,7 +15,6 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) {
return {
startTimer: bindActionCreators(tomatoActions.startTimer, dispatch),
pauseTimer: bindActionCreators(tomatoActions.pauseTimer, dispatch),
restartTimer: bindActionCreators(tomatoActions.restartTimer, dispatch),
addSecond: bindActionCreators(tomatoActions.addSecond, dispatch)
};
Expand Down
6 changes: 3 additions & 3 deletions components/Timer/presenter.js
Expand Up @@ -9,7 +9,6 @@ class Timer extends Component {
elapsedTime,
timerDuration,
startTimer,
pauseTimer,
restartTimer,
addSecond
} = this.props;
Expand All @@ -20,9 +19,10 @@ class Timer extends Component {
<Text style={styles.time}>25:00</Text>
</View>
<View style={styles.lower}>
{isPlaying && <Button iconName={"ios-pause"} />}
{!isPlaying && <Button iconName={"ios-play"} onPress={startTimer} />}
{isPlaying && <Button iconName={"ios-square"} />}
{isPlaying && (
<Button iconName={"ios-square"} onPress={restartTimer} />
)}
</View>
</View>
);
Expand Down
35 changes: 4 additions & 31 deletions reducer.js
Expand Up @@ -3,9 +3,7 @@
// Actions

const START_TIMER = "START_TIMER";
const PAUSE_TIMER = "PAUSE_TIMER";
const RESUME_TIMER = "RESUME_TIMER";
const STOP_TIMER = "STOP_TIMER";
const RESTART_TIMER = "RESTART_TIMER";
const ADD_SECOND = "ADD_SECOND";

// Action Creators
Expand All @@ -16,12 +14,6 @@ function startTimer() {
};
}

function pauseTimer() {
return {
type: PAUSE_TIMER
};
}

function restartTimer() {
return {
type: RESTART_TIMER
Expand All @@ -48,12 +40,8 @@ function reducer(state = initialState, action) {
switch (action.type) {
case START_TIMER:
return applyStartTimer(state, action);
case PAUSE_TIMER:
return applyPauseTimer(state, action);
case RESUME_TIMER:
return applyResumeTimer(state, action);
case STOP_TIMER:
return applyStopTimer(state, action);
case RESTART_TIMER:
return applyRestartTimer(state, action);
case ADD_SECOND:
return applyAddSecond(state, action);
default:
Expand All @@ -71,21 +59,7 @@ function applyStartTimer(state, action) {
};
}

function applyPauseTimer(state, action) {
return {
...state,
isPlaying: false
};
}

function applyResumeTimer(state, action) {
return {
...state,
isPlaying: true
};
}

function applyStopTimer(state, action) {
function applyRestartTimer(state, action) {
return {
...state,
isPlaying: false,
Expand All @@ -112,7 +86,6 @@ function applyAddSecond(state, action) {

const actionCreators = {
startTimer,
pauseTimer,
restartTimer,
addSecond
};
Expand Down

0 comments on commit 2065b1e

Please sign in to comment.