You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
spa_instat_tv/src/features/MatchCard/CardFrontside/index.tsx

167 lines
4.6 KiB

import type { KeyboardEvent } from 'react'
import { useLocation, useRouteMatch } from 'react-router'
import getUnixTime from 'date-fns/getUnixTime'
import { ProfileTypes, PAGES } from 'config'
import type { Match } from 'features/Matches'
import { SportIcon } from 'components/SportIcon/SportIcon'
import { useMatchSwitchesStore } from 'features/MatchSwitches'
import { useName } from 'features/Name'
import { T9n } from 'features/T9n'
import { MatchAccess } from 'features/Matches/helpers/getMatchClickAction'
import { useUserFavoritesStore } from 'features/UserFavorites/store'
import { NoAccessMessage } from '../NoAccessMessage'
import {
CardWrapperOuter,
CardWrapper,
Info,
LiveSign,
MatchDate,
MatchTimeInfo,
Preview,
PreviewWrapper,
Score,
Team,
TeamName,
Teams,
Time,
TournamentName,
TeamLogos,
TeamLogo,
BuyMatchBadge,
CountryFlag,
SecondaryInfo,
FavoriteSign,
NameSignWrapper,
HoverFrame,
} from '../styled'
import { useCardPreview } from './hooks'
type Props = {
match: Match,
onClick: () => void,
onKeyPress: (e: KeyboardEvent<HTMLLIElement>) => void,
}
export const CardFrontside = ({
match,
onClick,
onKeyPress,
}: Props) => {
const location = useLocation()
const {
access,
date,
formattedDate,
live,
preview,
previewURL,
sportType,
team1,
team2,
time,
tournament,
} = match
const isHomePage = useRouteMatch(PAGES.home)?.isExact
const isMatchPage = location.pathname.includes(PAGES.match)
const tournamentName = useName(tournament)
const { isInFavorites } = useUserFavoritesStore()
const { isScoreHidden } = useMatchSwitchesStore()
const isInFuture = getUnixTime(date) > getUnixTime(new Date())
const showScore = !(
isInFuture
|| isScoreHidden
) || (live && !isScoreHidden)
const tournamentInFavorites = isInFavorites(ProfileTypes.TOURNAMENTS, tournament.id)
const team1InFavorites = isInFavorites(ProfileTypes.TEAMS, team1.id)
const team2InFavorites = isInFavorites(ProfileTypes.TEAMS, team2.id)
const { previewImage } = useCardPreview({
preview,
previewURL,
})
return (
<CardWrapperOuter
onClick={onClick}
onKeyPress={onKeyPress}
>
<CardWrapper>
<HoverFrame />
<PreviewWrapper>
{previewImage && (
<Preview
title={tournamentName}
src={previewImage}
/>
)}
{access === MatchAccess.NoCountryAccess
? <NoAccessMessage />
: (
<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>
)}
{access === MatchAccess.CanBuyMatch && <BuyMatchBadge />}
<MatchTimeInfo>
<MatchDate isHomePage={isHomePage}>
{isHomePage || isMatchPage ? null : formattedDate}
<Time>{time}</Time>
</MatchDate>
{live && (
<LiveSign>
<T9n t='live' />
</LiveSign>
)}
</MatchTimeInfo>
</PreviewWrapper>
<Info>
<Teams>
<Team>
<NameSignWrapper>
<TeamName nameObj={team1} />
{team1InFavorites && <FavoriteSign />}
</NameSignWrapper>
{showScore && <Score>{team1.score}</Score>}
</Team>
<Team>
<NameSignWrapper>
<TeamName nameObj={team2} />
{team2InFavorites && <FavoriteSign />}
</NameSignWrapper>
{showScore && <Score>{team2.score}</Score>}
</Team>
</Teams>
<SecondaryInfo>
<SportIcon sport={sportType} />
<CountryFlag src={`https://instatscout.com/images/flags/48/${match.countryId}.png`} />
{tournament && (
<NameSignWrapper>
<TournamentName title={tournamentName}>
{tournamentName}
</TournamentName>
{tournamentInFavorites && <FavoriteSign marginLeft={12} />}
</NameSignWrapper>
)}
</SecondaryInfo>
</Info>
</CardWrapper>
</CardWrapperOuter>
)
}