fix(#3003): supertournament into favorites

keep-around/9d11a525a1ee745f785976389c40d7a0601133e1
Rakov Roman 3 years ago
parent bb5a4fc477
commit bfdf684287
  1. 9
      src/features/TournamentList/hooks.tsx
  2. 12
      src/features/UserFavorites/FavoritesTooltip/index.tsx
  3. 62
      src/features/UserFavorites/hooks/index.tsx
  4. 34
      src/features/UserFavorites/index.tsx
  5. 5
      src/helpers/getProfileLogo/index.tsx
  6. 1
      src/helpers/index.tsx
  7. 4
      src/requests/getUserSportFavs.tsx

@ -14,6 +14,7 @@ interface TournamentsSortProps {
id: number,
isFavorite: boolean,
isLive: boolean,
isSuperTournament: boolean,
}
export const useTournaments = (matches: Array<Match>) => {
@ -49,7 +50,8 @@ export const useTournaments = (matches: Array<Match>) => {
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<Match>) => {
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<Match>) => {
const tournamentsSorted = useMemo(() => orderBy(
tournamentSort,
['isLive', 'isFavorite'],
['desc', 'desc'],
['isLive', 'isFavorite', 'isSuperTournament'],
['desc', 'desc', 'desc'],
), [tournamentSort])
useEffect(() => {

@ -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) => (
<TooltipWrapper top={topPosition}>
<Name nameObj={info} />
<Name nameObj={superTournament ?? favorite?.info!} />
</TooltipWrapper>
)

@ -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<typeof modifyUserFavorites>[0]
export const useUserFavorites = () => {
@ -33,6 +49,29 @@ export const useUserFavorites = () => {
open,
} = useToggle()
const superTournaments = useMemo(() => {
const uniqueTournamnetIds: Record<number, number> = {}
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<SuperTournament>,
)
}, [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,
}
}

@ -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) => {
<UserSportFavWrapper>
<UserSportFavStar marginTop={marginTop} />
<ScrollWrapper>
{
map(superTournaments, (item) => (
<UserSportFavItemLogoWrapper
onFocus={getPosition}
onMouseOver={getPosition}
key={`${item.type}_${item.sport}_${item.id}`}
>
<UserSportFavXWrapper onClick={() => removeSuperTournament(item.id)}>
<Close size={9} />
<FavoritesToolip
topPosition={position}
superTournament={item}
/>
</UserSportFavXWrapper>
<UserSportFavImgWrapper
isTournamentSuper
id={item.id}
altNameObj={item}
sportType={item.sport}
profileType={item.type}
/>
</UserSportFavItemLogoWrapper>
))
}
{
map(userFavorites, (item) => (
<UserSportFavItemLogoWrapper

@ -2,10 +2,9 @@ import {
SportTypes,
ProfileTypes,
PROFILE_NAMES,
isProduction,
} from 'config'
import { readToken } from 'helpers'
import { readToken, readSelectedApi } from 'helpers'
const IMAGES_URLS = {
[SportTypes.BASKETBALL]: 'https://basketball.instatscout.com/images',
@ -41,7 +40,7 @@ export const getProfileLogo = ({
}: GetLogoArgs) => {
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:

@ -7,3 +7,4 @@ export * from './msToMinutesAndSeconds'
export * from './secondsToHms'
export * from './redirectToUrl'
export * from './getRandomString'
export * from './selectedApi'

@ -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,

Loading…
Cancel
Save