diff --git a/src/App.tsx b/src/App.tsx
index 16b39b6..f824941 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,140 +1,16 @@
import { useEffect } from 'react'
-import { useAtom, useAtomValue, useSetAtom } from 'jotai'
-import { useResetAtom } from 'jotai/utils'
-import usePlayer from './hooks/usePlayer'
+import PlayerControl from './components/PlayerControl'
-import {
- playerSourceAtom,
- playerVolumeAtom,
- playerMutedAtom,
-} from './atoms/player'
-import {
- audioMomentsAtom,
- generateRandomAudioMomentsAtom,
- removeActualAudioMomentAtom,
- audioMomentShouldUnpauseAtom,
- audioMomentShouldPlayAtom,
-} from './atoms/audioMoments'
-import {
- timerIsRunningAtom,
- startTimerAtom,
- pauseTimerAtom,
- resetTimerAtom,
- timerCanResetAtom,
- timeTickingEffect,
-} from './atoms/timer'
+import { useTranslation } from 'react-i18next'
import cn from './lib/cn'
-import { MediaPlayer, MediaProvider } from '@vidstack/react'
-import '@vidstack/react/player/styles/base.css'
-
-import {
- AudioOrVideoSourceInput,
- Button,
- StartOrPauseTimerButton,
- Timer,
- VolumeControl,
-} from './components'
-
-import { useTranslation } from 'react-i18next'
-
import { FaGithub } from 'react-icons/fa'
export default function App() {
- const {
- player,
- playerPaused,
- playerCurrentTime,
- playerDuration,
- playerCanPlay,
- resumePlayer,
- pausePlayer,
- resetPlayerCurrentTime,
- resetPlayer,
- } = usePlayer()
-
- const [playerSource, setPlayerSource] = useAtom(playerSourceAtom)
- const playerVolume = useAtomValue(playerVolumeAtom)
- const playerMuted = useAtomValue(playerMutedAtom)
-
- const audioMoments = useAtomValue(audioMomentsAtom)
- const generateRandomAudioMoments = useSetAtom(generateRandomAudioMomentsAtom)
- const removeActualAudioMoment = useSetAtom(removeActualAudioMomentAtom)
- const resetAudioMoments = useResetAtom(audioMomentsAtom)
- const [audioMomentShouldUnpause, setAudioMomentShouldUnpause] = useAtom(
- audioMomentShouldUnpauseAtom,
- )
- const audioMomentShouldPlay = useAtomValue(audioMomentShouldPlayAtom)
-
- const timerIsRunning = useAtomValue(timerIsRunningAtom)
- const startTimer = useSetAtom(startTimerAtom)
- const pauseTimer = useSetAtom(pauseTimerAtom)
- const resetTimer = useSetAtom(resetTimerAtom)
- const timerCanReset = useAtomValue(timerCanResetAtom)
- useAtom(timeTickingEffect)
-
const { t, i18n } = useTranslation('', { keyPrefix: 'app' })
- function handleAudioOrVideoSourceInputChange(input: string | File): void {
- resetTimer()
- if (playerSource !== '') {
- resetAudioMoments()
- pausePlayer()
- resetPlayerCurrentTime()
- }
-
- setPlayerSource(input)
- }
-
- function handleStartTimer(): void {
- startTimer()
- if (playerPaused && audioMomentShouldUnpause) {
- resumePlayer()
- setAudioMomentShouldUnpause(false)
- }
- }
-
- function handlePauseTimer(): void {
- pauseTimer()
- if (!playerPaused) {
- pausePlayer()
- setAudioMomentShouldUnpause(true)
- }
- }
-
- function handleStartOrPauseTimerButtonClick(): void {
- if (!audioMoments) generateRandomAudioMoments(playerDuration)
-
- if (timerIsRunning) {
- handlePauseTimer()
- return
- }
-
- handleStartTimer()
- }
-
- function handleResetTimerButtonClick(): void {
- resetTimer()
-
- if (playerCurrentTime > 0) {
- resetPlayer()
- resetAudioMoments()
- }
- }
-
- useEffect(() => {
- function handleAudioMoments() {
- if (audioMomentShouldPlay) {
- resumePlayer()
- removeActualAudioMoment()
- }
- }
-
- handleAudioMoments()
- }, [audioMomentShouldPlay, resumePlayer, removeActualAudioMoment])
-
useEffect(() => {
document.title = t('pageTitle')
document.documentElement.lang = i18n.language
@@ -155,39 +31,7 @@ export default function App() {
>
{t('title')}
-