Skip to content

Commit

Permalink
Add click sound effects
Browse files Browse the repository at this point in the history
  • Loading branch information
mikumino committed Dec 18, 2023
1 parent 9ff681f commit b196210
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/FlowtimeBreak.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState, useEffect } from 'react';
import { useState, useEffect } from 'react';
import TimeDisplay from './TimeDisplay';
import Controls from './Controls';
import tick from '../assets/Tick.mp3';


interface FlowtimeBreakProps {
breakTime: number;
Expand Down Expand Up @@ -29,15 +31,18 @@ const FlowtimeBreak = ({ breakTime, handleEndBreak }: FlowtimeBreakProps) => {
}, [isRunning, timeRemaining]);

const handleStart = () => {
new Audio(tick).play();
if (!isRunning) {
setEndTime(Date.now() + timeRemaining);
}
setIsRunning(!isRunning);
};
const handleStop = () => {
new Audio(tick).play();
handleEndBreak();
}
const handleReset = () => {
new Audio(tick).play();
setTimeRemaining(breakTime);
};

Expand Down
4 changes: 4 additions & 0 deletions src/components/FlowtimeFocus.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState, useEffect } from 'react';
import TimeDisplay from './TimeDisplay';
import Controls from './Controls';
import tick from '../assets/Tick.mp3';

interface FlowTimeFocusProps {
handleEndFocus: (focusTime: number) => void;
Expand All @@ -26,17 +27,20 @@ const FlowtimeFocus = ({ handleEndFocus }: FlowTimeFocusProps) => {
}, [isRunning, time, startTime]);

const handleStart = () => {
new Audio(tick).play();
if (!isRunning) {
setStartTime(Date.now() - time);
}
setIsRunning(!isRunning);
};

const handleStop = () => {
new Audio(tick).play();
handleEndFocus(time);
};

const handleReset = () => {
new Audio(tick).play();
setStartTime(0);
setTime(0);
};
Expand Down

0 comments on commit b196210

Please sign in to comment.