fix(1701): calculate full match duration from boundaries

keep-around/fdb88b04b32b9392e76795099e2ec47c9856b38b
Mirlan 4 years ago committed by Andrei Dekterev
parent 6ed39e2570
commit 47c07a32e5
  1. 2
      src/features/MatchPage/components/LiveMatch/hooks/index.tsx
  2. 11
      src/features/MatchPage/helpers/fullMatchDuration.tsx
  3. 2
      src/features/MatchPage/store/hooks/index.tsx
  4. 16
      src/features/MatchPage/store/hooks/useMatchData.tsx
  5. 3
      src/features/MatchPage/store/hooks/useMatchPlaylists.tsx
  6. 2
      src/requests/getMatchPlaylists.tsx

@ -46,7 +46,7 @@ export const useLiveMatch = () => {
} = usePlayerProgressReporter() } = usePlayerProgressReporter()
const onDurationChange = (duration: number) => { const onDurationChange = (duration: number) => {
if (profile?.live) return if (profile?.live || profile?.video_bounds) return
setFullMatchPlaylistDuration(duration) setFullMatchPlaylistDuration(duration)
} }

@ -0,0 +1,11 @@
import find from 'lodash/find'
import type { MatchInfo } from 'requests/getMatchInfo'
import { FULL_MATCH_BOUNDARY } from 'features/MatchPage/components/LiveMatch/helpers'
export const calculateDuration = (profile: MatchInfo) => {
const bound = find(profile?.video_bounds, { h: FULL_MATCH_BOUNDARY })
if (!bound) return 0
return Number(bound.e) - Number(bound.s)
}

@ -58,7 +58,7 @@ export const useMatchPage = () => {
matchPlaylists, matchPlaylists,
selectedPlaylist, selectedPlaylist,
setFullMatchPlaylistDuration, setFullMatchPlaylistDuration,
} = useMatchData(matchProfile?.live) } = useMatchData(matchProfile)
const profile = useMemo( const profile = useMemo(
() => addScoresFromPlaylists(matchProfile, matchPlaylists), () => addScoresFromPlaylists(matchProfile, matchPlaylists),

@ -2,16 +2,19 @@ import { useEffect, useMemo } from 'react'
import debounce from 'lodash/debounce' import debounce from 'lodash/debounce'
import { MatchInfo } from 'requests/getMatchInfo'
import { usePageParams } from 'hooks/usePageParams' import { usePageParams } from 'hooks/usePageParams'
import { useInterval } from 'hooks/useInterval' import { useInterval } from 'hooks/useInterval'
import { calculateDuration } from '../../helpers/fullMatchDuration'
import { useMatchPlaylists } from './useMatchPlaylists' import { useMatchPlaylists } from './useMatchPlaylists'
import { useEvents } from './useEvents' import { useEvents } from './useEvents'
const MATCH_DATA_POLL_INTERVAL = 60000 const MATCH_DATA_POLL_INTERVAL = 60000
const MATCH_PLAYLISTS_DELAY = 5000 const MATCH_PLAYLISTS_DELAY = 5000
export const useMatchData = (live: boolean = false) => { export const useMatchData = (profile: MatchInfo) => {
const { profileId: matchId, sportType } = usePageParams() const { profileId: matchId, sportType } = usePageParams()
const { const {
fetchMatchPlaylists, fetchMatchPlaylists,
@ -27,13 +30,19 @@ export const useMatchData = (live: boolean = false) => {
[fetchMatchPlaylists], [fetchMatchPlaylists],
) )
const fullMatchDuration = useMemo(() => calculateDuration(profile), [profile])
useEffect(() => { useEffect(() => {
if (!profile) return
fetchMatchPlaylists({ fetchMatchPlaylists({
fullMatchDuration,
id: matchId, id: matchId,
sportType, sportType,
}) })
fetchMatchEvents() fetchMatchEvents()
}, [ }, [
profile,
fullMatchDuration,
matchId, matchId,
sportType, sportType,
fetchMatchPlaylists, fetchMatchPlaylists,
@ -42,6 +51,7 @@ export const useMatchData = (live: boolean = false) => {
const intervalCallback = () => { const intervalCallback = () => {
fetchPlaylistsDebounced({ fetchPlaylistsDebounced({
fullMatchDuration,
id: matchId, id: matchId,
sportType, sportType,
}) })
@ -55,12 +65,12 @@ export const useMatchData = (live: boolean = false) => {
}) })
useEffect(() => { useEffect(() => {
if (live) { if (profile?.live) {
start() start()
} else { } else {
stop() stop()
} }
}, [live, start, stop]) }, [profile?.live, start, stop])
return { return {
events, events,

@ -16,6 +16,7 @@ import { usePlaylistLexics } from './usePlaylistLexics'
import { useSelectedPlaylist } from './useSelectedPlaylist' import { useSelectedPlaylist } from './useSelectedPlaylist'
type ArgsFetchMatchPlaylists = { type ArgsFetchMatchPlaylists = {
fullMatchDuration: number,
id: number, id: number,
sportType: SportTypes, sportType: SportTypes,
} }
@ -43,10 +44,12 @@ export const useMatchPlaylists = () => {
}, [setSelectedPlaylist]) }, [setSelectedPlaylist])
const fetchMatchPlaylists = useCallback(({ const fetchMatchPlaylists = useCallback(({
fullMatchDuration,
id, id,
sportType, sportType,
}: ArgsFetchMatchPlaylists) => { }: ArgsFetchMatchPlaylists) => {
getMatchPlaylists({ getMatchPlaylists({
fullMatchDuration,
matchId: id, matchId: id,
selectedActions: [], selectedActions: [],
sportType, sportType,

@ -12,6 +12,7 @@ import { getFullMatchDuration } from './getFullMatchDuration'
const proc = PROCEDURES.ott_match_popup const proc = PROCEDURES.ott_match_popup
type Args = { type Args = {
fullMatchDuration: number,
matchId: number, matchId: number,
selectedActions: Array<number>, selectedActions: Array<number>,
sportType: SportTypes, sportType: SportTypes,
@ -75,6 +76,7 @@ type Response = {
} }
export const getMatchPlaylists = async ({ export const getMatchPlaylists = async ({
fullMatchDuration,
matchId, matchId,
selectedActions, selectedActions,
sportType, sportType,

Loading…
Cancel
Save