feat(in-583): remove supertournaments from favorites

pull/193/head
Margarita 3 years ago
parent b0b7ab6073
commit 27b2449711
  1. 37760
      package-lock.json
  2. 42
      src/features/UserFavorites/hooks/index.tsx
  3. 25
      src/features/UserFavorites/index.tsx

37760
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,18 +1,14 @@
import {
useCallback,
useEffect,
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 {
FavoritesActions,
UserFavorites,
modifyUserFavorites,
getUserFavorites,
@ -53,29 +49,6 @@ 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: ProfileTypes.SUPERTOURNAMENTS,
})
}
return acc
},
[] as Array<SuperTournament>,
)
}, [userFavorites])
const fetchFavorites = useCallback(() => {
getUserFavorites().then((value) => {
if (Array.isArray(value)) {
@ -85,19 +58,6 @@ export const useUserFavorites = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [userInfo?.email])
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,
})
}
})
}
useEffect(() => {
if (!user) return
@ -122,9 +82,7 @@ export const useUserFavorites = () => {
isOpen,
open,
playerHighlight,
removeSuperTournament,
setPlayerHighlight,
superTournaments,
userFavorites,
}
}

@ -37,8 +37,6 @@ export const UserFavorites = ({ marginTop }: Props) => {
addRemoveFavorite,
close,
isOpen,
removeSuperTournament,
superTournaments,
userFavorites,
} = useUserFavoritesStore()
@ -54,29 +52,6 @@ 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
id={item.id}
altNameObj={item}
sportType={item.sport}
profileType={item.type}
/>
</UserSportFavItemLogoWrapper>
))
}
{
map(userFavorites, (item) => (
<UserSportFavItemLogoWrapper

Loading…
Cancel
Save