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

58 lines
1.4 KiB

import { useEffect } from 'react'
import { useToggle } from 'hooks/useToggle'
import type { Settings } from 'features/MatchPopup'
import { useMatchPopupStore } from 'features/MatchPopup'
import { usePlayerLogger } from './usePlayerLogger'
import { useEpisodes } from './useEpisodes'
import { useChapters } from './useChapters'
export const useFinishedMatch = () => {
const {
handlePlaylistClick,
matchPlaylists,
selectedPlaylist,
setChapters,
setSettings,
} = useMatchPopupStore()
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,
playlists: matchPlaylists,
selectedPlaylist,
setEpisodesSettings,
}
}