|
|
|
|
@ -1,11 +1,9 @@ |
|
|
|
|
import { |
|
|
|
|
useEffect, |
|
|
|
|
useMemo, |
|
|
|
|
useState, |
|
|
|
|
useCallback, |
|
|
|
|
} from 'react' |
|
|
|
|
|
|
|
|
|
import debounce from 'lodash/debounce' |
|
|
|
|
|
|
|
|
|
import type { MatchInfo } from 'requests/getMatchInfo' |
|
|
|
|
|
|
|
|
|
import { usePageParams, useInterval } from 'hooks' |
|
|
|
|
@ -19,8 +17,7 @@ import { useMatchPlaylists } from './useMatchPlaylists' |
|
|
|
|
import { useEvents } from './useEvents' |
|
|
|
|
import { initialPlaylist } from './useSelectedPlaylist' |
|
|
|
|
|
|
|
|
|
const MATCH_DATA_POLL_INTERVAL = 60000 |
|
|
|
|
const MATCH_PLAYLISTS_DELAY = 5000 |
|
|
|
|
const MATCH_DATA_POLL_INTERVAL = 5000 |
|
|
|
|
|
|
|
|
|
type UseMatchDataArgs = { |
|
|
|
|
matchProfile: MatchInfo, |
|
|
|
|
@ -42,37 +39,38 @@ export const useMatchData = ({ matchProfile: profile, selectedTab }: UseMatchDat |
|
|
|
|
|
|
|
|
|
const { events, fetchMatchEvents } = useEvents() |
|
|
|
|
|
|
|
|
|
const fetchPlaylistsDebounced = useMemo( |
|
|
|
|
() => debounce(fetchMatchPlaylists, MATCH_PLAYLISTS_DELAY), |
|
|
|
|
[fetchMatchPlaylists], |
|
|
|
|
) |
|
|
|
|
const chaptersDuration = useDuration(chapters) / 1000 |
|
|
|
|
const fullMatchDuration = matchDuration |
|
|
|
|
useEffect(() => { |
|
|
|
|
if (!profile || (profile.live && Number(profile.c_match_calc_status) <= 1)) return |
|
|
|
|
if (!profile || profile.live) return |
|
|
|
|
|
|
|
|
|
fetchMatchPlaylists({ |
|
|
|
|
fullMatchDuration, |
|
|
|
|
id: matchId, |
|
|
|
|
sportType, |
|
|
|
|
}) |
|
|
|
|
fetchMatchEvents() |
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [ |
|
|
|
|
profile, |
|
|
|
|
profile?.live, |
|
|
|
|
fullMatchDuration, |
|
|
|
|
matchId, |
|
|
|
|
sportType, |
|
|
|
|
fetchMatchPlaylists, |
|
|
|
|
fetchMatchEvents, |
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
const intervalCallback = () => { |
|
|
|
|
fetchPlaylistsDebounced({ |
|
|
|
|
const intervalCallback = useCallback(() => { |
|
|
|
|
fetchMatchPlaylists({ |
|
|
|
|
fullMatchDuration, |
|
|
|
|
id: matchId, |
|
|
|
|
sportType, |
|
|
|
|
}) |
|
|
|
|
fetchMatchEvents() |
|
|
|
|
} |
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [ |
|
|
|
|
fullMatchDuration, |
|
|
|
|
matchId, |
|
|
|
|
sportType, |
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
const { start, stop } = useInterval({ |
|
|
|
|
callback: intervalCallback, |
|
|
|
|
@ -86,7 +84,7 @@ export const useMatchData = ({ matchProfile: profile, selectedTab }: UseMatchDat |
|
|
|
|
} else { |
|
|
|
|
stop() |
|
|
|
|
} |
|
|
|
|
}, [profile?.live, profile?.c_match_calc_status, start, stop]) |
|
|
|
|
}, [profile?.live, profile?.c_match_calc_status, start, stop, matchId]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
selectedPlaylist?.id === FULL_GAME_KEY && setMatchDuration(chaptersDuration) |
|
|
|
|
|