fix(645): added sportTypes to matches request results in profile pages (#243)

keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
Mirlan 5 years ago committed by GitHub
parent eb5336a813
commit 38b1d62092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/features/PlayerPage/hooks.tsx
  2. 3
      src/features/TeamPage/hooks.tsx
  3. 3
      src/features/TournamentPage/hooks.tsx
  4. 3
      src/requests/getMatches/getHomeMatches.tsx
  5. 5
      src/requests/getMatches/getPlayerMatches.tsx
  6. 35
      src/requests/getMatches/getPreviews.tsx
  7. 5
      src/requests/getMatches/getTeamMatches.tsx
  8. 5
      src/requests/getMatches/getTournamentMatches.tsx
  9. 34
      src/requests/getMatches/request.tsx

@ -11,7 +11,6 @@ import { getPlayerInfo, getPlayerMatches } from 'requests'
import { useName } from 'features/Name' import { useName } from 'features/Name'
import { useLexicsStore } from 'features/LexicsStore' import { useLexicsStore } from 'features/LexicsStore'
import { addSportType } from 'features/Matches/helpers/addSportType'
import { useMatchSwitchesStore } from 'features/MatchSwitches' import { useMatchSwitchesStore } from 'features/MatchSwitches'
export const usePlayerPage = () => { export const usePlayerPage = () => {
@ -54,7 +53,7 @@ export const usePlayerPage = () => {
offset, offset,
playerId, playerId,
sportType, sportType,
}).then((matches) => addSportType(matches, sportType)), }),
[ [
playerId, playerId,
sportType, sportType,

@ -10,7 +10,6 @@ import { getTeamInfo, getTeamMatches } from 'requests'
import { useSportNameParam, usePageId } from 'hooks' import { useSportNameParam, usePageId } from 'hooks'
import { useName } from 'features/Name' import { useName } from 'features/Name'
import { addSportType } from 'features/Matches/helpers/addSportType'
import { useMatchSwitchesStore } from 'features/MatchSwitches' import { useMatchSwitchesStore } from 'features/MatchSwitches'
export const useTeamPage = () => { export const useTeamPage = () => {
@ -36,7 +35,7 @@ export const useTeamPage = () => {
offset, offset,
sportType, sportType,
teamId, teamId,
}).then((matches) => addSportType(matches, sportType)), }),
[ [
teamId, teamId,
sportType, sportType,

@ -10,7 +10,6 @@ import { getTournamentInfo, getTournamentMatches } from 'requests'
import { useSportNameParam, usePageId } from 'hooks' import { useSportNameParam, usePageId } from 'hooks'
import { useName } from 'features/Name' import { useName } from 'features/Name'
import { addSportType } from 'features/Matches/helpers/addSportType'
import { useMatchSwitchesStore } from 'features/MatchSwitches' import { useMatchSwitchesStore } from 'features/MatchSwitches'
export const useTournamentPage = () => { export const useTournamentPage = () => {
@ -36,7 +35,7 @@ export const useTournamentPage = () => {
offset, offset,
sportType, sportType,
tournamentId, tournamentId,
}).then((matches) => addSportType(matches, sportType)), }),
[ [
tournamentId, tournamentId,
sportType, sportType,

@ -4,6 +4,7 @@ import { MatchStatuses } from 'features/HeaderFilters'
import type { MatchesBySection } from './types' import type { MatchesBySection } from './types'
import { requestMatches } from './request' import { requestMatches } from './request'
import { getMatchesPreviews } from './getPreviews'
const proc = PROCEDURES.get_matches const proc = PROCEDURES.get_matches
@ -41,5 +42,5 @@ export const getHomeMatches = async ({
}, },
} }
return requestMatches(config) return requestMatches(config).then(getMatchesPreviews)
} }

@ -1,7 +1,10 @@
import { PROCEDURES, SportTypes } from 'config' import { PROCEDURES, SportTypes } from 'config'
import { addSportType } from 'features/Matches/helpers/addSportType'
import type { MatchesBySection } from './types' import type { MatchesBySection } from './types'
import { requestMatches } from './request' import { requestMatches } from './request'
import { getMatchesPreviews } from './getPreviews'
const proc = PROCEDURES.get_player_matches const proc = PROCEDURES.get_player_matches
@ -34,4 +37,6 @@ export const getPlayerMatches = async ({
} }
return requestMatches(config) return requestMatches(config)
.then((matches) => addSportType(matches, sportType))
.then(getMatchesPreviews)
} }

