feat(ott-2268): add redirect to tournament page if match didn't started

keep-around/a8ff5fff2c61c0392b2244fb4f614e891a790777
nevainero 4 years ago
parent 2b4443a47f
commit a8ff5fff2c
  1. 9
      src/features/MatchPage/hooks/useMatchProfile.tsx
  2. 30
      src/features/MatchPage/index.tsx

@ -9,6 +9,8 @@ import { getMatchInfo } from 'requests'
import { usePageParams } from 'hooks/usePageParams'
import { parseDate } from 'helpers/parseDate'
import type { Playlists } from '../types'
import { useMatchData } from './useMatchData'
@ -46,8 +48,15 @@ export const useMatchProfile = () => {
[matchProfile, matchPlaylists],
)
const isStarted = useMemo(() => (
profile?.date
? parseDate(profile.date) < new Date()
: true
), [profile?.date])
return {
events,
isStarted,
profile,
}
}

@ -1,3 +1,5 @@
import { useHistory } from 'react-router'
import { usePageLogger } from 'hooks/usePageLogger'
import { ProfileHeader } from 'features/ProfileHeader'
@ -16,11 +18,23 @@ import { Wrapper } from './styled'
const MatchPage = () => {
usePageLogger()
const { events, profile } = useMatchProfile()
const history = useHistory()
const {
events,
isStarted,
profile,
} = useMatchProfile()
const playFromScout = profile?.has_video && !profile?.live
const playFromOTT = !profile?.has_video && (profile?.live || profile?.storage)
// TODO Добавить попап 'Данный матч ещё не начался'
if (!isStarted && profile) {
const sportName = history.location.pathname.split('/')[1]
history.push(`/${sportName}/tournaments/${profile.tournament.id}`)
}
return (
<PageWrapper>
<ProfileHeader color='rgb(0,0,0)' height={4.5}>
@ -30,8 +44,18 @@ const MatchPage = () => {
<UserFavorites />
<SubscriptionGuard matchProfile={profile}>
<Wrapper>
{playFromOTT && <LiveMatch events={events} profile={profile} />}
{playFromScout && <FinishedMatch events={events} profile={profile} />}
{playFromOTT && (
<LiveMatch
events={events}
profile={profile}
/>
)}
{playFromScout && (
<FinishedMatch
events={events}
profile={profile}
/>
)}
</Wrapper>
</SubscriptionGuard>
</Main>

Loading…
Cancel
Save