Skip to content

Commit

Permalink
Merge pull request #17 from byandrev/dev
Browse files Browse the repository at this point in the history
feat: add click sound effect
  • Loading branch information
byandrev authored Oct 6, 2023
2 parents ad67b97 + b0be4f7 commit 670c318
Show file tree
Hide file tree
Showing 5 changed files with 4,511 additions and 4,399 deletions.
Binary file added public/click.wav
Binary file not shown.
2 changes: 1 addition & 1 deletion src/components/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Header() {
></Button>
<Button
variant="ghost"
colorScheme="red"
colorScheme="gray"
leftIcon={<SettingsIcon />}
iconSpacing={0}
></Button>
Expand Down
28 changes: 23 additions & 5 deletions src/components/PomodoroActions.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import { Button, Flex } from "@chakra-ui/react";
import { FaPlay, FaPause, FaUndoAlt } from "react-icons/fa";
import { FaPause, FaPlay, FaUndoAlt } from "react-icons/fa";

import useAudio from "../hooks/useAudio";
import useTimer from "../hooks/useTimer";

function PomodoroActions() {
const { handleStart, handleStop, handleRestart } = useTimer();
const { toggle } = useAudio("/click.wav");

const handleClickStart = () => {
toggle();
handleStart();
};

const handleClickRestart = () => {
toggle();
handleRestart();
};

const handleClickStop = () => {
toggle();
handleStop();
};

return (
<Flex justifyContent="center">
Expand All @@ -13,26 +31,26 @@ function PomodoroActions() {
leftIcon={<FaUndoAlt />}
iconSpacing={0}
fontSize="2rem"
onClick={handleRestart}
onClick={handleClickRestart}
></Button>
<Button
variant="ghost"
color="brand.base"
leftIcon={<FaPlay />}
iconSpacing={0}
fontSize="2rem"
onClick={handleStart}
onClick={handleClickStart}
></Button>
<Button
variant="ghost"
color="brand.base"
leftIcon={<FaPause />}
iconSpacing={0}
fontSize="2rem"
onClick={handleStop}
onClick={handleClickStop}
></Button>
</Flex>
);
}

export default PomodoroActions;
export default PomodoroActions;
23 changes: 23 additions & 0 deletions src/hooks/useAudio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useEffect, useState } from "react";

const useAudio = (url) => {
const [audio] = useState(new Audio(url));
const [playing, setPlaying] = useState(false);

const toggle = () => setPlaying(!playing);

useEffect(() => {
playing ? audio.play() : audio.pause();
}, [audio, playing]);

useEffect(() => {
audio.addEventListener("ended", () => setPlaying(false));
return () => {
audio.removeEventListener("ended", () => setPlaying(false));
};
}, [audio]);

return { playing, toggle };
};

export default useAudio;
Loading

0 comments on commit 670c318

Please sign in to comment.