Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
amitjimiwal committed Aug 9, 2023
1 parent e776d1e commit 18275ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/components/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import ProgressBar from "../ProgressBar";
import Timer from "../Timer";
import { AppDispatch, RootState } from "../../redux/store";
import { useCallback, useEffect} from "react";
import { increaseRound, setMode } from "../../redux/slice/timerslice,";
import { increaseRound, resetrounds, setMode } from "../../redux/slice/timerslice,";
import { LONG_BREAK, POMODORO, SHORT_BREAK } from "../../constant";
import useCountdown from "../../hooks/useCountdown";
import { updateTitle } from "../../utils/utilityfunction";

const Main = () => {
const dispatch = useDispatch<AppDispatch>();
console.log("main render")
const { modes, mode ,round,longBreakInterval} = useSelector((state: RootState) => state.timer);
const {ticking, start, stop, reset, timeLeft, progress} =useCountdown({
onStart:()=>{
Expand All @@ -32,9 +31,10 @@ const Main = () => {
switch (mode) {
case LONG_BREAK:
jumpTo(POMODORO);
dispatch(resetrounds())
break;
case SHORT_BREAK:
if(round==longBreakInterval){
if(round>=longBreakInterval){
jumpTo(LONG_BREAK);
break;
}
Expand All @@ -45,7 +45,7 @@ const Main = () => {
dispatch(increaseRound());
break;
}
}, [dispatch, jumpTo, mode,start]);
}, [dispatch, jumpTo, mode,longBreakInterval,round]);
useEffect(() => {
updateTitle(timeLeft,mode)
}, [mode,timeLeft]);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Timer = ({ time, next,start,stop ,ticking}: Props) => {
</div>
<div className="text-8xl text-center my-10 text-white font-bold tracking-wider">
{formattimeInMinutes(time)}
{/* {time!==0 ? formattimeInMinutes(time): `${modes[mode].time} : 00`} */}
{/* {time!==0 ? formattimeInMinutes(time): `${modes[mode].time >10 ? modes[mode].time : "0"+modes[mode].time} : 00`} */}
</div>
<div className="flexproperty gap-4">
<TimerButton
Expand Down
11 changes: 7 additions & 4 deletions src/redux/slice/timerslice,.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { POMODORO, SHORT_BREAK, LONG_BREAK } from '../../constant'
import { reduxState } from '../../interface/appinterface'
const initialState: reduxState = {
mode: POMODORO,
round: 1,
round: 0,
longBreakInterval: 1,
modes: {
[POMODORO]: {
Expand All @@ -15,13 +15,13 @@ const initialState: reduxState = {
[SHORT_BREAK]: {
id: SHORT_BREAK,
label: "Short Break",
time: 1,
time: 2,
color:'#397097'
},
[LONG_BREAK]: {
id: LONG_BREAK,
label: "Long Break",
time: 1,
time: 3,
color:'#518A58'
},
},
Expand All @@ -47,9 +47,12 @@ const timerSlice = createSlice({
},
opensettings:(state)=>{
state.settingsopen= !state.settingsopen
},
resetrounds:(state)=>{
state.round=0
}
}
})

export default timerSlice.reducer;
export const { setLongBreakInterval, setMode, updateModeTime, increaseRound ,opensettings} = timerSlice.actions
export const { setLongBreakInterval, setMode, updateModeTime, increaseRound ,opensettings,resetrounds} = timerSlice.actions

0 comments on commit 18275ec

Please sign in to comment.