refactor(2051): show match status from proc ott_match_popup

keep-around/d794ec2ab05109b936f11eafa2f3d3f8ffaa312b
Mirlan 4 years ago committed by Макситалиев Мирлан
parent d82edaf67b
commit d794ec2ab0
  1. 23
      src/features/MatchPage/components/MatchProfileCard/helpers.tsx
  2. 26
      src/features/MatchPage/components/MatchProfileCard/index.tsx
  3. 5
      src/features/MatchPage/helpers/buildPlaylists.tsx
  4. 2
      src/features/MatchPage/index.tsx
  5. 1
      src/features/MatchPage/types.tsx
  6. 11
      src/requests/getMatchPlaylists.tsx

@ -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 ''
}
}

@ -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 type { MatchInfo } from 'requests/getMatchInfo'
import { ProfileTypes } from 'config' import { ProfileTypes } from 'config'
import { useMatchSwitchesStore } from 'features/MatchSwitches' import { useMatchSwitchesStore } from 'features/MatchSwitches'
import { Name } from 'features/Name' import { Name } from 'features/Name'
import { T9n } from 'features/T9n' import { useMatchPopupStore } from 'features/MatchPopup'
import { usePageParams } from 'hooks/usePageParams' import { usePageParams } from 'hooks/usePageParams'
import { getMatchStatus } from './helpers'
import { import {
Wrapper, Wrapper,
Team, Team,
@ -24,14 +19,13 @@ import {
} from './styled' } from './styled'
type Props = { type Props = {
events: Events,
profile: MatchInfo, profile: MatchInfo,
} }
export const MatchProfileCard = ({ events, profile }: Props) => { export const MatchProfileCard = ({ profile }: Props) => {
const { sportType } = usePageParams() const { sportType } = usePageParams()
const { isScoreHidden } = useMatchSwitchesStore() const { isScoreHidden } = useMatchSwitchesStore()
const lastEvent = last(events) const { matchPlaylists } = useMatchPopupStore()
if (!profile) return <Wrapper /> if (!profile) return <Wrapper />
@ -58,20 +52,16 @@ export const MatchProfileCard = ({ events, profile }: Props) => {
</StyledLink> </StyledLink>
</Team> </Team>
<ScoreWrapper> <ScoreWrapper>
<Score>
{ {
isScoreHidden isScoreHidden
? '-' ? '-'
: ( : `${team1.score} - ${team2.score}`
<Score>
{team1.score} - {team2.score}
</Score>
)
} }
{live && ( </Score>
{live && matchPlaylists.state && (
<MatchStatus> <MatchStatus>
{isEmpty(events) || !lastEvent {matchPlaylists.state}
? <T9n t='live' />
: getMatchStatus(sportType, lastEvent)}
</MatchStatus> </MatchStatus>
)} )}
</ScoreWrapper> </ScoreWrapper>

@ -27,8 +27,8 @@ const getMatchPlaylists = (matchPlaylists: MatchPlaylists | null): MatchPlaylist
const playlist = matchPlaylists[key] const playlist = matchPlaylists[key]
const lexic = matchPlaylists.lexics[key] const lexic = matchPlaylists.lexics[key]
return { return {
data: sortBy(playlist.data, ['h', 's']), data: sortBy(playlist?.data, ['h', 's']),
duration: playlist.dur, duration: playlist?.dur,
id: key, id: key,
lexic, lexic,
type: PlaylistTypes.MATCH, type: PlaylistTypes.MATCH,
@ -54,6 +54,7 @@ export const buildPlaylists = (matchPlaylists: MatchPlaylists | null) => {
}, },
score1: matchPlaylists?.score1 || 0, score1: matchPlaylists?.score1 || 0,
score2: matchPlaylists?.score2 || 0, score2: matchPlaylists?.score2 || 0,
state: matchPlaylists?.state,
} }
return playlists return playlists
} }

@ -24,7 +24,7 @@ const MatchPage = () => {
return ( return (
<PageWrapper> <PageWrapper>
<ProfileHeader color='rgb(0,0,0)' height={4.5}> <ProfileHeader color='rgb(0,0,0)' height={4.5}>
<MatchProfileCard events={events} profile={profile} /> <MatchProfileCard profile={profile} />
</ProfileHeader> </ProfileHeader>
<Main> <Main>
<UserFavorites /> <UserFavorites />

@ -62,4 +62,5 @@ export type Playlists = {
}, },
score1: number, score1: number,
score2: number, score2: number,
state?: string,
} }

@ -58,17 +58,16 @@ export type Lexics = {
} }
export type MatchPlaylists = { export type MatchPlaylists = {
ball_in_play: PlaylistWithDuration, ball_in_play?: PlaylistWithDuration,
color1?: string, full_game?: PlaylistWithDuration,
color2?: string, goals?: PlaylistWithDuration,
full_game: PlaylistWithDuration, highlights?: PlaylistWithDuration,
goals: PlaylistWithDuration,
highlights: PlaylistWithDuration,
lexics: Lexics, lexics: Lexics,
players1: Players, players1: Players,
players2: Players, players2: Players,
score1: number, score1: number,
score2: number, score2: number,
state?: string,
} }
type Response = { type Response = {

Loading…
Cancel
Save