Skip to content

Commit

Permalink
Merge pull request #2520 from MuhammadUmer44/feature-space-bar-media-…
Browse files Browse the repository at this point in the history
…controls

[Graph Mindset]: Media Player Add spacebar play/pause control
  • Loading branch information
Rassl authored Dec 16, 2024
2 parents 2ecf08c + d8cf7a2 commit 6365c60
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/components/mindset/components/MediaPlayer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ const MediaPlayerComponent = ({ mediaUrl }: Props) => {
}
}, [playingTime, isSeeking, setIsSeeking, playerRef])

const togglePlay = () => {
const togglePlay = useCallback(() => {
setIsPlaying(!isPlaying)
}
}, [isPlaying, setIsPlaying])

const handlePlay = useCallback(() => {
setIsPlaying(true)
Expand All @@ -102,6 +102,24 @@ const MediaPlayerComponent = ({ mediaUrl }: Props) => {
setStatus('error')
}

const handleKeyDown = useCallback(
(event: KeyboardEvent) => {
if (event.code === 'Space') {
event.preventDefault()
togglePlay()
}
},
[togglePlay],
)

useEffect(() => {
window.addEventListener('keydown', handleKeyDown)

return () => {
window.removeEventListener('keydown', handleKeyDown)
}
}, [handleKeyDown])

const edges = useMemo(() => {
const edgesFiltered = dataInitial?.links.filter((link) => link?.properties?.start) || []

Expand Down

0 comments on commit 6365c60

Please sign in to comment.