diff --git a/src/app/alphabet/MemoryCard.tsx b/src/app/alphabet/MemoryCard.tsx index 9de12ff..00c5d0c 100644 --- a/src/app/alphabet/MemoryCard.tsx +++ b/src/app/alphabet/MemoryCard.tsx @@ -2,7 +2,7 @@ import Button from "@/components/Button"; import IconClick from "@/components/IconClick"; import IMAGES from "@/config/images"; import { Letter, SupportedAlphabets } from "@/interfaces"; -import { Dispatch, SetStateAction, useRef, useState } from "react"; +import { Dispatch, KeyboardEvent, SetStateAction, useEffect, useRef, useState } from "react"; export default function MemoryCard( { @@ -19,9 +19,21 @@ export default function MemoryCard( const [more, setMore] = useState(false); const [ipaDisplay, setIPADisplay] = useState(true); const [letterDisplay, setLetterDisplay] = useState(true); + + useEffect(() => { + const handleKeydown = (e: globalThis.KeyboardEvent) => { + if (e.key === ' ') refresh(); + } + document.addEventListener('keydown', handleKeydown); + return () => document.removeEventListener('keydown', handleKeydown); + }); + const letter = alphabet[index]; + const refresh = () => { + setIndex(Math.floor(Math.random() * alphabet.length)); + } return ( -
+
) => e.preventDefault()}>
setChosenAlphabet(null)}> @@ -31,7 +43,7 @@ export default function MemoryCard( {ipaDisplay ? letter.letter_sound_ipa : ''}
- setIndex(Math.floor(Math.random() * alphabet.length))}> + setMore(!more)}> { more ? (<> diff --git a/src/app/srt-player/VideoPlayer/VideoPanel.tsx b/src/app/srt-player/VideoPlayer/VideoPanel.tsx index 3a5db3f..5137e27 100644 --- a/src/app/srt-player/VideoPlayer/VideoPanel.tsx +++ b/src/app/srt-player/VideoPlayer/VideoPanel.tsx @@ -39,6 +39,24 @@ const VideoPanel = forwardRef(( setIsPlaying(!video.paused); }, [videoRef, videoUrl]); + useEffect(() => { + const handleKeyDownEvent = (e: globalThis.KeyboardEvent) => { + if (e.key === 'n') { + next(); + } else if (e.key === 'p') { + previous(); + } else if (e.key === ' ') { + togglePlayPause(); + } else if (e.key === 'r') { + restart(); + } else if (e.key === 'a') { + ; handleAutoPauseToggle(); + } + } + document.addEventListener('keydown', handleKeyDownEvent); + return () => document.removeEventListener('keydown', handleKeyDownEvent) + }); + useEffect(() => { const cb = () => { if (ready.current.all()) { @@ -139,22 +157,8 @@ const VideoPanel = forwardRef(( } } - const handleKeyDownEvent = (e: KeyboardEvent) => { - if (e.key === 'n') { - next(); - } else if (e.key === 'p') { - previous(); - } else if (e.key === ' ') { - togglePlayPause(); - } else if (e.key === 'r') { - restart(); - } else if (e.key === 'a') { - ; handleAutoPauseToggle(); - } - } - return ( -
+
diff --git a/src/app/srt-player/page.tsx b/src/app/srt-player/page.tsx index 54d0c15..ca1258d 100644 --- a/src/app/srt-player/page.tsx +++ b/src/app/srt-player/page.tsx @@ -1,6 +1,6 @@ 'use client'; -import { useRef, useState } from "react"; +import { KeyboardEvent, useRef, useState } from "react"; import UploadArea from "./UploadArea"; import VideoPanel from "./VideoPlayer/VideoPanel"; @@ -10,7 +10,7 @@ export default function Home() { const [videoUrl, setVideoUrl] = useState(null); const [srtUrl, setSrtUrl] = useState(null); return ( -
+
) => e.preventDefault()}>