feat(in-512): change requests

pull/191/head
Ruslan Khayrullin 3 years ago
parent 6a286d46dd
commit 5815744de4
  1. 4
      src/config/procedures.tsx
  2. 32
      src/features/MatchPage/store/hooks/useMatchData.tsx
  3. 1
      src/features/MatchPage/store/hooks/useMatchPlaylists.tsx
  4. 1
      src/features/MatchPopup/store/hooks/index.tsx
  5. 2
      src/hooks/useInterval.tsx
  6. 15
      src/requests/getMatchEvents.tsx
  7. 22
      src/requests/getMatchPlaylists.tsx

@ -3,7 +3,9 @@ export const PROCEDURES = {
get_cities: 'get_cities',
get_languages: 'get_languages',
get_match_info: 'get_match_info',
get_match_plays: 'get_match_plays',
get_match_subscriptions: 'get_match_subscriptions',
get_match_watch: 'get_match_watch',
get_matches: 'get_matches',
get_objects: 'get_objects',
get_player_info: 'get_player_info',
@ -28,8 +30,6 @@ export const PROCEDURES = {
get_view_user_match: 'get_view_user_match',
landing_get_match_info: 'landing_get_match_info',
lst_c_country: 'lst_c_country',
ott_match_events: 'ott_match_events',
ott_match_popup: 'ott_match_popup',
ott_match_popup_actions: 'ott_match_popup_actions',
ott_match_popup_player_playlist: 'ott_match_popup_player_playlist',
param_lexical: 'param_lexical',

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

@ -67,7 +67,6 @@ export const useMatchPlaylists = ({
getMatchPlaylists({
fullMatchDuration,
matchId: id,
selectedActions: [],
sportType,
}).then(fetchLexics)
.then(buildPlaylists)

@ -95,7 +95,6 @@ export const useMatchPopup = () => {
getMatchPlaylists({
fullMatchDuration,
matchId: id,
selectedActions: [],
sportType,
withFullMatchDuration,
}).then(fetchLexics)

@ -31,7 +31,7 @@ export const useInterval = ({
const id = setInterval(savedCallback.current, intervalDuration)
return () => clearInterval(id)
}, [isRunning, intervalDuration])
}, [isRunning, intervalDuration, callback])
return { start, stop }
}

@ -1,14 +1,10 @@
import {
DATA_URL,
PROCEDURES,
} from 'config'
import { STATS_API_URL, PROCEDURES } from 'config'
import { Episode, Episodes } from 'requests'
import { callApi, getSportLexic } from 'helpers'
import { callApi } from 'helpers'
const proc = PROCEDURES.ott_match_events
const proc = PROCEDURES.get_match_plays
type Args = {
matchId: number,
@ -66,7 +62,8 @@ export const getMatchEvents = async ({
const config = {
body: {
params: {
_p_match_id: matchId,
match_id: matchId,
sport_id: sportType,
},
proc,
},
@ -74,7 +71,7 @@ export const getMatchEvents = async ({
const response: Response = await callApi({
config,
url: `${DATA_URL}/${getSportLexic(sportType)}`,
url: `${STATS_API_URL}/data/stats`,
})
if (!response?.data) return Promise.reject(response)

@ -1,18 +1,11 @@
import isEmpty from 'lodash/isEmpty'
import { PROCEDURES, STATS_API_URL } from 'config'
import { callApi } from 'helpers'
import {
DATA_URL,
PROCEDURES,
} from 'config'
import { callApi, getSportLexic } from 'helpers'
const proc = PROCEDURES.ott_match_popup
const proc = PROCEDURES.get_match_watch
type Args = {
fullMatchDuration?: number,
matchId: number,
selectedActions: Array<number>,
sportType: number,
withFullMatchDuration?: boolean,
}
@ -79,16 +72,13 @@ type Response = {
export const getMatchPlaylists = async ({
fullMatchDuration,
matchId,
selectedActions,
sportType,
}: Args): Promise<MatchPlaylists> => {
const actions = isEmpty(selectedActions) ? null : selectedActions
const config = {
body: {
params: {
_p_actions: actions,
_p_match_id: matchId,
match_id: matchId,
sport_id: sportType,
},
proc,
},
@ -102,7 +92,7 @@ export const getMatchPlaylists = async ({
try {
const playlist: Response = await callApi({
config,
url: `${DATA_URL}/${getSportLexic(sportType)}`,
url: `${STATS_API_URL}/data/stats`,
})
if (playlist.data) {
return { ...playlist.data, full_game }

Loading…
Cancel
Save