feat(640): request and display match previews (#241)
parent
3de4adb0fc
commit
eb5336a813
|
Before Width: | Height: | Size: 122 KiB |
@ -0,0 +1,50 @@ |
||||
import isEmpty from 'lodash/isEmpty' |
||||
import reduce from 'lodash/reduce' |
||||
import find from 'lodash/find' |
||||
import map from 'lodash/map' |
||||
|
||||
import type { PreviewsData, Previews } from 'requests' |
||||
import { getMatchesPreviewImages } from 'requests' |
||||
|
||||
import { MatchStatuses } from 'features/HeaderFilters' |
||||
|
||||
import type { Matches } from './types' |
||||
|
||||
const combinePreviews = (matches: Matches, previews: Previews) => ( |
||||
map(matches, (match) => { |
||||
const preview = find( |
||||
previews, |
||||
{ match_id: match.id, sport_id: match.sport }, |
||||
)?.preview |
||||
return preview ? { ...match, preview } : match |
||||
}) |
||||
) |
||||
|
||||
/** |
||||
* Запрашивает превью картинок матчей с видео и статус которых Завершенный |
||||
*/ |
||||
export const getPreviews = async (matches: Matches) => { |
||||
const previewsData = reduce( |
||||
matches, |
||||
(acc: PreviewsData, { |
||||
has_video, |
||||
id, |
||||
sport, |
||||
stream_status, |
||||
}) => { |
||||
if (has_video && stream_status === MatchStatuses.Finished) { |
||||
acc.push({ |
||||
match_id: id, |
||||
sport_id: sport, |
||||
}) |
||||
} |
||||
return acc |
||||
}, |
||||
[], |
||||
) |
||||
|
||||
if (isEmpty(previewsData)) return matches |
||||
|
||||
const previews = await getMatchesPreviewImages(previewsData) |
||||
return combinePreviews(matches, previews) |
||||
} |
||||
@ -0,0 +1,30 @@ |
||||
import { API_ROOT, SportTypes } from 'config' |
||||
import { callApi } from 'helpers' |
||||
|
||||
type Match = { |
||||
match_id: number, |
||||
sport_id: SportTypes, |
||||
} |
||||
|
||||
export type PreviewsData = Array<Match> |
||||
|
||||
type Preview = { |
||||
match_id: number, |
||||
preview: string, |
||||
sport_id: SportTypes, |
||||
} |
||||
|
||||
export type Previews = Array<Preview> |
||||
|
||||
export const getMatchesPreviewImages = async (matches: PreviewsData) => { |
||||
const config = { |
||||
body: matches, |
||||
} |
||||
|
||||
const previews: Previews = await callApi({ |
||||
config, |
||||
url: `${API_ROOT}/videoapi/preview`, |
||||
}) |
||||
|
||||
return previews |
||||
} |
||||
Loading…
Reference in new issue