@ -8,7 +8,7 @@ import { getMatchesPreviewImages } from 'requests'
import { MatchStatuses } from 'features/HeaderFilters' import { MatchStatuses } from 'features/HeaderFilters'
import type { Matches } from './types' import type { MatchesBySection, Matches } from './types'
const combinePreviews = (matches: Matches, previews: Previews) => ( const combinePreviews = (matches: Matches, previews: Previews) => (
map(matches, (match) => { map(matches, (match) => {
@ -23,7 +23,7 @@ const combinePreviews = (matches: Matches, previews: Previews) => (
/** /**
* Запрашивает превью картинок матчей с видео и статус которых Завершенный * Запрашивает превью картинок матчей с видео и статус которых Завершенный
*/ */
export const getPreviews = async (matches: Matches) => { const getPreviews = async (matches: Matches) => {
const previewsData = reduce( const previewsData = reduce(
matches, matches,
(acc: PreviewsData, { (acc: PreviewsData, {
@ -48,3 +48,34 @@ export const getPreviews = async (matches: Matches) => {
const previews = await getMatchesPreviewImages(previewsData) const previews = await getMatchesPreviewImages(previewsData)
return combinePreviews(matches, previews) return combinePreviews(matches, previews)
} }
export const getMatchesPreviews = async (matches: MatchesBySection) => {
if (matches.isVideoSections) {
const [
broadcast,
features,
highlights,
] = await Promise.all(
[
getPreviews(matches.broadcast),
getPreviews(matches.features),
getPreviews(matches.highlights),
],
)
return {
...matches,
broadcast,
features,
highlights,
}
}
const broadcast = await getPreviews(matches.broadcast)
return {
...matches,
broadcast,
features: [],
highlights: [],
}
}

@ -1,6 +1,9 @@
import { PROCEDURES, SportTypes } from 'config' import { PROCEDURES, SportTypes } from 'config'
import { addSportType } from 'features/Matches/helpers/addSportType'
import type { MatchesBySection } from './types' import type { MatchesBySection } from './types'
import { getMatchesPreviews } from './getPreviews'
import { requestMatches } from './request' import { requestMatches } from './request'
const proc = PROCEDURES.get_team_matches const proc = PROCEDURES.get_team_matches
@ -34,4 +37,6 @@ export const getTeamMatches = async ({
} }
return requestMatches(config) return requestMatches(config)
.then((matches) => addSportType(matches, sportType))
.then(getMatchesPreviews)
} }

@ -1,6 +1,9 @@
import { PROCEDURES, SportTypes } from 'config' import { PROCEDURES, SportTypes } from 'config'
import { addSportType } from 'features/Matches/helpers/addSportType'
import type { MatchesBySection } from './types' import type { MatchesBySection } from './types'
import { getMatchesPreviews } from './getPreviews'
import { requestMatches } from './request' import { requestMatches } from './request'
const proc = PROCEDURES.get_tournament_matches const proc = PROCEDURES.get_tournament_matches
@ -34,4 +37,6 @@ export const getTournamentMatches = async ({
} }
return requestMatches(config) return requestMatches(config)
.then((matches) => addSportType(matches, sportType))
.then(getMatchesPreviews)
} }

@ -2,7 +2,6 @@ import { DATA_URL } from 'config'
import { callApi } from 'helpers' import { callApi } from 'helpers'
import type { MatchesResponse, MatchesBySection } from './types' import type { MatchesResponse, MatchesBySection } from './types'
import { getPreviews } from './getPreviews'
type Config = { type Config = {
body: { body: {
@ -20,36 +19,11 @@ export const requestMatches = async (config: Config): Promise<MatchesBySection>
url: DATA_URL, url: DATA_URL,
}) })
const isVideoSections = Boolean(is_video_sections)
if (isVideoSections) {
const [
broadcast,
features,
highlights,
] = await Promise.all(
[
getPreviews(data.broadcast),
getPreviews(data.features),
getPreviews(data.highlights),
],
)
return {
broadcast,
features,
hasNextPage: Boolean(show),
highlights,
isVideoSections,
}
}
const broadcast = await getPreviews(data.broadcast)
return { return {
broadcast, broadcast: data.broadcast || [],
features: [], features: data.features || [],
hasNextPage: Boolean(show), hasNextPage: Boolean(show),
highlights: [], highlights: data.highlights || [],
isVideoSections, isVideoSections: Boolean(is_video_sections),
} }
} }

Loading…
Cancel
Save