|
|
|
@ -4,6 +4,7 @@ import { |
|
|
|
useEffect, |
|
|
|
useEffect, |
|
|
|
useState, |
|
|
|
useState, |
|
|
|
} from 'react' |
|
|
|
} from 'react' |
|
|
|
|
|
|
|
import { useQueryClient } from 'react-query' |
|
|
|
|
|
|
|
|
|
|
|
import throttle from 'lodash/throttle' |
|
|
|
import throttle from 'lodash/throttle' |
|
|
|
import isEmpty from 'lodash/isEmpty' |
|
|
|
import isEmpty from 'lodash/isEmpty' |
|
|
|
@ -11,12 +12,16 @@ import every from 'lodash/every' |
|
|
|
import find from 'lodash/find' |
|
|
|
import find from 'lodash/find' |
|
|
|
import isUndefined from 'lodash/isUndefined' |
|
|
|
import isUndefined from 'lodash/isUndefined' |
|
|
|
|
|
|
|
|
|
|
|
import type { |
|
|
|
import { querieKeys } from 'config' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import type { MatchScore } from 'requests' |
|
|
|
|
|
|
|
import { |
|
|
|
MatchInfo, |
|
|
|
MatchInfo, |
|
|
|
PlayersStats, |
|
|
|
PlayersStats, |
|
|
|
Player, |
|
|
|
Player, |
|
|
|
|
|
|
|
getPlayersStats, |
|
|
|
|
|
|
|
getMatchParticipants, |
|
|
|
} from 'requests' |
|
|
|
} from 'requests' |
|
|
|
import { getPlayersStats, getMatchParticipants } from 'requests' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { useObjectState, usePageParams } from 'hooks' |
|
|
|
import { useObjectState, usePageParams } from 'hooks' |
|
|
|
|
|
|
|
|
|
|
|
@ -57,6 +62,10 @@ export const usePlayersStats = ({ |
|
|
|
sportType, |
|
|
|
sportType, |
|
|
|
} = usePageParams() |
|
|
|
} = usePageParams() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const client = useQueryClient() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const matchScore = client.getQueryData<MatchScore>(querieKeys.matchScore) |
|
|
|
|
|
|
|
|
|
|
|
const isCurrentStats = statsType === StatsType.CURRENT_STATS |
|
|
|
const isCurrentStats = statsType === StatsType.CURRENT_STATS |
|
|
|
|
|
|
|
|
|
|
|
const isEmptyPlayersStats = (teamId: number) => ( |
|
|
|
const isEmptyPlayersStats = (teamId: number) => ( |
|
|
|
@ -66,17 +75,19 @@ export const usePlayersStats = ({ |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const fetchPlayers = useMemo(() => throttle(async (second?: number) => { |
|
|
|
const fetchPlayers = useMemo(() => throttle(async (second?: number) => { |
|
|
|
|
|
|
|
const videoBounds = matchScore?.video_bounds || matchProfile?.video_bounds |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
if ( |
|
|
|
!matchProfile?.team1.id |
|
|
|
!matchProfile?.team1.id |
|
|
|
|| !matchProfile?.team2.id |
|
|
|
|| !matchProfile?.team2.id |
|
|
|
|| !matchProfile?.video_bounds |
|
|
|
|| !videoBounds |
|
|
|
) return null |
|
|
|
) return null |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
return getMatchParticipants({ |
|
|
|
return getMatchParticipants({ |
|
|
|
matchId, |
|
|
|
matchId, |
|
|
|
sportType, |
|
|
|
sportType, |
|
|
|
...(!isUndefined(second) && getHalfTime(matchProfile.video_bounds, second)), |
|
|
|
...(!isUndefined(second) && getHalfTime(videoBounds, second)), |
|
|
|
}) |
|
|
|
}) |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
return Promise.reject(e) |
|
|
|
return Promise.reject(e) |
|
|
|
@ -86,18 +97,21 @@ export const usePlayersStats = ({ |
|
|
|
matchProfile?.team1.id, |
|
|
|
matchProfile?.team1.id, |
|
|
|
matchProfile?.team2.id, |
|
|
|
matchProfile?.team2.id, |
|
|
|
matchProfile?.video_bounds, |
|
|
|
matchProfile?.video_bounds, |
|
|
|
|
|
|
|
matchScore?.video_bounds, |
|
|
|
sportType, |
|
|
|
sportType, |
|
|
|
]) |
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
const fetchPlayersStats = useMemo(() => (async (team: 'team1' | 'team2', second?: number) => { |
|
|
|
const fetchPlayersStats = useMemo(() => (async (team: 'team1' | 'team2', second?: number) => { |
|
|
|
if (!sportName || !matchProfile?.[team].id || !matchProfile?.video_bounds) return null |
|
|
|
const videoBounds = matchScore?.video_bounds || matchProfile?.video_bounds |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!sportName || !matchProfile?.[team].id || !videoBounds) return null |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
return getPlayersStats({ |
|
|
|
return getPlayersStats({ |
|
|
|
matchId, |
|
|
|
matchId, |
|
|
|
sportName, |
|
|
|
sportName, |
|
|
|
teamId: matchProfile[team].id, |
|
|
|
teamId: matchProfile[team].id, |
|
|
|
...(!isUndefined(second) && getHalfTime(matchProfile.video_bounds, second)), |
|
|
|
...(!isUndefined(second) && getHalfTime(videoBounds, second)), |
|
|
|
}) |
|
|
|
}) |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
return Promise.reject(e) |
|
|
|
return Promise.reject(e) |
|
|
|
@ -111,7 +125,10 @@ export const usePlayersStats = ({ |
|
|
|
]) |
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
const fetchData = useMemo(() => throttle(async (second?: number) => { |
|
|
|
const fetchData = useMemo(() => throttle(async (second?: number) => { |
|
|
|
if (selectedPlaylist?.id !== FULL_GAME_KEY || !matchProfile?.video_bounds) return |
|
|
|
if ( |
|
|
|
|
|
|
|
selectedPlaylist?.id !== FULL_GAME_KEY |
|
|
|
|
|
|
|
|| (matchProfile?.live && Number(matchProfile.c_match_calc_status) <= 1) |
|
|
|
|
|
|
|
) return |
|
|
|
|
|
|
|
|
|
|
|
const [res1, res2, res3] = await Promise.all([ |
|
|
|
const [res1, res2, res3] = await Promise.all([ |
|
|
|
fetchPlayers(second), |
|
|
|
fetchPlayers(second), |
|
|
|
@ -140,7 +157,8 @@ export const usePlayersStats = ({ |
|
|
|
setPlayersStats, |
|
|
|
setPlayersStats, |
|
|
|
matchProfile?.team1.id, |
|
|
|
matchProfile?.team1.id, |
|
|
|
matchProfile?.team2.id, |
|
|
|
matchProfile?.team2.id, |
|
|
|
matchProfile?.video_bounds, |
|
|
|
matchProfile?.live, |
|
|
|
|
|
|
|
matchProfile?.c_match_calc_status, |
|
|
|
setIsPlayersStatsFetching, |
|
|
|
setIsPlayersStatsFetching, |
|
|
|
]) |
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
|