diff --git a/frontend/public/sounds/alert.mp3 b/frontend/public/sounds/alert.mp3 new file mode 100644 index 0000000..d9dbf34 Binary files /dev/null and b/frontend/public/sounds/alert.mp3 differ diff --git a/frontend/src/Components/DashBoard/PomodoroTimer.jsx b/frontend/src/Components/DashBoard/PomodoroTimer.jsx index dfa07cc..ad3c8fe 100644 --- a/frontend/src/Components/DashBoard/PomodoroTimer.jsx +++ b/frontend/src/Components/DashBoard/PomodoroTimer.jsx @@ -1,4 +1,4 @@ -import { useContext } from "react"; +import { useContext, useEffect } from "react"; import Navbar from "../Navbar/Navbar"; import ThemeContext from "../ui/theme-provider.jsx"; import { useTimer } from "../../context/TimerContext.jsx"; @@ -79,10 +79,24 @@ export default function PomodoroTimer() { const minutes = Math.floor(timeLeft / 60); const seconds = timeLeft % 60; + useEffect(() => { + // Check if the timer is at 0:00. We rely on the context to switch phases. + // We only play the sound if the timer hits zero while running. + if (timeLeft === 0) { + const audio = document.getElementById('timer-end-sound'); + if (audio) { + audio.play().catch(error => { + // Log error if browser blocks auto-play + console.error("Audio playback blocked:", error); + }); + } + } + }, [timeLeft]); // only re-runs when timeLeft changes + return (
{description}
-