diff --git a/src/features/MatchPage/index.tsx b/src/features/MatchPage/index.tsx index 1b445acf..2ee216d4 100644 --- a/src/features/MatchPage/index.tsx +++ b/src/features/MatchPage/index.tsx @@ -1,14 +1,20 @@ +import { useEffect } from 'react' import { useHistory } from 'react-router' -import { usePageLogger } from 'hooks/usePageLogger' - import { ProfileHeader } from 'features/ProfileHeader' import { UserFavorites } from 'features/UserFavorites' +import { useUserFavoritesStore } from 'features/UserFavorites/store' import { PageWrapper, Main, } from 'features/PageLayout' +import { FavoritesActions } from 'requests' +import { ProfileTypes } from 'config' + +import { usePageLogger } from 'hooks/usePageLogger' +import { usePageParams } from 'hooks/usePageParams' + import { SubscriptionGuard } from './components/SubscriptionGuard' import { MatchProfileCard } from './components/MatchProfileCard' import { FinishedMatch } from './components/FinishedMatch' @@ -19,6 +25,7 @@ import { Wrapper } from './styled' const MatchPage = () => { usePageLogger() const history = useHistory() + const { addRemoveFavorite, userFavorites } = useUserFavoritesStore() const { events, @@ -26,6 +33,32 @@ const MatchPage = () => { profile, } = useMatchProfile() + const { + profileType, + sportType, + } = usePageParams() + + 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, + id: profile?.tournament.id, + isAuto: true, + sport: sportType, + type: ProfileTypes.TOURNAMENTS, + }) + } + }, 60000) + + return () => { + clearTimeout(timer) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [profile, profileType]) + const playFromScout = profile?.has_video && !profile?.live const playFromOTT = !profile?.has_video && (profile?.live || profile?.storage) diff --git a/src/requests/modifyUserSportFavs.tsx b/src/requests/modifyUserSportFavs.tsx index a9a24cc4..bd3ca9ce 100644 --- a/src/requests/modifyUserSportFavs.tsx +++ b/src/requests/modifyUserSportFavs.tsx @@ -28,6 +28,7 @@ type Response = { type Args = { action: FavoritesActions, id: number, + isAuto?: boolean, sport: SportTypes, type: ProfileTypes, } @@ -36,6 +37,7 @@ type Args = { export const modifyUserFavorites = async ({ action, id, + isAuto = false, sport, type, }: Args) => { @@ -44,6 +46,7 @@ export const modifyUserFavorites = async ({ params: { _p_action: action, _p_id: id, + _p_is_auto_add: isAuto, _p_sport: sport, _p_type: type, },