From d794ec2ab05109b936f11eafa2f3d3f8ffaa312b Mon Sep 17 00:00:00 2001 From: Mirlan Date: Tue, 7 Dec 2021 20:59:56 +0600 Subject: [PATCH] refactor(2051): show match status from proc ott_match_popup --- .../components/MatchProfileCard/helpers.tsx | 23 ------------- .../components/MatchProfileCard/index.tsx | 34 +++++++------------ .../MatchPage/helpers/buildPlaylists.tsx | 5 +-- src/features/MatchPage/index.tsx | 2 +- src/features/MatchPage/types.tsx | 1 + src/requests/getMatchPlaylists.tsx | 11 +++--- 6 files changed, 22 insertions(+), 54 deletions(-) delete mode 100644 src/features/MatchPage/components/MatchProfileCard/helpers.tsx diff --git a/src/features/MatchPage/components/MatchProfileCard/helpers.tsx b/src/features/MatchPage/components/MatchProfileCard/helpers.tsx deleted file mode 100644 index 7980a686..00000000 --- a/src/features/MatchPage/components/MatchProfileCard/helpers.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { SportTypes } from 'config' - -import type { Event } from 'requests' - -// Здесь в дальнейшем будет расширена логика получения статуса матча -// для каждого вида спорта, как только решат как это сделать на бэке - -const getBasketballStatus = (event: Event) => `Q${event.h} ${event.c}` -const getFootballStatus = (event: Event) => `H${event.h} ${event.c}` -const getHockeyStatus = (event: Event) => `P${event.h} ${event.c}` - -export const getMatchStatus = (sportType: SportTypes, lastEvent: Event) => { - switch (sportType) { - case SportTypes.BASKETBALL: - return getBasketballStatus(lastEvent) - case SportTypes.FOOTBALL: - return getFootballStatus(lastEvent) - case SportTypes.HOCKEY: - return getHockeyStatus(lastEvent) - default: - return '' - } -} diff --git a/src/features/MatchPage/components/MatchProfileCard/index.tsx b/src/features/MatchPage/components/MatchProfileCard/index.tsx index 8a0a2848..e61f19ee 100644 --- a/src/features/MatchPage/components/MatchProfileCard/index.tsx +++ b/src/features/MatchPage/components/MatchProfileCard/index.tsx @@ -1,18 +1,13 @@ -import isEmpty from 'lodash/isEmpty' -import last from 'lodash/last' - -import type { Events } from 'requests/getMatchEvents' import type { MatchInfo } from 'requests/getMatchInfo' import { ProfileTypes } from 'config' import { useMatchSwitchesStore } from 'features/MatchSwitches' import { Name } from 'features/Name' -import { T9n } from 'features/T9n' +import { useMatchPopupStore } from 'features/MatchPopup' import { usePageParams } from 'hooks/usePageParams' -import { getMatchStatus } from './helpers' import { Wrapper, Team, @@ -24,14 +19,13 @@ import { } from './styled' type Props = { - events: Events, profile: MatchInfo, } -export const MatchProfileCard = ({ events, profile }: Props) => { +export const MatchProfileCard = ({ profile }: Props) => { const { sportType } = usePageParams() const { isScoreHidden } = useMatchSwitchesStore() - const lastEvent = last(events) + const { matchPlaylists } = useMatchPopupStore() if (!profile) return @@ -58,20 +52,16 @@ export const MatchProfileCard = ({ events, profile }: Props) => { - { - isScoreHidden - ? '-' - : ( - - {team1.score} - {team2.score} - - ) - } - {live && ( + + { + isScoreHidden + ? '-' + : `${team1.score} - ${team2.score}` + } + + {live && matchPlaylists.state && ( - {isEmpty(events) || !lastEvent - ? - : getMatchStatus(sportType, lastEvent)} + {matchPlaylists.state} )} diff --git a/src/features/MatchPage/helpers/buildPlaylists.tsx b/src/features/MatchPage/helpers/buildPlaylists.tsx index 57871dc4..89b17c0d 100644 --- a/src/features/MatchPage/helpers/buildPlaylists.tsx +++ b/src/features/MatchPage/helpers/buildPlaylists.tsx @@ -27,8 +27,8 @@ const getMatchPlaylists = (matchPlaylists: MatchPlaylists | null): MatchPlaylist const playlist = matchPlaylists[key] const lexic = matchPlaylists.lexics[key] return { - data: sortBy(playlist.data, ['h', 's']), - duration: playlist.dur, + data: sortBy(playlist?.data, ['h', 's']), + duration: playlist?.dur, id: key, lexic, type: PlaylistTypes.MATCH, @@ -54,6 +54,7 @@ export const buildPlaylists = (matchPlaylists: MatchPlaylists | null) => { }, score1: matchPlaylists?.score1 || 0, score2: matchPlaylists?.score2 || 0, + state: matchPlaylists?.state, } return playlists } diff --git a/src/features/MatchPage/index.tsx b/src/features/MatchPage/index.tsx index 50139bb2..e1293043 100644 --- a/src/features/MatchPage/index.tsx +++ b/src/features/MatchPage/index.tsx @@ -24,7 +24,7 @@ const MatchPage = () => { return ( - +
diff --git a/src/features/MatchPage/types.tsx b/src/features/MatchPage/types.tsx index 70249cce..51d202cf 100644 --- a/src/features/MatchPage/types.tsx +++ b/src/features/MatchPage/types.tsx @@ -62,4 +62,5 @@ export type Playlists = { }, score1: number, score2: number, + state?: string, } diff --git a/src/requests/getMatchPlaylists.tsx b/src/requests/getMatchPlaylists.tsx index cb0538f5..9c395904 100644 --- a/src/requests/getMatchPlaylists.tsx +++ b/src/requests/getMatchPlaylists.tsx @@ -58,17 +58,16 @@ export type Lexics = { } export type MatchPlaylists = { - ball_in_play: PlaylistWithDuration, - color1?: string, - color2?: string, - full_game: PlaylistWithDuration, - goals: PlaylistWithDuration, - highlights: PlaylistWithDuration, + ball_in_play?: PlaylistWithDuration, + full_game?: PlaylistWithDuration, + goals?: PlaylistWithDuration, + highlights?: PlaylistWithDuration, lexics: Lexics, players1: Players, players2: Players, score1: number, score2: number, + state?: string, } type Response = {