fix(#2684): fix calculate duration for match from scout

keep-around/31934c87741a585cc6b3c9552489ffa62de670b6
Andrei Dekterev 3 years ago
parent 34b261a4cb
commit 2fc0e2a5be
  1. 12
      src/features/MatchPage/components/FinishedMatch/hooks/index.tsx
  2. 16
      src/features/MatchPopup/store/hooks/index.tsx
  3. 1
      src/features/MultiSourcePlayer/index.tsx

@ -3,6 +3,7 @@ import { useToggle } from 'hooks/useToggle'
import type { Settings } from 'features/MatchPopup' import type { Settings } from 'features/MatchPopup'
import { useMatchPopupStore } from 'features/MatchPopup' import { useMatchPopupStore } from 'features/MatchPopup'
import { useEffect } from 'react'
import { usePlayerLogger } from './usePlayerLogger' import { usePlayerLogger } from './usePlayerLogger'
import { useEpisodes } from './useEpisodes' import { useEpisodes } from './useEpisodes'
import { useChapters } from './useChapters' import { useChapters } from './useChapters'
@ -12,6 +13,7 @@ export const useFinishedMatch = () => {
handlePlaylistClick, handlePlaylistClick,
matchPlaylists, matchPlaylists,
selectedPlaylist, selectedPlaylist,
setChapters,
setSettings, setSettings,
} = useMatchPopupStore() } = useMatchPopupStore()
const { const {
@ -35,8 +37,14 @@ export const useFinishedMatch = () => {
} }
handlePlaylistClick(playlist, e) handlePlaylistClick(playlist, e)
} }
const { chapters } = useChapters({ episodes, selectedPlaylist })
useEffect(() => {
setChapters(chapters)
}, [chapters, setChapters])
return { return {
chapters,
closeSettingsPopup, closeSettingsPopup,
isSettingsPopupOpen, isSettingsPopupOpen,
onPlayingChange, onPlayingChange,
@ -45,9 +53,5 @@ export const useFinishedMatch = () => {
playlists: matchPlaylists, playlists: matchPlaylists,
selectedPlaylist, selectedPlaylist,
setEpisodesSettings, setEpisodesSettings,
...useChapters({
episodes,
selectedPlaylist,
}),
} }
} }

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

@ -72,7 +72,6 @@ export const MultiSourcePlayer = (props: Props) => {
wrapperRef, wrapperRef,
} = useMultiSourcePlayer(props) } = useMultiSourcePlayer(props)
const firstPlayerActive = activePlayer === Players.PLAYER1 const firstPlayerActive = activePlayer === Players.PLAYER1
return ( return (
<PlayerWrapper <PlayerWrapper
ref={wrapperRef} ref={wrapperRef}

Loading…
Cancel
Save