|
|
|
|
@ -1,8 +1,9 @@ |
|
|
|
|
import type { BaseSyntheticEvent } from 'react' |
|
|
|
|
import { useCallback } from 'react' |
|
|
|
|
|
|
|
|
|
import findIndex from 'lodash/findIndex' |
|
|
|
|
import find from 'lodash/find' |
|
|
|
|
|
|
|
|
|
import { FavoritesActions } from 'requests' |
|
|
|
|
import { handleImageError, getProfileLogo } from 'helpers' |
|
|
|
|
|
|
|
|
|
import { useSportNameParam, usePageId } from 'hooks' |
|
|
|
|
@ -16,11 +17,11 @@ export const useProfileCard = ({ profileType }: ProfileCardProps) => { |
|
|
|
|
const profileId = usePageId() |
|
|
|
|
const { sportType } = useSportNameParam() |
|
|
|
|
|
|
|
|
|
const isFavorite = findIndex(userFavorites, { |
|
|
|
|
const isFavorite = Boolean(find(userFavorites, { |
|
|
|
|
id: profileId, |
|
|
|
|
sport: sportType, |
|
|
|
|
type: profileType, |
|
|
|
|
}) !== -1 |
|
|
|
|
})) |
|
|
|
|
|
|
|
|
|
const logo = getProfileLogo({ |
|
|
|
|
id: profileId, |
|
|
|
|
@ -28,14 +29,18 @@ export const useProfileCard = ({ profileType }: ProfileCardProps) => { |
|
|
|
|
sportType, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const addToFavorites = useCallback(() => { |
|
|
|
|
const toggleFavorites = useCallback(() => { |
|
|
|
|
const action = isFavorite |
|
|
|
|
? FavoritesActions.REMOVE |
|
|
|
|
: FavoritesActions.ADD |
|
|
|
|
addRemoveFavorite({ |
|
|
|
|
action: 1, |
|
|
|
|
action, |
|
|
|
|
id: profileId, |
|
|
|
|
sport: sportType, |
|
|
|
|
type: profileType, |
|
|
|
|
}) |
|
|
|
|
}, [ |
|
|
|
|
isFavorite, |
|
|
|
|
addRemoveFavorite, |
|
|
|
|
profileId, |
|
|
|
|
profileType, |
|
|
|
|
@ -49,9 +54,9 @@ export const useProfileCard = ({ profileType }: ProfileCardProps) => { |
|
|
|
|
}), [profileType, sportType]) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
addToFavorites, |
|
|
|
|
isFavorite, |
|
|
|
|
logo, |
|
|
|
|
onError, |
|
|
|
|
toggleFavorites, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|