|
|
|
|
@ -15,6 +15,8 @@ import { useToggle } from 'hooks' |
|
|
|
|
|
|
|
|
|
import { buildPlaylists } from 'features/MatchPage/helpers/buildPlaylists' |
|
|
|
|
import { Playlists } from 'features/MatchPage/types' |
|
|
|
|
import { Chapters } from 'features/MultiSourcePlayer/types' |
|
|
|
|
import { useDuration } from 'features/MultiSourcePlayer/hooks/useDuration' |
|
|
|
|
|
|
|
|
|
import { useSettingsState } from './useSettingsState' |
|
|
|
|
import { useSportActions } from './useSportActions' |
|
|
|
|
@ -23,8 +25,6 @@ import type { MatchData } from '../../types' |
|
|
|
|
import { PlayerPlaylistFormats } from '../../types' |
|
|
|
|
import { usePlayerClickHandler } from './usePlayerClickHandler' |
|
|
|
|
import { usePlaylistLexics } from './usePlaylistLexics' |
|
|
|
|
import { calculateDuration } from '../../../MatchPage/helpers/fullMatchDuration' |
|
|
|
|
import { useMatchPage } from '../../../MatchPage/store/hooks' |
|
|
|
|
|
|
|
|
|
type ArgsFetchMatchPlaylists = { |
|
|
|
|
id: number, |
|
|
|
|
@ -37,8 +37,7 @@ const initialPlaylists = buildPlaylists(null) |
|
|
|
|
export const useMatchPopup = () => { |
|
|
|
|
const { pathname } = useLocation() |
|
|
|
|
const [match, setMatch] = useState<MatchData>(null) |
|
|
|
|
const { profile } = useMatchPage() |
|
|
|
|
|
|
|
|
|
const [chapters, setChapters] = useState<Chapters>([]) |
|
|
|
|
const [matchPlaylists, setMatchPlaylists] = useState<Playlists>(initialPlaylists) |
|
|
|
|
const { |
|
|
|
|
close: closePopup, |
|
|
|
|
@ -89,14 +88,14 @@ export const useMatchPopup = () => { |
|
|
|
|
useEffect(() => { |
|
|
|
|
setMatchPlaylists(initialPlaylists) |
|
|
|
|
}, [pathname]) |
|
|
|
|
|
|
|
|
|
const fullMatchDuration = useDuration(chapters) / 1000 |
|
|
|
|
const fetchMatchPlaylists = useCallback(({ |
|
|
|
|
id, |
|
|
|
|
sportType, |
|
|
|
|
withFullMatchDuration = true, |
|
|
|
|
}: ArgsFetchMatchPlaylists) => { |
|
|
|
|
getMatchPlaylists({ |
|
|
|
|
fullMatchDuration: calculateDuration(profile), |
|
|
|
|
fullMatchDuration, |
|
|
|
|
matchId: id, |
|
|
|
|
selectedActions: [], |
|
|
|
|
sportType, |
|
|
|
|
@ -104,8 +103,7 @@ export const useMatchPopup = () => { |
|
|
|
|
}).then(fetchLexics) |
|
|
|
|
.then(buildPlaylists) |
|
|
|
|
.then(setMatchPlaylists) |
|
|
|
|
}, [fetchLexics, profile]) |
|
|
|
|
|
|
|
|
|
}, [fetchLexics, fullMatchDuration]) |
|
|
|
|
const openMatchPopup = (selectedMatch: MatchData) => { |
|
|
|
|
if (!selectedMatch) return |
|
|
|
|
setMatch(selectedMatch) |
|
|
|
|
@ -115,7 +113,6 @@ export const useMatchPopup = () => { |
|
|
|
|
sportType: selectedMatch.sportType, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
actions, |
|
|
|
|
closePopup, |
|
|
|
|
@ -132,5 +129,6 @@ export const useMatchPopup = () => { |
|
|
|
|
setSettings, |
|
|
|
|
settings, |
|
|
|
|
...usePlayerClickHandler(), |
|
|
|
|
setChapters, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|