mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 17:04:15 +00:00
feat: add keyboard shortcut for play button
This commit is contained in:
parent
ebb35deaf9
commit
d3a2a12e1f
2 changed files with 17 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { useEffect } from 'react';
|
import { useCallback, useEffect } from 'react';
|
||||||
import { BiPause, BiPlay } from 'react-icons/bi/index';
|
import { BiPause, BiPlay } from 'react-icons/bi/index';
|
||||||
|
|
||||||
import { useSoundStore } from '@/store';
|
import { useSoundStore } from '@/store';
|
||||||
|
|
@ -15,21 +15,33 @@ export function PlayButton() {
|
||||||
|
|
||||||
const showSnackbar = useSnackbar();
|
const showSnackbar = useSnackbar();
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleToggle = useCallback(() => {
|
||||||
if (noSelected) return showSnackbar('Please first select a sound to play.');
|
if (noSelected) return showSnackbar('Please first select a sound to play.');
|
||||||
|
|
||||||
toggle();
|
toggle();
|
||||||
};
|
}, [showSnackbar, toggle, noSelected]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isPlaying && noSelected) pause();
|
if (isPlaying && noSelected) pause();
|
||||||
}, [isPlaying, pause, noSelected]);
|
}, [isPlaying, pause, noSelected]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const listener = (e: KeyboardEvent) => {
|
||||||
|
if (e.shiftKey && e.key === ' ') {
|
||||||
|
handleToggle();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('keydown', listener);
|
||||||
|
|
||||||
|
return () => document.removeEventListener('keydown', listener);
|
||||||
|
}, [handleToggle]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
aria-disabled={noSelected}
|
aria-disabled={noSelected}
|
||||||
className={cn(styles.playButton, noSelected && styles.disabled)}
|
className={cn(styles.playButton, noSelected && styles.disabled)}
|
||||||
onClick={handleClick}
|
onClick={handleToggle}
|
||||||
>
|
>
|
||||||
{isPlaying ? (
|
{isPlaying ? (
|
||||||
<>
|
<>
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ export function Notepad({ onClose, show }: NotepadProps) {
|
||||||
ref={textareaRef}
|
ref={textareaRef}
|
||||||
value={note}
|
value={note}
|
||||||
onChange={e => write(e.target.value)}
|
onChange={e => write(e.target.value)}
|
||||||
|
onKeyDown={e => e.stopPropagation()}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<p className={styles.counter}>
|
<p className={styles.counter}>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue