diff --git a/src/features/TournamentList/hooks.tsx b/src/features/TournamentList/hooks.tsx index ade8691b..93a69933 100644 --- a/src/features/TournamentList/hooks.tsx +++ b/src/features/TournamentList/hooks.tsx @@ -14,6 +14,7 @@ interface TournamentsSortProps { id: number, isFavorite: boolean, isLive: boolean, + isSuperTournament: boolean, } export const useTournaments = (matches: Array) => { @@ -49,7 +50,8 @@ export const useTournaments = (matches: Array) => { const tournamentInFavorites = isInFavorites( ProfileTypes.TOURNAMENTS, - match.tournament.id, + // в избранном могут быть только обычные турниры + match.tournament.is_super_tournament ? match.group.id : match.tournament.id, ) if (!acc[match.tournament.id] && compareSport(match, selectedSport) @@ -72,6 +74,7 @@ export const useTournaments = (matches: Array) => { id: match.tournament.id, isFavorite: tournamentInFavorites, isLive: match.live, + isSuperTournament: Boolean(match.tournament.is_super_tournament), }) sportIds.add(match.sportType) } else if (compareSport(match, selectedSport) && compareLeague(match.tournament.id)) { @@ -91,8 +94,8 @@ export const useTournaments = (matches: Array) => { const tournamentsSorted = useMemo(() => orderBy( tournamentSort, - ['isLive', 'isFavorite'], - ['desc', 'desc'], + ['isLive', 'isFavorite', 'isSuperTournament'], + ['desc', 'desc', 'desc'], ), [tournamentSort]) useEffect(() => { diff --git a/src/features/UserFavorites/FavoritesTooltip/index.tsx b/src/features/UserFavorites/FavoritesTooltip/index.tsx index ed9ddfab..a6d9a059 100644 --- a/src/features/UserFavorites/FavoritesTooltip/index.tsx +++ b/src/features/UserFavorites/FavoritesTooltip/index.tsx @@ -4,18 +4,20 @@ import { Name } from 'features/Name' import { TooltipWrapper } from './styled' +import { SuperTournament } from '../hooks' + type TooltipBlockProps = { - favorite: UserFavorite, + favorite?: UserFavorite, + superTournament?: SuperTournament, topPosition: number, } export const FavoritesToolip = ({ - favorite: { - info, - }, + favorite, + superTournament, topPosition, }: TooltipBlockProps) => ( - + ) diff --git a/src/features/UserFavorites/hooks/index.tsx b/src/features/UserFavorites/hooks/index.tsx index b997b87e..6e95f0fd 100644 --- a/src/features/UserFavorites/hooks/index.tsx +++ b/src/features/UserFavorites/hooks/index.tsx @@ -1,14 +1,25 @@ -import { useCallback, useState } from 'react' +import { + useCallback, + useMemo, + useState, +} from 'react' import find from 'lodash/find' +import forEach from 'lodash/forEach' +import { reduce } from 'lodash' import type { ObjectWithName } from 'features/Name' -import type { UserFavorites } from 'requests' -import { modifyUserFavorites, getUserFavorites } from 'requests' +import { + FavoritesActions, + UserFavorites, + modifyUserFavorites, + getUserFavorites, +} from 'requests' import { useToggle } from 'hooks/useToggle' -import { ProfileTypes } from 'config' + +import { ProfileTypes, SportTypes } from 'config' type ProfileType = { profile: ObjectWithName & { @@ -21,6 +32,11 @@ type ProfileType = { sportType: number, } +export type SuperTournament = ObjectWithName & { + sport: SportTypes, + type: ProfileTypes, +} + type Args = Parameters[0] export const useUserFavorites = () => { @@ -33,6 +49,29 @@ export const useUserFavorites = () => { open, } = useToggle() + const superTournaments = useMemo(() => { + const uniqueTournamnetIds: Record = {} + + return reduce( + userFavorites, + (acc, item) => { + if ( + item.info.super_tournament + && !uniqueTournamnetIds[item.info.super_tournament.id] + ) { + uniqueTournamnetIds[item.info.super_tournament.id] = item.info.super_tournament.id + acc.push({ + ...item.info.super_tournament, + sport: item.sport, + type: item.type, + }) + } + return acc + }, + [] as Array, + ) + }, [userFavorites]) + const fetchFavorites = useCallback(() => { getUserFavorites().then((value) => { if (Array.isArray(value)) { @@ -41,6 +80,19 @@ export const useUserFavorites = () => { }) }, []) + const removeSuperTournament = (id: number) => { + forEach(userFavorites, (item) => { + if (item.info.super_tournament?.id === id) { + addRemoveFavorite({ + action: FavoritesActions.REMOVE, + id: item.id, + sport: item.sport, + type: item.type, + }) + } + }) + } + const addRemoveFavorite = (args: Args) => { modifyUserFavorites(args).then(setUserFavorites, open) } @@ -57,7 +109,9 @@ export const useUserFavorites = () => { isOpen, open, playerHighlight, + removeSuperTournament, setPlayerHighlight, + superTournaments, userFavorites, } } diff --git a/src/features/UserFavorites/index.tsx b/src/features/UserFavorites/index.tsx index d24ffd67..f8dd62c6 100644 --- a/src/features/UserFavorites/index.tsx +++ b/src/features/UserFavorites/index.tsx @@ -1,5 +1,9 @@ -import type { MouseEvent, FocusEvent } from 'react' -import { useEffect, useState } from 'react' +import { + MouseEvent, + FocusEvent, + useEffect, + useState, +} from 'react' import map from 'lodash/map' @@ -35,6 +39,8 @@ export const UserFavorites = ({ marginTop }: Props) => { close, fetchFavorites, isOpen, + removeSuperTournament, + superTournaments, userFavorites, } = useUserFavoritesStore() @@ -52,6 +58,30 @@ export const UserFavorites = ({ marginTop }: Props) => { + { + map(superTournaments, (item) => ( + + removeSuperTournament(item.id)}> + + + + + + )) + } { map(userFavorites, (item) => ( { switch (true) { case isTournamentSuper: - return `https://cf-aws${isProduction ? '' : '-staging'}.insports.tv/media/supertournaments/${sportType}/${id}/${MediaType.logo}.jpg?access_token=${readToken()}` + return `https://cf-aws${readSelectedApi() === 'staging' ? '-staging' : ''}.insports.tv/media/supertournaments/${sportType}/${id}/${MediaType.logo}.jpg?access_token=${readToken()}` case sportType === SportTypes.BOXING: return `https://images.insports.tv/${sportType}/${PROFILE_NAMES[profileType]}/${id}.png` default: diff --git a/src/helpers/index.tsx b/src/helpers/index.tsx index 06dc4502..734a5130 100644 --- a/src/helpers/index.tsx +++ b/src/helpers/index.tsx @@ -7,3 +7,4 @@ export * from './msToMinutesAndSeconds' export * from './secondsToHms' export * from './redirectToUrl' export * from './getRandomString' +export * from './selectedApi' diff --git a/src/requests/getUserSportFavs.tsx b/src/requests/getUserSportFavs.tsx index c6e30538..008019d6 100644 --- a/src/requests/getUserSportFavs.tsx +++ b/src/requests/getUserSportFavs.tsx @@ -14,7 +14,7 @@ type ObjectWithName = { name_rus: string, } -type Info = { +export type Info = { country?: ObjectWithName, date?: string, firstname_eng?: string, @@ -27,6 +27,8 @@ type Info = { nickname_rus?: string, short_name_eng?: string, short_name_rus?: string, + /** информация о супертурнире, если турнир входит в супертурнир */ + super_tournament?: ObjectWithName, team?: ObjectWithName, team1?: ObjectWithName, team2?: ObjectWithName,