feat(in-512): change requests #191

Merged
andrey.dekterev merged 1 commits from in-512 into develop 3 years ago
  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_cities: 'get_cities',
get_languages: 'get_languages', get_languages: 'get_languages',
get_match_info: 'get_match_info', get_match_info: 'get_match_info',
get_match_plays: 'get_match_plays',
get_match_subscriptions: 'get_match_subscriptions', get_match_subscriptions: 'get_match_subscriptions',
get_match_watch: 'get_match_watch',
get_matches: 'get_matches', get_matches: 'get_matches',
get_objects: 'get_objects', get_objects: 'get_objects',
get_player_info: 'get_player_info', get_player_info: 'get_player_info',
@ -28,8 +30,6 @@ export const PROCEDURES = {
get_view_user_match: 'get_view_user_match', get_view_user_match: 'get_view_user_match',
landing_get_match_info: 'landing_get_match_info', landing_get_match_info: 'landing_get_match_info',
lst_c_country: 'lst_c_country', 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_actions: 'ott_match_popup_actions',
ott_match_popup_player_playlist: 'ott_match_popup_player_playlist', ott_match_popup_player_playlist: 'ott_match_popup_player_playlist',
param_lexical: 'param_lexical', param_lexical: 'param_lexical',

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

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

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

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

@ -1,14 +1,10 @@
import { import { STATS_API_URL, PROCEDURES } from 'config'
DATA_URL,
PROCEDURES,
} from 'config'
import { Episode, Episodes } from 'requests' 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 = { type Args = {
matchId: number, matchId: number,
@ -66,7 +62,8 @@ export const getMatchEvents = async ({
const config = { const config = {
body: { body: {
params: { params: {
_p_match_id: matchId, match_id: matchId,
sport_id: sportType,
}, },
proc, proc,
}, },
@ -74,7 +71,7 @@ export const getMatchEvents = async ({
const response: Response = await callApi({ const response: Response = await callApi({
config, config,
url: `${DATA_URL}/${getSportLexic(sportType)}`, url: `${STATS_API_URL}/data/stats`,
}) })
if (!response?.data) return Promise.reject(response) 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 { const proc = PROCEDURES.get_match_watch
DATA_URL,
PROCEDURES,
} from 'config'
import { callApi, getSportLexic } from 'helpers'
const proc = PROCEDURES.ott_match_popup
type Args = { type Args = {
fullMatchDuration?: number, fullMatchDuration?: number,
matchId: number, matchId: number,
selectedActions: Array<number>,
sportType: number, sportType: number,
withFullMatchDuration?: boolean, withFullMatchDuration?: boolean,
} }
@ -79,16 +72,13 @@ type Response = {
export const getMatchPlaylists = async ({ export const getMatchPlaylists = async ({
fullMatchDuration, fullMatchDuration,
matchId, matchId,
selectedActions,
sportType, sportType,
}: Args): Promise<MatchPlaylists> => { }: Args): Promise<MatchPlaylists> => {
const actions = isEmpty(selectedActions) ? null : selectedActions
const config = { const config = {
body: { body: {
params: { params: {
_p_actions: actions, match_id: matchId,
_p_match_id: matchId, sport_id: sportType,
}, },
proc, proc,
}, },
@ -102,7 +92,7 @@ export const getMatchPlaylists = async ({
try { try {
const playlist: Response = await callApi({ const playlist: Response = await callApi({
config, config,
url: `${DATA_URL}/${getSportLexic(sportType)}`, url: `${STATS_API_URL}/data/stats`,
}) })
if (playlist.data) { if (playlist.data) {
return { ...playlist.data, full_game } return { ...playlist.data, full_game }

Loading…
Cancel
Save