refactor(563): removed match stream_status property usage (#246)

keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
Mirlan 5 years ago committed by GitHub
parent 38b1d62092
commit 76ebedfabb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/features/MatchCard/CardBackSide/index.tsx
  2. 40
      src/features/MatchCard/CardFinished/index.tsx
  3. 9
      src/features/MatchCard/CardFrontSide/index.tsx
  4. 40
      src/features/MatchCard/CardLive/index.tsx
  5. 57
      src/features/MatchCard/CardLiveHover/index.tsx
  6. 101
      src/features/MatchCard/CardSoon/index.tsx
  7. 16
      src/features/MatchCard/hooks.tsx
  8. 38
      src/features/MatchCard/index.tsx
  9. 9
      src/features/Matches/helpers/prepareMatches.tsx
  10. 5
      src/requests/getMatches/getPreviews.tsx
  11. 8
      src/requests/getMatches/types.tsx

@ -14,7 +14,7 @@ import {
Rows, Rows,
} from '../styled' } from '../styled'
type CardFinishedHoverProps = { type Props = {
match: Match, match: Match,
onClose: () => void, onClose: () => void,
} }
@ -23,14 +23,13 @@ const stopProp = (e: MouseEvent<HTMLDivElement>) => {
e.stopPropagation() e.stopPropagation()
} }
export const CardFinishedHover = ({ export const CardBackside = ({
match: { match: {
hasVideo,
id, id,
sportName, sportName,
}, },
onClose, onClose,
}: CardFinishedHoverProps) => ( }: Props) => (
<OutsideClick onClick={onClose}> <OutsideClick onClick={onClose}>
<CardHoverWrapper onClick={onClose}> <CardHoverWrapper onClick={onClose}>
<CardHoverInner> <CardHoverInner>

@ -1,40 +0,0 @@
import type { Match } from 'features/Matches'
import { useCard } from '../hooks'
import { MatchInfoCard } from '../MatchInfoCard'
import { CardFinishedHover } from '../CardFinishedHover'
type CardFinishedProps = {
match: Match,
showSportName?: boolean,
}
export const CardFinished = ({
match,
showSportName,
}: CardFinishedProps) => {
const {
close,
flipCard,
isOpen,
onKeyPress,
} = useCard(match)
if (isOpen) {
return (
<CardFinishedHover
match={match}
onClose={close}
/>
)
}
return (
<MatchInfoCard
match={match}
showSportName={showSportName}
onClick={flipCard}
onKeyPress={onKeyPress}
/>
)
}

@ -32,12 +32,11 @@ type Props = {
showSportName?: boolean, showSportName?: boolean,
} }
export const MatchInfoCard = ({ export const CardFrontside = ({
match: { match: {
accessibleBySubscription, accessibleBySubscription,
accessibleInUsersCountry, accessibleInUsersCountry,
date, date,
hasVideo,
preview, preview,
sportType, sportType,
team1, team1,
@ -59,7 +58,7 @@ export const MatchInfoCard = ({
> >
<PreviewWrapper> <PreviewWrapper>
{ {
hasVideo preview
? ( ? (
<Preview <Preview
alt={tournamentName} alt={tournamentName}
@ -108,11 +107,11 @@ export const MatchInfoCard = ({
<Teams> <Teams>
<Team> <Team>
<TeamName nameObj={team1} /> <TeamName nameObj={team1} />
{!isScoreHidden && <Score>{team1.score}</Score>} {(!isScoreHidden && team1.score) && <Score>{team1.score}</Score>}
</Team> </Team>
<Team> <Team>
<TeamName nameObj={team2} /> <TeamName nameObj={team2} />
{!isScoreHidden && <Score>{team2.score}</Score>} {(!isScoreHidden && team2.score) && <Score>{team2.score}</Score>}
</Team> </Team>
</Teams> </Teams>
</Info> </Info>

@ -1,40 +0,0 @@
import type { Match } from 'features/Matches'
import { useCard } from '../hooks'
import { MatchInfoCard } from '../MatchInfoCard'
import { CardLiveHover } from '../CardLiveHover'
type CardLiveProps = {
match: Match,
showSportName?: boolean,
}
export const CardLive = ({
match,
showSportName,
}: CardLiveProps) => {
const {
close,
flipCard,
isOpen,
onKeyPress,
} = useCard(match)
if (isOpen) {
return (
<CardLiveHover
match={match}
onClose={close}
/>
)
}
return (
<MatchInfoCard
match={match}
showSportName={showSportName}
onClick={flipCard}
onKeyPress={onKeyPress}
/>
)
}

@ -1,57 +0,0 @@
import type { MouseEvent } from 'react'
import { Link } from 'react-router-dom'
import type { Match } from 'features/Matches'
import { RESUME_KEY } from 'features/MatchPage/hooks/useLastPlayPosition'
import { OutsideClick } from 'features/OutsideClick'
import {
CardHoverInner,
CardHoverTitle,
CardHoverWrapper,
MoreVideo,
Row,
Rows,
} from '../styled'
type CardLiveHoverProps = {
match: Match,
onClose: () => void,
}
const stopProp = (e: MouseEvent<HTMLDivElement>) => {
e.stopPropagation()
}
export const CardLiveHover = ({
match: {
id,
sportName,
},
onClose,
}: CardLiveHoverProps) => (
<OutsideClick onClick={onClose}>
<CardHoverWrapper onClick={onClose}>
<CardHoverInner>
<CardHoverTitle t='match_video' />
<Rows onClick={stopProp}>
<Row>
<Link to={`/${sportName}/matches/${id}`}>
<MoreVideo t='watch_now' />
</Link>
<Link to={`/${sportName}/matches/${id}`}>
<MoreVideo t='watch_from_beginning' />
</Link>
</Row>
<Row>
<Link to={`/${sportName}/matches/${id}?${RESUME_KEY}=true`}>
<MoreVideo t='watch_from_last_pause' />
</Link>
</Row>
</Rows>
</CardHoverInner>
</CardHoverWrapper>
</OutsideClick>
)

@ -1,101 +0,0 @@
import styled from 'styled-components/macro'
import { ProfileTypes } from 'config'
import type { Match } from 'features/Matches'
import { SportName } from 'features/Common'
import { useName } from 'features/Name'
import { NoAccessMessage } from '../NoAccessMessage'
import {
MatchDate,
CardWrapper as CommonCardWrapper,
Time,
Info,
PreviewWrapper,
Team,
TeamName as CommonTeamName,
Teams,
TournamentName,
TeamLogos,
TeamLogo,
BuyMatchButton,
} from '../styled'
const CardWrapper = styled(CommonCardWrapper)`
cursor: pointer;
`
const TeamName = styled(CommonTeamName)`
max-width: none;
`
type CardSoonProps = {
match: Match,
showSportName?: boolean,
}
export const CardSoon = ({
match: {
accessibleBySubscription,
accessibleInUsersCountry,
date,
sportType,
team1,
team2,
time,
tournament,
},
showSportName,
}: CardSoonProps) => {
const tournamentName = useName(tournament)
return (
<CardWrapper>
<PreviewWrapper>
<TeamLogos>
<TeamLogo
id={team1.id}
nameAsTitle
altNameObj={team1}
sportType={sportType}
profileType={ProfileTypes.TEAMS}
/>
<TeamLogo
id={team2.id}
nameAsTitle
altNameObj={team2}
sportType={sportType}
profileType={ProfileTypes.TEAMS}
/>
</TeamLogos>
{!accessibleBySubscription && <BuyMatchButton />}
{(accessibleBySubscription && !accessibleInUsersCountry)
? <NoAccessMessage />
: (
<MatchDate>
{date}
<Time>
{time}
</Time>
</MatchDate>
)}
</PreviewWrapper>
<Info>
{showSportName && <SportName sport={sportType} />}
{tournamentName && (
<TournamentName title={tournamentName}>
{tournamentName}
</TournamentName>
)}
<Teams>
<Team>
<TeamName nameObj={team1} />
</Team>
<Team>
<TeamName nameObj={team2} />
</Team>
</Teams>
</Info>
</CardWrapper>
)
}

@ -5,28 +5,18 @@ import { useToggle } from 'hooks'
import type { Match } from 'features/Matches' import type { Match } from 'features/Matches'
export const useCard = ({ export const useCard = (match: Match) => {
accessibleBySubscription,
accessibleInUsersCountry,
hasVideo,
}: Match) => {
const { const {
close, close,
isOpen, isOpen,
open, open,
} = useToggle() } = useToggle()
const isClickable = (
hasVideo
&& accessibleInUsersCountry
&& accessibleBySubscription
)
const flipCard = useCallback(() => { const flipCard = useCallback(() => {
if (isClickable) { if (match.isClickable) {
open() open()
} }
}, [isClickable, open]) }, [match, open])
const onKeyPress = useCallback((e: KeyboardEvent<HTMLLIElement>) => { const onKeyPress = useCallback((e: KeyboardEvent<HTMLLIElement>) => {
if (e.key === 'Enter') { if (e.key === 'Enter') {

@ -3,29 +3,39 @@ import { useRouteMatch } from 'react-router'
import { PAGES } from 'config' import { PAGES } from 'config'
import type { Match } from 'features/Matches' import type { Match } from 'features/Matches'
import { MatchStatuses } from 'features/HeaderFilters'
import { CardLive } from './CardLive' import { CardFrontside } from './CardFrontside'
import { CardFinished } from './CardFinished' import { CardBackside } from './CardBackside'
import { CardSoon } from './CardSoon' import { useCard } from './hooks'
type MatchCardProps = { type Props = {
match: Match, match: Match,
} }
const cards = { export const MatchCard = ({ match }: Props) => {
[MatchStatuses.Finished]: CardFinished,
[MatchStatuses.Live]: CardLive,
[MatchStatuses.Soon]: CardSoon,
}
export const MatchCard = ({ match }: MatchCardProps) => {
const isHomePage = useRouteMatch(PAGES.home)?.isExact const isHomePage = useRouteMatch(PAGES.home)?.isExact
const Card = cards[match.streamStatus] const {
close,
flipCard,
isOpen,
onKeyPress,
} = useCard(match)
if (isOpen) {
return (
<CardBackside
match={match}
onClose={close}
/>
)
}
return ( return (
<Card <CardFrontside
match={match} match={match}
showSportName={isHomePage} showSportName={isHomePage}
onClick={flipCard}
onKeyPress={onKeyPress}
/> />
) )
} }

@ -10,9 +10,10 @@ const prepareMatch = ({
date, date,
has_video, has_video,
id, id,
live,
preview, preview,
sport, sport,
stream_status, storage,
sub, sub,
team1, team1,
team2, team2,
@ -23,10 +24,14 @@ const prepareMatch = ({
date: format(new Date(date), 'dd.MM.yy'), date: format(new Date(date), 'dd.MM.yy'),
hasVideo: has_video, hasVideo: has_video,
id, id,
isClickable: (sub && access && (
has_video
|| live
|| storage
)),
preview, preview,
sportName: getSportLexic(sport), sportName: getSportLexic(sport),
sportType: sport, sportType: sport,
streamStatus: stream_status,
team1, team1,
team2, team2,
time: format(new Date(date), 'HH:mm'), time: format(new Date(date), 'HH:mm'),

@ -6,8 +6,6 @@ import map from 'lodash/map'
import type { PreviewsData, Previews } from 'requests' import type { PreviewsData, Previews } from 'requests'
import { getMatchesPreviewImages } from 'requests' import { getMatchesPreviewImages } from 'requests'
import { MatchStatuses } from 'features/HeaderFilters'
import type { MatchesBySection, Matches } from './types' import type { MatchesBySection, Matches } from './types'
const combinePreviews = (matches: Matches, previews: Previews) => ( const combinePreviews = (matches: Matches, previews: Previews) => (
@ -30,9 +28,8 @@ const getPreviews = async (matches: Matches) => {
has_video, has_video,
id, id,
sport, sport,
stream_status,
}) => { }) => {
if (has_video && stream_status === MatchStatuses.Finished) { if (has_video) {
acc.push({ acc.push({
match_id: id, match_id: id,
sport_id: sport, sport_id: sport,

@ -1,7 +1,5 @@
import { SportTypes } from 'config' import { SportTypes } from 'config'
import { MatchStatuses } from 'features/HeaderFilters'
type Tournament = { type Tournament = {
id: number, id: number,
name_eng: string, name_eng: string,
@ -18,12 +16,16 @@ export type Team = {
export type Match = { export type Match = {
access: boolean, access: boolean,
date: string, date: string,
/** наличие mp4 видео */
has_video: boolean, has_video: boolean,
id: number, id: number,
/** наличие hls стрима */
live: boolean,
preview?: string, preview?: string,
round_id: number | null, round_id: number | null,
sport: SportTypes, sport: SportTypes,
stream_status: MatchStatuses, /** наличие завершенного hls стрима */
storage: boolean,
sub: boolean, sub: boolean,
team1: Team, team1: Team,
team2: Team, team2: Team,

Loading…
Cancel
Save