Skip to content

Commit

Permalink
Play pause using keyboard event spacebar
Browse files Browse the repository at this point in the history
  • Loading branch information
mohdsayed committed Dec 28, 2024
1 parent 419f2f3 commit d74dbb4
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,28 @@ const Panel = ({ currentSiteData, setCurrentSite }: PanelProps) => {
});
}, []);

const tooglePlayOnKeydown = useCallback(
(event: KeyboardEvent) => {
// Check if the pressed key is the spacebar
if (event.code === 'Space') {
setPlaying();
}
},
[setPlaying]
);

const { setActiveTab } = useTabs(({ actions }) => ({
setActiveTab: actions.setActiveTab,
}));

useEffect(() => {
document.addEventListener('keydown', tooglePlayOnKeydown);

return () => {
document.removeEventListener('keydown', tooglePlayOnKeydown);
};
}, [tooglePlayOnKeydown]);

useEffect(() => {
if (!currentSiteData) {
setActiveTab(0);
Expand Down

0 comments on commit d74dbb4

Please sign in to comment.