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. + setShowSettings(!showSettings)} + className='px-4 py-2 rounded-xl bg-[#4eb7b3]/20 border border-[#4eb7b3]/40 text-[#4eb7b3]' +> + ⚙ Timer Settings + + + setMode("focus")} + className={`btn cursor-pointer ${ + mode==="focus" + ? "bg-[#4eb7b3] text-black" + : "btn-primary" +}`} + > + Focus + + + setMode("short")} + className={`btn cursor-pointer ${ + mode==="short" + ? "bg-[#4eb7b3] text-black" + : "btn-primary" +}`} + > + Short Break + + + setMode("long")} + className={`btn cursor-pointer ${ + mode==="long" + ? "bg-[#4eb7b3] text-black" + : "btn-primary" +}`} + > + Long Break + + + {showSettings && ( + + + + + + + Focus + + { + 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' + /> + + + + + Short Break + + + { + 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' + /> + + + + + Long Break + + + { + 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()} - setIsRunning(true)} - > + { + if(!isRunning){ + if(timeLeft === 0){ + setTimeLeft(getCurrentTime()*60); + } + setIsRunning(true); +} +}} +> Start @@ -91,8 +220,12 @@ const Pomodoro = () => { {setTimeLeft(25*60); setIsRunning(false); stopCompletionSound(); setShowPopUp(false);}} - > +onClick={()=>{ +setTimeLeft(getCurrentTime() * 60); +setIsRunning(false); +stopCompletionSound(); +setShowPopUp(false); +}} > Reset @@ -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?"} {finRef.current.pause(); finRef.current.currentTime=0; setShowPopUp(false)}}> Close
Great work. Take a break!
{mode==="focus" ? "Great work. Take a break!" : "Break completed. Ready to focus?"}