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 { useLexicsStore } from 'features/LexicsStore'
import { addSportType } from 'features/Matches/helpers/addSportType'
import { useMatchSwitchesStore } from 'features/MatchSwitches'
export const usePlayerPage = () => {
@ -54,7 +53,7 @@ export const usePlayerPage = () => {
offset,
playerId,
sportType,
}).then((matches) => addSportType(matches, sportType)),
}),
[
playerId,
sportType,

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

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

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

@ -8,7 +8,7 @@ import { getMatchesPreviewImages } from 'requests'
import { MatchStatuses } from 'features/HeaderFilters'
import type { Matches } from './types'
import type { MatchesBySection, Matches } from './types'
const combinePreviews = (matches: Matches, previews: Previews) => (
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(
matches,
(acc: PreviewsData, {
@ -48,3 +48,34 @@ export const getPreviews = async (matches: Matches) => {
const previews = await getMatchesPreviewImages(previewsData)
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 { addSportType } from 'features/Matches/helpers/addSportType'
import type { MatchesBySection } from './types'
import { getMatchesPreviews } from './getPreviews'
import { requestMatches } from './request'
const proc = PROCEDURES.get_team_matches
@ -34,4 +37,6 @@ export const getTeamMatches = async ({
}
return requestMatches(config)
.then((matches) => addSportType(matches, sportType))
.then(getMatchesPreviews)
}

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

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

Loading…
Cancel
Save