|
|
|
@ -1,4 +1,8 @@ |
|
|
|
import { useState, useEffect } from 'react' |
|
|
|
import { |
|
|
|
|
|
|
|
useState, |
|
|
|
|
|
|
|
useEffect, |
|
|
|
|
|
|
|
useCallback, |
|
|
|
|
|
|
|
} from 'react' |
|
|
|
|
|
|
|
|
|
|
|
import isEmpty from 'lodash/isEmpty' |
|
|
|
import isEmpty from 'lodash/isEmpty' |
|
|
|
|
|
|
|
|
|
|
|
@ -14,6 +18,7 @@ import { usePopupNavigation } from './usePopupNavigation' |
|
|
|
import type { MatchData } from '../../types' |
|
|
|
import type { MatchData } from '../../types' |
|
|
|
import { PopupPages, PlayerPlaylistFormats } from '../../types' |
|
|
|
import { PopupPages, PlayerPlaylistFormats } from '../../types' |
|
|
|
import { usePlayerClickHandler } from './usePlayerClickHandler' |
|
|
|
import { usePlayerClickHandler } from './usePlayerClickHandler' |
|
|
|
|
|
|
|
import { usePlaylistLexics } from './usePlaylistLexics' |
|
|
|
|
|
|
|
|
|
|
|
export const useMatchPopup = () => { |
|
|
|
export const useMatchPopup = () => { |
|
|
|
const [match, setMatch] = useState<MatchData>(null) |
|
|
|
const [match, setMatch] = useState<MatchData>(null) |
|
|
|
@ -28,7 +33,6 @@ export const useMatchPopup = () => { |
|
|
|
} = usePopupNavigation() |
|
|
|
} = usePopupNavigation() |
|
|
|
|
|
|
|
|
|
|
|
const { |
|
|
|
const { |
|
|
|
resetSelectedActions, |
|
|
|
|
|
|
|
setEpisodeDuration, |
|
|
|
setEpisodeDuration, |
|
|
|
setSelectedActions, |
|
|
|
setSelectedActions, |
|
|
|
setSelectedPlaylistFormat, |
|
|
|
setSelectedPlaylistFormat, |
|
|
|
@ -43,6 +47,21 @@ export const useMatchPopup = () => { |
|
|
|
|
|
|
|
|
|
|
|
const { actions, fetchSportActions } = useSportActions(match?.sportType) |
|
|
|
const { actions, fetchSportActions } = useSportActions(match?.sportType) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { fetchLexics } = usePlaylistLexics() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const onFormatSelect = useCallback((format: PlayerPlaylistFormats) => { |
|
|
|
|
|
|
|
setSelectedPlaylistFormat(format) |
|
|
|
|
|
|
|
if (format === PlayerPlaylistFormats.SELECTED_ACTIONS) { |
|
|
|
|
|
|
|
fetchSportActions() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setSelectedActions([]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [ |
|
|
|
|
|
|
|
fetchSportActions, |
|
|
|
|
|
|
|
setSelectedActions, |
|
|
|
|
|
|
|
setSelectedPlaylistFormat, |
|
|
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (!isOpen) { |
|
|
|
if (!isOpen) { |
|
|
|
setMatch(null) |
|
|
|
setMatch(null) |
|
|
|
@ -51,25 +70,21 @@ export const useMatchPopup = () => { |
|
|
|
}, [isOpen]) |
|
|
|
}, [isOpen]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (selectedPlaylistFormat !== PlayerPlaylistFormats.SELECTED_ACTIONS) { |
|
|
|
const isPlaylistPage = page === PopupPages.PLAYLIST |
|
|
|
resetSelectedActions() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [selectedPlaylistFormat, resetSelectedActions]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
const isSettingsPage = page === PopupPages.SETTINGS |
|
|
|
|
|
|
|
const actionsFormatSelected = ( |
|
|
|
const actionsFormatSelected = ( |
|
|
|
selectedPlaylistFormat === PlayerPlaylistFormats.SELECTED_ACTIONS |
|
|
|
selectedPlaylistFormat === PlayerPlaylistFormats.SELECTED_ACTIONS |
|
|
|
) |
|
|
|
) |
|
|
|
if (isSettingsPage && actionsFormatSelected) { |
|
|
|
if (isPlaylistPage && actionsFormatSelected && isEmpty(selectedActions)) { |
|
|
|
fetchSportActions() |
|
|
|
setSelectedPlaylistFormat(PlayerPlaylistFormats.ALL_MATCH_TIME) |
|
|
|
} |
|
|
|
} |
|
|
|
}, [ |
|
|
|
}, [ |
|
|
|
|
|
|
|
actions, |
|
|
|
|
|
|
|
selectedActions, |
|
|
|
selectedPlaylistFormat, |
|
|
|
selectedPlaylistFormat, |
|
|
|
match, |
|
|
|
match, |
|
|
|
page, |
|
|
|
page, |
|
|
|
fetchSportActions, |
|
|
|
fetchSportActions, |
|
|
|
resetSelectedActions, |
|
|
|
setSelectedPlaylistFormat, |
|
|
|
]) |
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
@ -77,16 +92,17 @@ export const useMatchPopup = () => { |
|
|
|
|
|
|
|
|
|
|
|
getMatchPlaylists({ |
|
|
|
getMatchPlaylists({ |
|
|
|
matchId: match.id, |
|
|
|
matchId: match.id, |
|
|
|
// запрос с экшнами [1, 2, 3] временный
|
|
|
|
selectedActions, |
|
|
|
selectedActions: isEmpty(selectedActions) ? [1, 2, 3] : selectedActions, |
|
|
|
|
|
|
|
sportType: match.sportType, |
|
|
|
sportType: match.sportType, |
|
|
|
}).then(buildPlaylists) |
|
|
|
}).then(fetchLexics) |
|
|
|
|
|
|
|
.then(buildPlaylists) |
|
|
|
.then(setMatchPlaylists) |
|
|
|
.then(setMatchPlaylists) |
|
|
|
}, [ |
|
|
|
}, [ |
|
|
|
isOpen, |
|
|
|
isOpen, |
|
|
|
match, |
|
|
|
match, |
|
|
|
page, |
|
|
|
page, |
|
|
|
selectedActions, |
|
|
|
selectedActions, |
|
|
|
|
|
|
|
fetchLexics, |
|
|
|
]) |
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
@ -100,7 +116,7 @@ export const useMatchPopup = () => { |
|
|
|
matchPlaylists, |
|
|
|
matchPlaylists, |
|
|
|
onActionClick: setSelectedActions, |
|
|
|
onActionClick: setSelectedActions, |
|
|
|
onDurationChange: setEpisodeDuration, |
|
|
|
onDurationChange: setEpisodeDuration, |
|
|
|
onFormatSelect: setSelectedPlaylistFormat, |
|
|
|
onFormatSelect, |
|
|
|
openPopup, |
|
|
|
openPopup, |
|
|
|
page, |
|
|
|
page, |
|
|
|
selectedActions, |
|
|
|
selectedActions, |
|
|
|
|