Skip to content

Commit

Permalink
Add countdown timer
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbe-j committed Nov 12, 2023
1 parent 07b1791 commit 4948e79
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
19 changes: 19 additions & 0 deletions dance-app/src/Recording.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@
width: 100%;
}

.countdown:before {
content: '321';

font-family:monospace;
display:inline-block;
width:1ch;
margin-left: 40px;
margin-right: 40px;
font-size: 10rem;
font-weight: 500;
overflow:hidden;

animation:countdowns 3s steps(3) infinite;
}

@keyframes countdowns {
0% {text-indent:0}
100% {text-indent:-3ch;}
}
.hide {
display: none;
}
Expand Down
25 changes: 21 additions & 4 deletions dance-app/src/sections/recording.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const RecordingPage = ({
});
const page = useContext(PageContext);
const [showVideo, setShowVideo] = useState<VideoState>(VideoState.preview);
const [showCountDown, setShowCountDown] = useState<boolean>(false);
const recordingRef = useRef<Recording | null>(null);
const hasRecording = recordingRef.current?.previewRef.current?.src;

Expand All @@ -79,14 +80,26 @@ const RecordingPage = ({
await openCamera(newRecording.id);
};

const countDown = () => {
console.log('countdown start')
setShowCountDown(true)
setTimeout(() => {
record()
console.log('countdown end')
setShowCountDown(false)
}, 3000)
}

const record = async () => {
console.log('record start')
const { current: recording } = recordingRef;
if (recording) {
setShowVideo(VideoState.recording);
await startRecording(recording.id);
setTimeout(async () => {
await stopRecording(recording.id);
setShowVideo(VideoState.preview);
console.log('record end')
}, 7000);
}
console.log(recordingRef.current);
Expand All @@ -102,13 +115,17 @@ const RecordingPage = ({
</Button>
<div className="record-button">
<Button
onClick={recordingRef.current ? record : initCamera}
onClick={recordingRef.current ? countDown : initCamera}
variant="outlined"
className={classes.recordButton}
>
<Typography variant="h2">
{recordingRef.current ? "Record" : "Start"}
</Typography>
{showCountDown ? (
<span className="countdown" />
) : (
<Typography variant="h2">
{recordingRef.current ? "Record" : "Start"}
</Typography>
)}
</Button>
</div>
</header>
Expand Down

0 comments on commit 4948e79

Please sign in to comment.