Added logic for the stop button

This commit is contained in:
2021-09-24 21:48:37 -03:00
parent e2618e1c31
commit df90e04791
4 changed files with 48 additions and 9 deletions

BIN
public/sounds/bell x3.mp3 Normal file

Binary file not shown.

BIN
public/sounds/bell-x2.mp3 Normal file

Binary file not shown.

View File

@@ -1,5 +1,5 @@
import React, {useState} from 'react' import React, {useState} from 'react'
import MainPomodoroTimer from './MainPomodoroTimer' import MainPomodoroTimer, {setTim} from './MainPomodoroTimer'
import PomodoroCounter from './PomodoroCounter' import PomodoroCounter from './PomodoroCounter'
import StyleSelector from './StyleSelector' import StyleSelector from './StyleSelector'

View File

@@ -10,6 +10,8 @@ const MainPomodoroTimer = (props) => {
const [restCounter, setRestCounter] = useState(0) const [restCounter, setRestCounter] = useState(0)
const [timerActivity, setTimerActivity] = useState(false)
const setTimeStyle = () => { const setTimeStyle = () => {
if (props.style === 'Can I play, Daddy?') { if (props.style === 'Can I play, Daddy?') {
@@ -36,7 +38,7 @@ const MainPomodoroTimer = (props) => {
if (props.style === 'Regular'){ if (props.style === 'Regular'){
const minutes = 0 const minutes = 0
const seconds = 2 const seconds = 5
setMinutes(minutes) setMinutes(minutes)
setSeconds(seconds) setSeconds(seconds)
@@ -45,11 +47,11 @@ const MainPomodoroTimer = (props) => {
{ {
normal: { normal: {
minutes: 0, minutes: 0,
seconds: 1 seconds: 15
}, },
extended: { extended: {
minutes: 15, minutes: 0,
seconds: 1 seconds: 20
} }
} }
) )
@@ -138,7 +140,7 @@ const MainPomodoroTimer = (props) => {
} }
} }
const setPomodoroCounter = (counter = false) => { const setPomodoroCounter = (counter = false, mode) => {
if (!counter) { if (!counter) {
console.error('NOT PARAMETER PASSED') console.error('NOT PARAMETER PASSED')
} }
@@ -167,10 +169,12 @@ const MainPomodoroTimer = (props) => {
let idTimeOut let idTimeOut
if (props.timerOn) { if (props.timerOn) {
setTimerActivity(true)
if(!weAreInBreakTime) { if(!weAreInBreakTime) {
if (minutes === 0 && seconds === 0) { if (minutes === 0 && seconds === 0) {
setTimerActivity(false)
if (restCounter !== 3){ if (restCounter !== 3){
@@ -190,6 +194,7 @@ const MainPomodoroTimer = (props) => {
setTimeout( () => { setTimeout( () => {
setPomodoroCounter('Pomodoros') setPomodoroCounter('Pomodoros')
setRestCounter((restCounter + 1))
setBreak(0, 1) setBreak(0, 1)
setWeAreInBreakTime(true) setWeAreInBreakTime(true)
@@ -207,13 +212,14 @@ const MainPomodoroTimer = (props) => {
} }
if(weAreInBreakTime) { if(weAreInBreakTime) {
if (minutes === 0 && seconds === 0) { if (minutes === 0 && seconds === 0) {
setTimerActivity(false)
setTimeout( () => { setTimeout( () => {
if (restCounter === 4) { if (restCounter === 4) {
setPomodoroCounter('Long rest') setPomodoroCounter('Long Rest')
setRestCounter(0) setRestCounter(0)
} else { } else {
@@ -222,6 +228,7 @@ const MainPomodoroTimer = (props) => {
setWeAreInBreakTime(false) setWeAreInBreakTime(false)
props.setTimerOn(false) props.setTimerOn(false)
setTimeStyle() setTimeStyle()
}, 1000) }, 1000)
@@ -230,14 +237,46 @@ const MainPomodoroTimer = (props) => {
if (minutes >= 0 || seconds > 0) { if (minutes >= 0 || seconds > 0) {
idTimeOut = startTimer() idTimeOut = startTimer()
} }
} }
return () => { return () => {
clearInterval(idTimeOut) clearInterval(idTimeOut)
} }
} else if (props.timerOn === false && timerActivity === true){
if (!weAreInBreakTime) {
setPomodoroCounter('Pomodoros')
setRestCounter((restCounter + 1))
}
if (weAreInBreakTime) {
console.log(restCounter)
if (restCounter === 4) {
console.log('AA3')
setPomodoroCounter('Long Rest')
setRestCounter(0)
} else {
console.log('AA2')
setPomodoroCounter('Rest')
}
setWeAreInBreakTime(false)
}
setTimeStyle()
setTimerActivity(false)
} }
}, [props.timerOn, minutes, seconds, breakTime, setMinutes, setSeconds] }, [props.timerOn, minutes, seconds, breakTime, setMinutes, setSeconds]
) )