feat(#159): add fav tournament after visit tournament landing

keep-around/9d11a525a1ee745f785976389c40d7a0601133e1
Andrei Dekterev 3 years ago
parent 83dcbd93bc
commit 9752a5eeb6
  1. 5
      src/features/AuthStore/hooks/useAuth.tsx
  2. 18
      src/features/MatchPage/index.tsx
  3. 12
      src/features/TournamentPage/hooks.tsx
  4. 9
      src/helpers/parseUrlParams/parseUrlParams.tsx

@ -103,7 +103,10 @@ export const useAuth = () => {
markUserLoaded()
if (page) {
const route = `${page}${page === '/' ? search : ''}`
history.push(route)
history.push(`${route}${(
page.includes('tournaments') || page.includes('matches'))
? '?from=landing'
: ''}`)
setPage('')
setSearch('')
}

@ -18,6 +18,7 @@ import { isIOS } from 'config/userAgent'
import { usePageLogger } from 'hooks/usePageLogger'
import { usePageParams } from 'hooks/usePageParams'
import { checkUrlParams } from 'helpers/parseUrlParams/parseUrlParams'
import { MatchPageStore, useMatchPageStore } from './store'
import { SubscriptionGuard } from './components/SubscriptionGuard'
import { LiveMatch } from './components/LiveMatch'
@ -31,6 +32,7 @@ const MatchPageComponent = () => {
const { addRemoveFavorite, userFavorites } = useUserFavoritesStore()
const { isStarted, profile } = useMatchPageStore()
const isFavorite = profile && userFavorites.find((fav) => fav.id === profile?.tournament.id)
const {
profileType,
@ -40,7 +42,6 @@ const MatchPageComponent = () => {
useEffect(() => {
let timer = 0
timer = window.setTimeout(() => {
const isFavorite = profile && userFavorites.find((fav) => fav.id === profile?.tournament.id)
if (profile && !isFavorite) {
addRemoveFavorite({
action: FavoritesActions.ADD,
@ -57,6 +58,21 @@ const MatchPageComponent = () => {
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [profile, profileType])
useEffect(() => {
if (
profile
&& !isFavorite
&& checkUrlParams('from') === 'landing') {
addRemoveFavorite({
action: FavoritesActions.ADD,
id: profile?.tournament.id,
isAuto: true,
sport: sportType,
type: ProfileTypes.TOURNAMENTS,
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [profile])
const playFromScout = profile?.has_video && !profile?.live && !profile.has_hls
const playFromOTT = (!profile?.has_video && (profile?.live || profile?.storage))

@ -8,10 +8,13 @@ import { useHistory } from 'react-router'
import type { TournamentInfo } from 'requests'
import { getTournamentInfo, getTournamentMatches } from 'requests'
import { checkUrlParams } from 'helpers/parseUrlParams/parseUrlParams'
import { usePageParams } from 'hooks/usePageParams'
import { useName } from 'features/Name'
import { isPermittedTournament } from '../../helpers/isPermittedTournament'
import { useProfileCard } from '../ProfileCard/hooks'
export const useTournamentPage = () => {
const [tournamentProfile, setTournamentProfile] = useState<TournamentInfo>(null)
@ -19,6 +22,8 @@ export const useTournamentPage = () => {
const country = useName(tournamentProfile?.country || {})
const history = useHistory()
const { isFavorite, toggleFavorites } = useProfileCard()
useEffect(() => {
if (!isPermittedTournament(tournamentId, sportType)) {
history.push('/')
@ -32,6 +37,13 @@ export const useTournamentPage = () => {
tournamentId,
])
useEffect(() => {
!isFavorite
&& checkUrlParams('from') === 'landing'
&& toggleFavorites()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
const fetchMatches = useCallback(
(limit: number, offset: number) => getTournamentMatches({
limit,

@ -0,0 +1,9 @@
export const parseUrlParams = (key: string) => {
const params = new URLSearchParams(window.location.search)
return params.get('from')
}
export const checkUrlParams = (key: string) => {
const params = new URLSearchParams(window.location.search)
return params.get(key)
}
Loading…
Cancel
Save