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

@ -1,3 +1,5 @@
import { useHistory } from 'react-router'
import { usePageLogger } from 'hooks/usePageLogger' import { usePageLogger } from 'hooks/usePageLogger'
import { ProfileHeader } from 'features/ProfileHeader' import { ProfileHeader } from 'features/ProfileHeader'
@ -16,11 +18,23 @@ import { Wrapper } from './styled'
const MatchPage = () => { const MatchPage = () => {
usePageLogger() usePageLogger()
const { events, profile } = useMatchProfile() const history = useHistory()
const {
events,
isStarted,
profile,
} = useMatchProfile()
const playFromScout = profile?.has_video && !profile?.live const playFromScout = profile?.has_video && !profile?.live
const playFromOTT = !profile?.has_video && (profile?.live || profile?.storage) 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 ( return (
<PageWrapper> <PageWrapper>
<ProfileHeader color='rgb(0,0,0)' height={4.5}> <ProfileHeader color='rgb(0,0,0)' height={4.5}>
@ -30,8 +44,18 @@ const MatchPage = () => {
<UserFavorites /> <UserFavorites />
<SubscriptionGuard matchProfile={profile}> <SubscriptionGuard matchProfile={profile}>
<Wrapper> <Wrapper>
{playFromOTT && <LiveMatch events={events} profile={profile} />} {playFromOTT && (
{playFromScout && <FinishedMatch events={events} profile={profile} />} <LiveMatch
events={events}
profile={profile}
/>
)}
{playFromScout && (
<FinishedMatch
events={events}
profile={profile}
/>
)}
</Wrapper> </Wrapper>
</SubscriptionGuard> </SubscriptionGuard>
</Main> </Main>

Loading…
Cancel
Save