|
|
|
@ -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, |
|
|
|
|