You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
spa_instat_tv/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx

70 lines
1.7 KiB

import { useEffect } from 'react'
import { useToggle, useObjectState } from 'hooks'
import type { Settings } from 'features/MatchPopup'
import { useMatchPopupStore } from 'features/MatchPopup'
import { useMatchPageStore } from 'features/MatchPage/store'
import { usePlayerLogger } from './usePlayerLogger'
import { useEpisodes } from './useEpisodes'
import { useChapters } from './useChapters'
const initPausedData = {
activeChapterIndex: 0,
activePlayer: 0 || 1,
playedProgress: 0,
}
export type PausedData = typeof initPausedData
export const useFinishedMatch = () => {
const [pausedData, setPausedData] = useObjectState<PausedData>(initPausedData)
const { setChapters, setSettings } = useMatchPopupStore()
const {
handlePlaylistClick,
matchPlaylists,
selectedPlaylist,
} = useMatchPageStore()
const {
close: closeSettingsPopup,
isOpen: isSettingsPopupOpen,
open: openSettingsPopup,
} = useToggle()
const { episodes } = useEpisodes()
const { logPlaylistChange, onPlayingChange } = usePlayerLogger()
const setEpisodesSettings = (newSettings: Settings) => {
setSettings(newSettings)
closeSettingsPopup()
}
const onPlaylistSelect: typeof handlePlaylistClick = (playlist, e) => {
if (selectedPlaylist) {
logPlaylistChange(selectedPlaylist)
}
handlePlaylistClick(playlist, e)
}
const { chapters } = useChapters({ episodes, selectedPlaylist })
useEffect(() => {
setChapters(chapters)
}, [chapters, setChapters])
return {
chapters,
closeSettingsPopup,
isSettingsPopupOpen,
onPlayingChange,
onPlaylistSelect,
openSettingsPopup,
pausedData,
playlists: matchPlaylists,
selectedPlaylist,
setEpisodesSettings,
setPausedData,
}
}