-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use context for audio related info
- Loading branch information
Showing
38 changed files
with
288 additions
and
327 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,40 @@ | ||
import React from 'react'; | ||
import {NextSeo} from 'next-seo'; | ||
import React, {useEffect} from 'react'; | ||
import {useAudioPlayerContext} from 'src/contexts/audio-player-context'; | ||
import {useAudioRefContext} from 'src/contexts/audio-ref-context'; | ||
import {useDynamicTitle} from 'src/hooks/use-dynamic-title'; | ||
|
||
import {Invisible} from './audio.component.styles'; | ||
import {useAudioModule} from './hooks/use-audio-component'; | ||
|
||
export function AudioComponent() { | ||
interface Props { | ||
defaultSpeed: string; | ||
} | ||
|
||
export function AudioComponent({defaultSpeed}: Props) { | ||
const audioRef = useAudioRefContext(); | ||
const {dynamicTitle} = useDynamicTitle(); | ||
const {setSpeed} = useAudioPlayerContext(); | ||
|
||
useEffect(() => { | ||
setSpeed(defaultSpeed); | ||
}, [defaultSpeed, setSpeed]); | ||
|
||
useAudioModule(); | ||
|
||
return ( | ||
<Invisible> | ||
<audio | ||
ref={audioRef} | ||
aria-label="player" | ||
// controls | ||
> | ||
<track kind="captions" /> | ||
</audio> | ||
</Invisible> | ||
<> | ||
<NextSeo title={dynamicTitle} /> | ||
|
||
<Invisible> | ||
<audio | ||
ref={audioRef} | ||
aria-label="player" | ||
// controls | ||
> | ||
<track kind="captions" /> | ||
</audio> | ||
</Invisible> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,20 @@ | ||
import {useAtom} from 'jotai'; | ||
import {useEffect} from 'react'; | ||
import {useAudioPlayerContext} from 'src/contexts/audio-player-context'; | ||
|
||
import { | ||
isPlayingAtom, | ||
setPauseAtom, | ||
setPlayAtom, | ||
} from '../../../atoms/play-pause.atoms'; | ||
|
||
/** | ||
* Hook to toggle play/pause state with keyboard | ||
* @param keyCode | ||
*/ | ||
export function useKeyboardToggle(keyCode = 'Space'): void { | ||
const [isPlaying] = useAtom(isPlayingAtom); | ||
const [, setPlay] = useAtom(setPlayAtom); | ||
const [, setPause] = useAtom(setPauseAtom); | ||
const {togglePlaying} = useAudioPlayerContext(); | ||
|
||
useEffect(() => { | ||
const handleKeyboard = (event) => { | ||
if (event.code === keyCode) { | ||
if (isPlaying) { | ||
return setPause(); | ||
} | ||
|
||
setPlay(); | ||
const handler = (e: KeyboardEvent) => { | ||
if (e.code === keyCode) { | ||
togglePlaying(); | ||
} | ||
}; | ||
|
||
document.addEventListener('keypress', handleKeyboard); | ||
return () => document.removeEventListener('keypress', handleKeyboard); | ||
}, [isPlaying, keyCode, setPause, setPlay]); | ||
document.addEventListener('keypress', handler); | ||
|
||
return () => { | ||
document.removeEventListener('keypress', handler); | ||
}; | ||
}, [keyCode, togglePlaying]); | ||
} |
20 changes: 11 additions & 9 deletions
20
src/components/indicators/hooks/use-indicators-component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.