diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index d8e2a94c..992ef47c 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -229,6 +229,12 @@ const App = () => { } /> +} +/> + + { - const [showPopUp, setShowPopUp]= useState(false); - const [timeLeft, setTimeLeft] = useState(25*60); - const [isRunning, setIsRunning]= useState(false); - const finRef = useRef(new Audio(finSound)); +const Pomodoro = () => { + const [showSettings, setShowSettings] = useState(false); +const [showPopUp, setShowPopUp] = useState(false); + +const [focusTime, setFocusTime] = useState(25); +const [shortBreak, setShortBreak] = useState(5); +const [longBreak, setLongBreak] = useState(15); + +const [timeLeft, setTimeLeft] = useState(25 * 60); +const [isRunning, setIsRunning] = useState(false); +const [mode, setMode] = useState("focus"); +const getCurrentTime = () => { + if (mode === "focus") return focusTime; + if (mode === "short") return shortBreak; + return longBreak; +}; +const finRef = useRef(new Audio(finSound)); const stopCompletionSound = () => { if (finRef.current) { @@ -23,32 +35,35 @@ const Pomodoro = () => { return () => stopCompletionSound(); }, []); + useEffect(() => { + if (!isRunning) { + setTimeLeft(getCurrentTime() * 60); + } +}, [focusTime, shortBreak, longBreak, mode, isRunning]); useEffect(()=>{ let interval; if(isRunning){ interval= setInterval(()=>{ setTimeLeft((prev)=>{ - if(prev<=1){ - clearInterval(interval); - setTimeLeft(25*60); - setIsRunning(false); - finRef.current.play(); - setShowPopUp(true); - return 0; - } - + if(prev<=1){ + clearInterval(interval); + setIsRunning(false); + finRef.current.play(); + setShowPopUp(true); + return 0; +} return prev-1; }) },1000); } return ()=> clearInterval(interval) - },[isRunning, timeLeft]); + },[isRunning]); const formatTime= ()=>{ const minutes = Math.floor(timeLeft/60); - const seconds = timeLeft%60; + const seconds = Math.floor(timeLeft%60); return `${String(minutes).padStart(2,"0")}:${String(seconds).padStart(2,"0")}`; } @@ -71,16 +86,130 @@ const Pomodoro = () => {
-

Complete your tasks with a pomodoro timer.

-
+

Focus. Build habits. Forge your day.

+ +
+ + + + + +
+ {showSettings && ( + +
+ +
+ + + { + const value = Number(e.target.value); + + if(value >= 1 && value <= 180){ + setFocusTime(value); + } +}} className='w-20 px-2 py-1 rounded-lg bg-white/10 text-white' + /> +
+ +
+ + + { + const value = Number(e.target.value); + + if(value >= 1 && value <= 60){ + setShortBreak(value); + } +}} + className='w-20 px-2 py-1 rounded-lg bg-white/10 text-white' + /> +
+ +
+ + + { + const value = Number(e.target.value); + + if(value >= 1 && value <= 120){ + setLongBreak(value); + } +}} className='w-20 px-2 py-1 rounded-lg bg-white/10 text-white' + /> +
+ +
+)} +

{formatTime()}

- @@ -91,8 +220,12 @@ const Pomodoro = () => { @@ -102,7 +235,7 @@ const Pomodoro = () => { {showPopUp &&

Session Complete!

-

Great work. Take a break!

+

{mode==="focus" ? "Great work. Take a break!" : "Break completed. Ready to focus?"}