Ott 253 login error message (#66)
parent
cf7f314328
commit
ee838f0e22
@ -1,5 +0,0 @@ |
|||||||
export const SPORT_COLORS = { |
|
||||||
basketball: '#f1903b', |
|
||||||
football: '#00a435', |
|
||||||
hockey: '#5eb1ff', |
|
||||||
} |
|
||||||
@ -0,0 +1,11 @@ |
|||||||
|
export enum ProfileTypes { |
||||||
|
TOURNAMENTS = 1, |
||||||
|
TEAMS = 2, |
||||||
|
PLAYERS = 3, |
||||||
|
} |
||||||
|
|
||||||
|
export const PROFILE_NAMES = { |
||||||
|
[ProfileTypes.TOURNAMENTS]: 'tournaments', |
||||||
|
[ProfileTypes.TEAMS]: 'teams', |
||||||
|
[ProfileTypes.PLAYERS]: 'players', |
||||||
|
} as const |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
export enum SportTypes { |
||||||
|
FOOTBALL = 1, |
||||||
|
HOCKEY = 2, |
||||||
|
BASKETBALL = 3, |
||||||
|
} |
||||||
|
|
||||||
|
export const SPORT_NAMES = { |
||||||
|
[SportTypes.BASKETBALL]: 'basketball', |
||||||
|
[SportTypes.FOOTBALL]: 'football', |
||||||
|
[SportTypes.HOCKEY]: 'hockey', |
||||||
|
} |
||||||
@ -1,35 +1,47 @@ |
|||||||
import map from 'lodash/map' |
import map from 'lodash/map' |
||||||
|
|
||||||
import type { Tournaments } from 'requests' |
import { Tournaments } from 'requests' |
||||||
|
|
||||||
import { LOGOS_FALLBACKS } from 'config' |
import { ProfileTypes } from 'config' |
||||||
import { getLogo, SPORT_TYPES } from 'helpers' |
import { |
||||||
|
getProfileLogo, |
||||||
|
getSportColor, |
||||||
|
getSportLexic, |
||||||
|
getProfileFallbackLogo, |
||||||
|
} from 'helpers' |
||||||
|
|
||||||
type Name = 'name_rus' | 'name_eng' |
type Name = 'name_rus' | 'name_eng' |
||||||
type ShortName = 'short_name_rus' | 'short_name_eng' |
type ShortName = 'short_name_rus' | 'short_name_eng' |
||||||
|
|
||||||
export const normalizeTournaments = (tournaments: Tournaments, suffix: string) => ( |
export const normalizeTournaments = (tournaments: Tournaments, suffix: string) => ( |
||||||
map(tournaments, (tournament) => { |
map(tournaments, (tournament) => { |
||||||
const { c_sport, id } = tournament |
const profileType = ProfileTypes.TOURNAMENTS |
||||||
const sportType = SPORT_TYPES[c_sport] |
const { c_sport: sportType, id } = tournament |
||||||
|
const color = getSportColor(sportType) |
||||||
|
const sportLexic = getSportLexic(sportType) |
||||||
const name = tournament[`name_${suffix}` as Name] |
const name = tournament[`name_${suffix}` as Name] |
||||||
const shortName = tournament[`short_name_${suffix}` as ShortName] || name |
const shortName = tournament[`short_name_${suffix}` as ShortName] || name |
||||||
const country = tournament.country?.[`name_${suffix}` as Name] |
const country = tournament.country?.[`name_${suffix}` as Name] |
||||||
|
|
||||||
const logo = getLogo({ |
const logo = getProfileLogo({ |
||||||
id, |
id, |
||||||
|
profileType, |
||||||
|
sportType, |
||||||
|
}) |
||||||
|
const fallbackImage = getProfileFallbackLogo({ |
||||||
|
profileType, |
||||||
sportType, |
sportType, |
||||||
type: 'tournaments', |
|
||||||
}) |
}) |
||||||
|
|
||||||
return { |
return { |
||||||
|
color, |
||||||
country, |
country, |
||||||
fallbackImage: LOGOS_FALLBACKS[sportType].tournaments, |
fallbackImage, |
||||||
id, |
id, |
||||||
logo, |
logo, |
||||||
name, |
name, |
||||||
shortName, |
shortName, |
||||||
sportType, |
sportLexic, |
||||||
} |
} |
||||||
}) |
}) |
||||||
) |
) |
||||||
|
|||||||
@ -0,0 +1,41 @@ |
|||||||
|
import map from 'lodash/map' |
||||||
|
|
||||||
|
import { getProfileLogo, getProfileUrl } from 'helpers' |
||||||
|
import type { UserFavorites } from 'requests' |
||||||
|
|
||||||
|
type Names = 'name_eng' | 'name_rus' |
||||||
|
type ShortNames = 'short_name_eng' | 'short_name_rus' |
||||||
|
type FirstNames = 'firstname_eng' | 'firstname_rus' |
||||||
|
type LastNames = 'lastname_eng' | 'firstname_rus' |
||||||
|
type NickNames = 'nickname_eng' | 'nickname_rus' |
||||||
|
|
||||||
|
export const normalizeUserFavorites = (favorites: UserFavorites, suffix: string) => { |
||||||
|
const nameField = `name_${suffix}` as Names |
||||||
|
const shortNameField = `short_name_${suffix}` as ShortNames |
||||||
|
const firtsNameField = `firstname_${suffix}` as FirstNames |
||||||
|
const lastNameField = `lastname_${suffix}` as LastNames |
||||||
|
const nickNameField = `nickname_${suffix}` as NickNames |
||||||
|
|
||||||
|
return map(favorites, (item) => ({ |
||||||
|
countryName: item.info.country?.[nameField], |
||||||
|
firstname: item.info[firtsNameField], |
||||||
|
id: item.id, |
||||||
|
lastname: item.info[lastNameField], |
||||||
|
name: item.info[nameField], |
||||||
|
nickname: item.info[nickNameField], |
||||||
|
profileLogo: getProfileLogo({ |
||||||
|
id: item.id, |
||||||
|
profileType: item.type, |
||||||
|
sportType: item.sport, |
||||||
|
}), |
||||||
|
profileUrl: getProfileUrl({ |
||||||
|
id: item.id, |
||||||
|
profileType: item.type, |
||||||
|
sportType: item.sport, |
||||||
|
}), |
||||||
|
shortName: item.info[shortNameField], |
||||||
|
sport: item.sport, |
||||||
|
teamName: item.info.team?.[nameField], |
||||||
|
type: item.type, |
||||||
|
})) |
||||||
|
} |
||||||
@ -0,0 +1,36 @@ |
|||||||
|
import { |
||||||
|
useEffect, |
||||||
|
useState, |
||||||
|
useMemo, |
||||||
|
} from 'react' |
||||||
|
|
||||||
|
import type { UserFavorites } from 'requests' |
||||||
|
import { modifyUserFavorites, getUserFavorites } from 'requests' |
||||||
|
import { useLexicsStore } from 'features/LexicsStore' |
||||||
|
|
||||||
|
import { normalizeUserFavorites } from '../helpers' |
||||||
|
|
||||||
|
type Args = Parameters<typeof modifyUserFavorites>[0] |
||||||
|
|
||||||
|
export const useUserFavorites = () => { |
||||||
|
const { suffix } = useLexicsStore() |
||||||
|
const [userFavorites, setUserFavorites] = useState<UserFavorites>([]) |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
getUserFavorites().then(setUserFavorites) |
||||||
|
}, []) |
||||||
|
|
||||||
|
const addRemoveFavorite = (args: Args) => { |
||||||
|
modifyUserFavorites(args).then(setUserFavorites) |
||||||
|
} |
||||||
|
|
||||||
|
const memoizedUserFavorites = useMemo( |
||||||
|
() => normalizeUserFavorites(userFavorites, suffix), |
||||||
|
[userFavorites, suffix], |
||||||
|
) |
||||||
|
|
||||||
|
return { |
||||||
|
addRemoveFavorite, |
||||||
|
userFavorites: memoizedUserFavorites, |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,61 @@ |
|||||||
|
import React from 'react' |
||||||
|
|
||||||
|
import map from 'lodash/map' |
||||||
|
|
||||||
|
import { handleImageError } from 'helpers' |
||||||
|
|
||||||
|
import { useUserFavorites } from './hooks' |
||||||
|
import { TooltipBlock } from './TooltipBlock' |
||||||
|
import { |
||||||
|
StyledLink, |
||||||
|
UserSportFavItemLogoWrapper, |
||||||
|
UserSportFavXWrapper, |
||||||
|
UserSportFavImgWrapper, |
||||||
|
UserSportFavStar, |
||||||
|
UserSportFavLogoWrapper, |
||||||
|
UserSportFavWrapper, |
||||||
|
} from './styled' |
||||||
|
|
||||||
|
export const UserFavorites = () => { |
||||||
|
const { addRemoveFavorite, userFavorites } = useUserFavorites() |
||||||
|
|
||||||
|
return ( |
||||||
|
<UserSportFavWrapper> |
||||||
|
<UserSportFavLogoWrapper height={12} width={52} /> |
||||||
|
<UserSportFavStar /> |
||||||
|
{ |
||||||
|
map(userFavorites, (item) => ( |
||||||
|
<UserSportFavItemLogoWrapper key={`${item.type}_${item.sport}_${item.id}`}> |
||||||
|
<UserSportFavXWrapper |
||||||
|
onClick={() => addRemoveFavorite({ |
||||||
|
action: 2, |
||||||
|
id: item.id, |
||||||
|
sport: item.sport, |
||||||
|
type: item.type, |
||||||
|
})} |
||||||
|
/> |
||||||
|
<TooltipBlock |
||||||
|
countryName={item.countryName} |
||||||
|
teamName={item.name} |
||||||
|
playerTeamName={item.teamName} |
||||||
|
playerFirstName={item.firstname} |
||||||
|
playerLastName={item.lastname} |
||||||
|
sport={item.sport} |
||||||
|
/> |
||||||
|
<StyledLink to={item.profileUrl} target='_blank'> |
||||||
|
<UserSportFavImgWrapper |
||||||
|
src={item.profileLogo} |
||||||
|
alt={item.name} |
||||||
|
onError={(e) => handleImageError({ |
||||||
|
e, |
||||||
|
sport: item.sport, |
||||||
|
type: item.type, |
||||||
|
})} |
||||||
|
/> |
||||||
|
</StyledLink> |
||||||
|
</UserSportFavItemLogoWrapper> |
||||||
|
)) |
||||||
|
} |
||||||
|
</UserSportFavWrapper> |
||||||
|
) |
||||||
|
} |
||||||
@ -1,27 +0,0 @@ |
|||||||
import { SPORT_COLORS } from 'config' |
|
||||||
|
|
||||||
export const getSportName = (sport: number, suffix: string): string => { |
|
||||||
switch (sport) { |
|
||||||
case 1: |
|
||||||
return suffix === 'eng' ? 'Football' : 'Футбол' |
|
||||||
case 2: |
|
||||||
return suffix === 'eng' ? 'Hockey' : 'Хоккей' |
|
||||||
case 3: |
|
||||||
return suffix === 'eng' ? 'Basketball' : 'Баскетбол' |
|
||||||
default: |
|
||||||
return '' |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
export const getSportColor = (sport: number): string => { |
|
||||||
switch (sport) { |
|
||||||
case 1: |
|
||||||
return SPORT_COLORS.football |
|
||||||
case 2: |
|
||||||
return SPORT_COLORS.hockey |
|
||||||
case 3: |
|
||||||
return SPORT_COLORS.basketball |
|
||||||
default: |
|
||||||
return '' |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,132 +0,0 @@ |
|||||||
import { |
|
||||||
useEffect, |
|
||||||
useState, |
|
||||||
useMemo, |
|
||||||
} from 'react' |
|
||||||
|
|
||||||
import map from 'lodash/map' |
|
||||||
|
|
||||||
import { |
|
||||||
LOGOS_URLS, |
|
||||||
FAV_SPORT_URLS, |
|
||||||
} from 'config' |
|
||||||
import { |
|
||||||
SPORT_TYPES, |
|
||||||
DATA_TYPES, |
|
||||||
} from 'helpers' |
|
||||||
import { |
|
||||||
modifyUserSportFavs, |
|
||||||
ModifyUserSportFavsArgs, |
|
||||||
getUserSportFavs, |
|
||||||
UserSportFavItem, |
|
||||||
} from 'requests' |
|
||||||
import { useLexicsStore } from 'features/LexicsStore' |
|
||||||
|
|
||||||
type TNames = 'name_eng' | 'name_rus' |
|
||||||
type TShortNames = 'short_name_eng' | 'short_name_rus' |
|
||||||
type TFirstNames = 'firstname_eng' | 'firstname_rus' |
|
||||||
type TLastNames = 'lastname_eng' | 'firstname_rus' |
|
||||||
type TNickNames = 'nickname_eng' | 'nickname_rus' |
|
||||||
|
|
||||||
export type TMemoizedUserSportFavItem = { |
|
||||||
countryName?: string, |
|
||||||
firstname?: string, |
|
||||||
id: number, |
|
||||||
lastname?: string, |
|
||||||
name?: string, |
|
||||||
nickname?: string, |
|
||||||
shortName?: string, |
|
||||||
sport: number, |
|
||||||
teamName?: string, |
|
||||||
type: number, |
|
||||||
} |
|
||||||
|
|
||||||
type TMakeUrlArgs = { |
|
||||||
id: number, |
|
||||||
sport: number, |
|
||||||
type: number, |
|
||||||
} |
|
||||||
|
|
||||||
export const useUserSportFavs = () => { |
|
||||||
const { suffix } = useLexicsStore() |
|
||||||
const [userSportFavItems, setUserSportFavItems] = useState<Array<UserSportFavItem>>([]) |
|
||||||
|
|
||||||
const nameField = `name_${suffix}` as TNames |
|
||||||
const shortNameField = `short_name_${suffix}` as TShortNames |
|
||||||
const firtsNameField = `firstname_${suffix}` as TFirstNames |
|
||||||
const lastNameField = `lastname_${suffix}` as TLastNames |
|
||||||
const nickNameField = `nickname_${suffix}` as TNickNames |
|
||||||
|
|
||||||
useEffect(() => { |
|
||||||
getUserSportFavs().then(setUserSportFavItems) |
|
||||||
}, []) |
|
||||||
|
|
||||||
const addRemoveSportFav = ({ |
|
||||||
action, |
|
||||||
id, |
|
||||||
sport, |
|
||||||
type, |
|
||||||
}: ModifyUserSportFavsArgs) => { |
|
||||||
// при добавлении дубликата userSportFavItem back возвращает {}
|
|
||||||
modifyUserSportFavs({ |
|
||||||
action, |
|
||||||
id, |
|
||||||
sport, |
|
||||||
type, |
|
||||||
}).then((userSportFavs) => Array.isArray(userSportFavs) && setUserSportFavItems(userSportFavs)) |
|
||||||
} |
|
||||||
|
|
||||||
const memoizedUserSportFavItems = useMemo(() => map(userSportFavItems, (item) => ({ |
|
||||||
countryName: item.info.country?.[nameField], |
|
||||||
firstname: item.info[firtsNameField], |
|
||||||
id: item.id, |
|
||||||
lastname: item.info[lastNameField], |
|
||||||
name: item.info[nameField], |
|
||||||
nickname: item.info[nickNameField], |
|
||||||
shortName: item.info[shortNameField], |
|
||||||
sport: item.sport, |
|
||||||
teamName: item.info.team?.[nameField], |
|
||||||
type: item.type, |
|
||||||
})), |
|
||||||
[ |
|
||||||
firtsNameField, |
|
||||||
lastNameField, |
|
||||||
userSportFavItems, |
|
||||||
nameField, |
|
||||||
nickNameField, |
|
||||||
shortNameField, |
|
||||||
]) |
|
||||||
|
|
||||||
return { |
|
||||||
addRemoveSportFav, |
|
||||||
userSportFavItems: memoizedUserSportFavItems, |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
export const makePicUrl = (arg: TMakeUrlArgs) => ( |
|
||||||
// @ts-expect-error
|
|
||||||
`${LOGOS_URLS[SPORT_TYPES[arg.sport]][DATA_TYPES[arg.type]]}/${arg.id}.png` |
|
||||||
) |
|
||||||
|
|
||||||
export const makeProfileUrl = (arg: TMakeUrlArgs) => ( |
|
||||||
// @ts-expect-error
|
|
||||||
`${FAV_SPORT_URLS[SPORT_TYPES[arg.sport]][DATA_TYPES[arg.type]]}/${arg.id}` |
|
||||||
) |
|
||||||
|
|
||||||
export const userSportFavs = ( |
|
||||||
userSportFavItems: Array<TMemoizedUserSportFavItem>, |
|
||||||
) => userSportFavItems?.length > 0 && map( |
|
||||||
userSportFavItems, (fav) => ({ |
|
||||||
...fav, |
|
||||||
pic_url: makePicUrl({ |
|
||||||
id: fav.id, |
|
||||||
sport: fav.sport, |
|
||||||
type: fav.type, |
|
||||||
}), |
|
||||||
profile_url: makeProfileUrl({ |
|
||||||
id: fav.id, |
|
||||||
sport: fav.sport, |
|
||||||
type: fav.type, |
|
||||||
}), |
|
||||||
}), |
|
||||||
) |
|
||||||
@ -1,68 +0,0 @@ |
|||||||
import React from 'react' |
|
||||||
|
|
||||||
import map from 'lodash/map' |
|
||||||
|
|
||||||
import { useLexicsStore } from 'features/LexicsStore' |
|
||||||
import { handleImageError } from 'helpers' |
|
||||||
|
|
||||||
import { |
|
||||||
useUserSportFavs, |
|
||||||
userSportFavs, |
|
||||||
} from './hooks' |
|
||||||
import { TooltipBlock } from './TooltipBlock' |
|
||||||
import { |
|
||||||
StyledLink, |
|
||||||
UserSportFavItemLogoWrapper, |
|
||||||
UserSportFavXWrapper, |
|
||||||
UserSportFavImgWrapper, |
|
||||||
UserSportFavStar, |
|
||||||
UserSportFavLogoWrapper, |
|
||||||
UserSportFavWrapper, |
|
||||||
} from './styled' |
|
||||||
|
|
||||||
export const UserSportFav = () => { |
|
||||||
const { addRemoveSportFav, userSportFavItems } = useUserSportFavs() |
|
||||||
|
|
||||||
const { suffix } = useLexicsStore() |
|
||||||
|
|
||||||
const userSportFavList = userSportFavs(userSportFavItems) |
|
||||||
|
|
||||||
return ( |
|
||||||
<UserSportFavWrapper> |
|
||||||
<UserSportFavLogoWrapper height={12} width={52} /> |
|
||||||
<UserSportFavStar /> |
|
||||||
{userSportFavList && map(userSportFavList, (item) => ( |
|
||||||
<UserSportFavItemLogoWrapper key={`${item.type}_${item.sport}_${item.id}`}> |
|
||||||
<UserSportFavXWrapper |
|
||||||
onClick={() => addRemoveSportFav({ |
|
||||||
action: 2, |
|
||||||
id: item.id, |
|
||||||
sport: item.sport, |
|
||||||
type: item.type, |
|
||||||
})} |
|
||||||
/> |
|
||||||
<TooltipBlock |
|
||||||
countryName={item.countryName} |
|
||||||
teamName={item.name} |
|
||||||
playerTeamName={item.teamName} |
|
||||||
playerFirstName={item.firstname} |
|
||||||
playerLastName={item.lastname} |
|
||||||
sport={item.sport} |
|
||||||
suffix={suffix} |
|
||||||
/> |
|
||||||
<StyledLink to={item.profile_url} target='_blank'> |
|
||||||
<UserSportFavImgWrapper |
|
||||||
src={item.pic_url} |
|
||||||
alt={item.name} |
|
||||||
onError={(e) => handleImageError({ |
|
||||||
e, |
|
||||||
sport: item.sport, |
|
||||||
type: item.type, |
|
||||||
})} |
|
||||||
/> |
|
||||||
</StyledLink> |
|
||||||
</UserSportFavItemLogoWrapper> |
|
||||||
))} |
|
||||||
</UserSportFavWrapper> |
|
||||||
) |
|
||||||
} |
|
||||||
@ -1,23 +0,0 @@ |
|||||||
import { getLogo } from '..' |
|
||||||
|
|
||||||
describe('getLogo helper', () => { |
|
||||||
it('returns logo url', () => { |
|
||||||
expect(getLogo({ |
|
||||||
id: 1, |
|
||||||
sportType: 'football', |
|
||||||
type: 'players', |
|
||||||
})).toBe('https://instatscout.com/images/players/180/1.png') |
|
||||||
|
|
||||||
expect(getLogo({ |
|
||||||
id: 1, |
|
||||||
sportType: 'basketball', |
|
||||||
type: 'teams', |
|
||||||
})).toBe('https://basketball.instatscout.com/images/teams/180/1.png') |
|
||||||
|
|
||||||
expect(getLogo({ |
|
||||||
id: 1, |
|
||||||
sportType: 'hockey', |
|
||||||
type: 'tournaments', |
|
||||||
})).toBe('https://hockey.instatscout.com/images/tournaments/180/1.png') |
|
||||||
}) |
|
||||||
}) |
|
||||||
@ -1,23 +0,0 @@ |
|||||||
import type { SportType } from 'features/Search/config' |
|
||||||
|
|
||||||
const IMAGES_URLS = { |
|
||||||
basketball: 'https://basketball.instatscout.com/images', |
|
||||||
football: 'https://instatscout.com/images', |
|
||||||
hockey: 'https://hockey.instatscout.com/images', |
|
||||||
} |
|
||||||
|
|
||||||
type GetLogoArgs = { |
|
||||||
id: number, |
|
||||||
size?: number, |
|
||||||
sportType: SportType, |
|
||||||
type: 'players' | 'teams' | 'tournaments', |
|
||||||
} |
|
||||||
|
|
||||||
export const getLogo = ({ |
|
||||||
id, |
|
||||||
size = 180, |
|
||||||
sportType, |
|
||||||
type, |
|
||||||
}: GetLogoArgs) => ( |
|
||||||
`${IMAGES_URLS[sportType]}/${type}/${size}/${id}.png` |
|
||||||
) |
|
||||||
@ -0,0 +1,33 @@ |
|||||||
|
import { SportTypes, ProfileTypes } from 'config' |
||||||
|
|
||||||
|
const FALLBACK_LOGOS = { |
||||||
|
[SportTypes.BASKETBALL]: { |
||||||
|
[ProfileTypes.PLAYERS]: 'https://basketball.instatscout.com/images/player-no-photo.png', |
||||||
|
[ProfileTypes.TEAMS]: 'https://basketball.instatscout.com/images/team-no-photo.png', |
||||||
|
[ProfileTypes.TOURNAMENTS]: 'https://basketball.instatscout.com/images/tournaments/180/no-photo.png', |
||||||
|
}, |
||||||
|
|
||||||
|
[SportTypes.FOOTBALL]: { |
||||||
|
[ProfileTypes.PLAYERS]: 'https://football.instatscout.com/images/player-no-photo.png', |
||||||
|
[ProfileTypes.TEAMS]: 'https://football.instatscout.com/images/team-no-photo.png', |
||||||
|
[ProfileTypes.TOURNAMENTS]: 'https://football.instatscout.com/images/tournament-no-photo.png', |
||||||
|
}, |
||||||
|
|
||||||
|
[SportTypes.HOCKEY]: { |
||||||
|
[ProfileTypes.PLAYERS]: 'https://hockey.instatscout.com/images/player-no-photo.png', |
||||||
|
[ProfileTypes.TEAMS]: 'https://hockey.instatscout.com/images/team-no-photo.png', |
||||||
|
[ProfileTypes.TOURNAMENTS]: 'https://hockey.instatscout.com/images/tournaments/180/no-photo.png', |
||||||
|
}, |
||||||
|
} |
||||||
|
|
||||||
|
type Args = { |
||||||
|
profileType: ProfileTypes, |
||||||
|
sportType: SportTypes, |
||||||
|
} |
||||||
|
|
||||||
|
export const getProfileFallbackLogo = ({ |
||||||
|
profileType, |
||||||
|
sportType, |
||||||
|
}: Args) => ( |
||||||
|
FALLBACK_LOGOS[sportType][profileType] |
||||||
|
) |
||||||
@ -0,0 +1,25 @@ |
|||||||
|
import { SportTypes, ProfileTypes } from 'config' |
||||||
|
|
||||||
|
import { getProfileLogo } from '..' |
||||||
|
|
||||||
|
describe('getLogo helper', () => { |
||||||
|
it('returns logo url', () => { |
||||||
|
expect(getProfileLogo({ |
||||||
|
id: 1, |
||||||
|
profileType: ProfileTypes.PLAYERS, |
||||||
|
sportType: SportTypes.FOOTBALL, |
||||||
|
})).toBe('https://instatscout.com/images/players/180/1.png') |
||||||
|
|
||||||
|
expect(getProfileLogo({ |
||||||
|
id: 1, |
||||||
|
profileType: ProfileTypes.TEAMS, |
||||||
|
sportType: SportTypes.BASKETBALL, |
||||||
|
})).toBe('https://basketball.instatscout.com/images/teams/180/1.png') |
||||||
|
|
||||||
|
expect(getProfileLogo({ |
||||||
|
id: 1, |
||||||
|
profileType: ProfileTypes.TOURNAMENTS, |
||||||
|
sportType: SportTypes.HOCKEY, |
||||||
|
})).toBe('https://hockey.instatscout.com/images/tournaments/180/1.png') |
||||||
|
}) |
||||||
|
}) |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
import { |
||||||
|
SportTypes, |
||||||
|
ProfileTypes, |
||||||
|
PROFILE_NAMES, |
||||||
|
} from 'config' |
||||||
|
|
||||||
|
const IMAGES_URLS = { |
||||||
|
[SportTypes.BASKETBALL]: 'https://basketball.instatscout.com/images', |
||||||
|
[SportTypes.FOOTBALL]: 'https://instatscout.com/images', |
||||||
|
[SportTypes.HOCKEY]: 'https://hockey.instatscout.com/images', |
||||||
|
} |
||||||
|
|
||||||
|
type GetLogoArgs = { |
||||||
|
id: number, |
||||||
|
profileType: ProfileTypes, |
||||||
|
size?: number, |
||||||
|
sportType: SportTypes, |
||||||
|
} |
||||||
|
|
||||||
|
export const getProfileLogo = ({ |
||||||
|
id, |
||||||
|
profileType, |
||||||
|
size = 180, |
||||||
|
sportType, |
||||||
|
}: GetLogoArgs) => ( |
||||||
|
`${IMAGES_URLS[sportType]}/${PROFILE_NAMES[profileType]}/${size}/${id}.png` |
||||||
|
) |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
import { |
||||||
|
SportTypes, |
||||||
|
ProfileTypes, |
||||||
|
SPORT_NAMES, |
||||||
|
PROFILE_NAMES, |
||||||
|
} from 'config' |
||||||
|
|
||||||
|
type Args = { |
||||||
|
id: number, |
||||||
|
profileType: ProfileTypes, |
||||||
|
sportType: SportTypes, |
||||||
|
} |
||||||
|
|
||||||
|
export const getProfileUrl = ({ |
||||||
|
id, |
||||||
|
profileType, |
||||||
|
sportType, |
||||||
|
}: Args) => ( |
||||||
|
`${SPORT_NAMES[sportType]}/${PROFILE_NAMES[profileType]}/${id}` |
||||||
|
) |
||||||
@ -0,0 +1,9 @@ |
|||||||
|
import { SportTypes } from 'config' |
||||||
|
|
||||||
|
const colors = { |
||||||
|
[SportTypes.BASKETBALL]: '#f1903b', |
||||||
|
[SportTypes.FOOTBALL]: '#00a435', |
||||||
|
[SportTypes.HOCKEY]: '#5eb1ff', |
||||||
|
} |
||||||
|
|
||||||
|
export const getSportColor = (sport: SportTypes) => colors[sport] |
||||||
@ -0,0 +1,9 @@ |
|||||||
|
import { SportTypes } from 'config' |
||||||
|
|
||||||
|
const lexics = { |
||||||
|
[SportTypes.FOOTBALL]: 'football', |
||||||
|
[SportTypes.HOCKEY]: 'hockey', |
||||||
|
[SportTypes.BASKETBALL]: 'basketball', |
||||||
|
} |
||||||
|
|
||||||
|
export const getSportLexic = (sport: SportTypes) => lexics[sport] |
||||||
@ -1,29 +1,23 @@ |
|||||||
import { BaseSyntheticEvent } from 'react' |
import { BaseSyntheticEvent } from 'react' |
||||||
|
|
||||||
import { LOGOS_FALLBACKS } from 'config' |
import { |
||||||
|
SportTypes, |
||||||
|
ProfileTypes, |
||||||
|
} from 'config' |
||||||
|
import { getProfileFallbackLogo } from 'helpers/getProfileFallbackLogo' |
||||||
|
|
||||||
export type imageErrorArgs = { |
type Args = { |
||||||
e: BaseSyntheticEvent, |
e: BaseSyntheticEvent, |
||||||
sport: number, |
sport: SportTypes, |
||||||
type: number, |
type: ProfileTypes, |
||||||
} |
} |
||||||
|
|
||||||
export const SPORT_TYPES = { |
export const handleImageError = (arg: Args): void => { |
||||||
1: 'football', |
|
||||||
2: 'hockey', |
|
||||||
3: 'basketball', |
|
||||||
} as const |
|
||||||
|
|
||||||
export const DATA_TYPES = { |
|
||||||
1: 'tournaments', |
|
||||||
2: 'teams', |
|
||||||
3: 'players', |
|
||||||
} as const |
|
||||||
|
|
||||||
export const handleImageError = (arg: imageErrorArgs): void => { |
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
arg.e.target.onError = '' |
arg.e.target.onError = '' |
||||||
// @ts-expect-error
|
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
arg.e.target.src = LOGOS_FALLBACKS[SPORT_TYPES[arg.sport]][DATA_TYPES[arg.type]] |
arg.e.target.src = getProfileFallbackLogo({ |
||||||
|
profileType: arg.type, |
||||||
|
sportType: arg.sport, |
||||||
|
}) |
||||||
} |
} |
||||||
|
|||||||
@ -1,5 +1,9 @@ |
|||||||
export * from './callApi' |
export * from './callApi' |
||||||
export * from './callApi/getResponseData' |
export * from './callApi/getResponseData' |
||||||
export * from './token' |
export * from './token' |
||||||
export * from './getLogo' |
export * from './getProfileLogo' |
||||||
|
export * from './getProfileFallbackLogo' |
||||||
|
export * from './getProfileUrl' |
||||||
|
export * from './getSportColor' |
||||||
|
export * from './getSportLexic' |
||||||
export * from './handleImg' |
export * from './handleImg' |
||||||
|
|||||||
Loading…
Reference in new issue