From 5b9130eb1148e8b3299c67dfd44c249fc719d2dd Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Thu, 26 Jan 2023 19:39:30 +0700 Subject: [PATCH] fix(#258): change link for aws logo --- src/components/ItemInfo/ItemInfo.tsx | 11 ++++- src/config/routes.tsx | 1 + .../components/GroupBlock/index.tsx | 4 +- src/features/ItemsList/index.tsx | 8 ++- .../components/FavouriteTeam/index.tsx | 5 +- .../components/TournamentInfo/index.tsx | 3 +- src/features/ProfileCard/index.tsx | 8 ++- src/features/ProfileLogo/index.tsx | 49 +------------------ .../components/CollapseTournament/index.tsx | 4 +- .../components/TournamentMobile/index.tsx | 3 +- src/features/TournamentSubtitle/index.tsx | 8 ++- .../UserFavorites/TooltipBlock/index.tsx | 4 +- .../getProfileLogo/__tests__/index.tsx | 6 +-- src/helpers/getProfileLogo/index.tsx | 27 ++-------- .../components/MatchesHighlights/index.tsx | 3 +- src/utilits/mirage/Mirage.tsx | 2 +- 16 files changed, 56 insertions(+), 90 deletions(-) diff --git a/src/components/ItemInfo/ItemInfo.tsx b/src/components/ItemInfo/ItemInfo.tsx index 3dc2af82..e5814204 100644 --- a/src/components/ItemInfo/ItemInfo.tsx +++ b/src/components/ItemInfo/ItemInfo.tsx @@ -1,4 +1,9 @@ -import { ProfileTypes, PROFILE_NAMES } from 'config' +import { + ProfileTypes, + PROFILE_NAMES, + SportTypes, + URL_AWS, +} from 'config' import { ScWrapper, @@ -11,6 +16,7 @@ type ItemInfoType = { id: number, name: string, onClick: (val: any) => void, + sportId: SportTypes, type: ProfileTypes, } export const ItemInfo = ({ @@ -18,10 +24,11 @@ export const ItemInfo = ({ id, name, onClick, + sportId, type, }: ItemInfoType) => ( - + {name} ) diff --git a/src/config/routes.tsx b/src/config/routes.tsx index 178b420b..dd866e19 100644 --- a/src/config/routes.tsx +++ b/src/config/routes.tsx @@ -29,3 +29,4 @@ export const VIEWS_API = VIEWS_APIS[env] export const AUTH_SERVICE = APIS[env].auth export const API_ROOT = APIS[env].api export const DATA_URL = `${API_ROOT}/data` +export const URL_AWS = 'https://cf-aws.insports.tv' diff --git a/src/features/FavoritesMobilePopup/components/GroupBlock/index.tsx b/src/features/FavoritesMobilePopup/components/GroupBlock/index.tsx index 94e08c0d..da50381a 100644 --- a/src/features/FavoritesMobilePopup/components/GroupBlock/index.tsx +++ b/src/features/FavoritesMobilePopup/components/GroupBlock/index.tsx @@ -2,6 +2,8 @@ import { useState } from 'react' import map from 'lodash/map' +import { URL_AWS } from 'config' + import type { UserFavorites } from 'requests/getUserSportFavs' import { T9n } from 'features/T9n' import { SportIcon } from 'components/SportIcon/SportIcon' @@ -69,7 +71,7 @@ export const GroupBlock = ({ groupBlock }: Props) => { {name} - + {countryOrTeam} diff --git a/src/features/ItemsList/index.tsx b/src/features/ItemsList/index.tsx index 1f9534c7..b13ed09c 100644 --- a/src/features/ItemsList/index.tsx +++ b/src/features/ItemsList/index.tsx @@ -2,7 +2,11 @@ import { Fragment } from 'react' import map from 'lodash/map' -import { SportTypes, ProfileTypes } from 'config' +import { + SportTypes, + ProfileTypes, + URL_AWS, +} from 'config' import { isMobileDevice } from 'config/userAgent' import { Gender } from 'requests' @@ -55,7 +59,7 @@ export const ItemsList = ({ {item.additionalInfo && ( - + )} diff --git a/src/features/MatchPage/components/FavouriteTeam/index.tsx b/src/features/MatchPage/components/FavouriteTeam/index.tsx index f88ff7a2..a32cf367 100644 --- a/src/features/MatchPage/components/FavouriteTeam/index.tsx +++ b/src/features/MatchPage/components/FavouriteTeam/index.tsx @@ -1,11 +1,12 @@ import { T9n } from 'features/T9n' - import { Wrapper } from 'features/PreferencesPopup/styled' import { ItemInfo } from 'components/ItemInfo/ItemInfo' import type { FavouriteTeams } from 'requests/getFavouriteTeam' +import { SportTypes } from 'config' + import { useFavouriteTeam } from './hooks' import { @@ -49,6 +50,7 @@ export const FavouriteTeamPopup = () => { key={team.id} id={team.id} name={team.name_en} + sportId={SportTypes.FOOTBALL} type={2} onClick={() => changeActive(team)} /> @@ -66,6 +68,7 @@ export const FavouriteTeamPopup = () => { key={team.id} id={team.id} name={team.name_en} + sportId={SportTypes.FOOTBALL} type={2} onClick={() => changeActive(team)} /> diff --git a/src/features/PreferencesPopup/components/TournamentInfo/index.tsx b/src/features/PreferencesPopup/components/TournamentInfo/index.tsx index ac4c53fd..95f4ea05 100644 --- a/src/features/PreferencesPopup/components/TournamentInfo/index.tsx +++ b/src/features/PreferencesPopup/components/TournamentInfo/index.tsx @@ -1,6 +1,7 @@ import styled, { css } from 'styled-components/macro' import { isMobileDevice } from 'config/userAgent' +import { URL_AWS } from 'config' import type { Tournament } from 'requests/getSportTournaments' @@ -51,7 +52,7 @@ export const TournamentInfo = ({ {isIcon && } - + diff --git a/src/features/ProfileCard/index.tsx b/src/features/ProfileCard/index.tsx index 464b42d6..d09e915d 100644 --- a/src/features/ProfileCard/index.tsx +++ b/src/features/ProfileCard/index.tsx @@ -4,7 +4,11 @@ import { Link } from 'react-router-dom' import type { ObjectWithName } from 'features/Name' -import { PAGES, ProfileTypes } from 'config' +import { + PAGES, + ProfileTypes, + URL_AWS, +} from 'config' import { client, isLffClient } from 'config/clients' import { ClientNames } from 'config/clients/types' @@ -75,7 +79,7 @@ export const ProfileCard = ({ profile }: ProfileType) => {
{name} - + {tournamentId ? ( void, prefix?: string, profileType: ProfileTypes, - size?: number, sportType: SportTypes, title?: string, } -type AwsMediaFlags = { - cover_url: 'string' | null, - landing_mobile_url: 'string' | null, - landing_url: 'string' | null, - logo_url: 'string' | null, -} - export const ProfileLogo = ({ alt, altNameObj, @@ -48,7 +39,6 @@ export const ProfileLogo = ({ onLoad, prefix, profileType, - size, sportType, title, }: ProfileImageProps) => { @@ -57,50 +47,15 @@ export const ProfileLogo = ({ const altName = useName(altNameObj || {}, prefix) const titleText = nameAsTitle ? altName : title const awsSrc = getProfileLogo({ - awsInError: false, id, profileType, - size, - sportType, - }) - const scoutSrc = getProfileLogo({ - awsInError: true, - id, - profileType, - size, sportType, }) const fallbackSrc = getProfileFallbackLogo(profileType) useEffect(() => { - (async () => { - // если нет logoUrl, то нужно делать запрос в aws - // если logoUrl === null, то это уже ответ с aws - if (logoUrl === null) { - setImageSource(scoutSrc) - return - } - - if (logoUrl) { - setImageSource(logoUrl) - return - } - - try { - const { logo_url }: AwsMediaFlags = await (await fetch(awsSrc, { - headers: { Authorization: `Bearer ${readToken()}` }, - })).json() - - if (logo_url) { - setImageSource(logo_url) - return - } - setImageSource(scoutSrc) - } catch (error) { - setImageSource(scoutSrc) - } - })() - }, [awsSrc, logoUrl, scoutSrc]) + setImageSource(logoUrl || awsSrc) + }, [awsSrc, logoUrl]) return ( diff --git a/src/features/TournamentList/components/CollapseTournament/index.tsx b/src/features/TournamentList/components/CollapseTournament/index.tsx index a796c808..5992b826 100644 --- a/src/features/TournamentList/components/CollapseTournament/index.tsx +++ b/src/features/TournamentList/components/CollapseTournament/index.tsx @@ -1,4 +1,4 @@ -import { ProfileTypes } from 'config' +import { ProfileTypes, URL_AWS } from 'config' import { T9n } from 'features/T9n' import { Icon } from 'features/Icon' @@ -93,7 +93,7 @@ export const CollapseTournament = ({ {countryInfo && ( diff --git a/src/features/TournamentList/components/TournamentMobile/index.tsx b/src/features/TournamentList/components/TournamentMobile/index.tsx index 69f6e0c4..ef131655 100644 --- a/src/features/TournamentList/components/TournamentMobile/index.tsx +++ b/src/features/TournamentList/components/TournamentMobile/index.tsx @@ -1,6 +1,7 @@ import { Fragment, useState } from 'react' import { isLffClient } from 'config/clients' +import { URL_AWS } from 'config' import { SportIcon } from 'components/SportIcon/SportIcon' import { T9n } from 'features/T9n' @@ -54,7 +55,7 @@ export const TournamentMobile = ({ sport={sportType} /> )} diff --git a/src/features/TournamentSubtitle/index.tsx b/src/features/TournamentSubtitle/index.tsx index 897db6a9..579b42d4 100644 --- a/src/features/TournamentSubtitle/index.tsx +++ b/src/features/TournamentSubtitle/index.tsx @@ -6,7 +6,11 @@ import { Name } from 'features/Name' import { T9n } from 'features/T9n' import { useUserFavoritesStore } from 'features/UserFavorites/store' -import { ProfileTypes, SportTypes } from 'config' +import { + ProfileTypes, + SportTypes, + URL_AWS, +} from 'config' import { isLffClient } from 'config/clients' import { isMobileDevice } from 'config/userAgent' @@ -72,7 +76,7 @@ export const TournamentSubtitle = ({ )} - + {countryInfo && ( diff --git a/src/features/UserFavorites/TooltipBlock/index.tsx b/src/features/UserFavorites/TooltipBlock/index.tsx index bc7c62ec..f9f39094 100644 --- a/src/features/UserFavorites/TooltipBlock/index.tsx +++ b/src/features/UserFavorites/TooltipBlock/index.tsx @@ -2,6 +2,8 @@ import { UserFavorite } from 'requests' import { Name, useName } from 'features/Name' +import { URL_AWS } from 'config' + import { TooltipBlockWrapper, TooltipBlockItem, @@ -32,7 +34,7 @@ export const TooltipBlock = ({ {info?.team && }{' '} - {info?.country && } + {info?.country && } ) diff --git a/src/helpers/getProfileLogo/__tests__/index.tsx b/src/helpers/getProfileLogo/__tests__/index.tsx index c08f2ee4..f847b03d 100644 --- a/src/helpers/getProfileLogo/__tests__/index.tsx +++ b/src/helpers/getProfileLogo/__tests__/index.tsx @@ -8,18 +8,18 @@ describe('getLogo helper', () => { id: 1, profileType: ProfileTypes.PLAYERS, sportType: SportTypes.FOOTBALL, - })).toBe('https://api.test.insports.tv/v1/players/1/1/media') + })).toBe('https://cf-aws.insports.tv/media/players/1/1/photo.png') expect(getProfileLogo({ id: 1, profileType: ProfileTypes.TEAMS, sportType: SportTypes.BASKETBALL, - })).toBe('https://api.test.insports.tv/v1/teams/3/1/media') + })).toBe('https://cf-aws.insports.tv/media/teams/3/1/logo.jpg') expect(getProfileLogo({ id: 1, profileType: ProfileTypes.TOURNAMENTS, sportType: SportTypes.HOCKEY, - })).toBe('https://api.test.insports.tv/v1/tournaments/2/1/media') + })).toBe('https://cf-aws.insports.tv/media/tournaments/2/1/logo.jpg') }) }) diff --git a/src/helpers/getProfileLogo/index.tsx b/src/helpers/getProfileLogo/index.tsx index 746c53df..448c8d06 100644 --- a/src/helpers/getProfileLogo/index.tsx +++ b/src/helpers/getProfileLogo/index.tsx @@ -1,37 +1,18 @@ import { - SportTypes, - ProfileTypes, PROFILE_NAMES, - API_ROOT, + ProfileTypes, + SportTypes, + URL_AWS, } from 'config' -const IMAGES_URLS = { - [SportTypes.BASKETBALL]: 'https://basketball.instatscout.com/images', - [SportTypes.BOXING]: 'https://boxing.instatscout.com/images', - [SportTypes.FOOTBALL]: 'https://instatscout.com/images', - [SportTypes.HOCKEY]: 'https://hockey.instatscout.com/images', - [SportTypes.HANDBALL]: 'https://handball.instatscout.com/images', - [SportTypes.STREETBALL]: 'https://streetball.instatscout.com/images', - [SportTypes.VOLLEYBALL]: 'https://volleyball.instatscout.com/images', -} - type GetLogoArgs = { - awsInError?: boolean, id: number, profileType: ProfileTypes, - size?: number, sportType: SportTypes, } export const getProfileLogo = ({ - awsInError, id, profileType, - size = 180, sportType, -}: GetLogoArgs) => { - if (awsInError) { - return `${IMAGES_URLS[sportType]}/${PROFILE_NAMES[profileType]}/${size}/${id}.png` - } - return `${API_ROOT}/v1/${PROFILE_NAMES[profileType]}/${sportType}/${id}/media` -} +}: GetLogoArgs) => `${URL_AWS}/media/${PROFILE_NAMES[profileType]}/${sportType}/${id}/${profileType === ProfileTypes.PLAYERS ? 'photo.png' : 'logo.jpg'}` diff --git a/src/pages/HighlightsPage/components/MatchesHighlights/index.tsx b/src/pages/HighlightsPage/components/MatchesHighlights/index.tsx index 4c164e73..b001c68a 100644 --- a/src/pages/HighlightsPage/components/MatchesHighlights/index.tsx +++ b/src/pages/HighlightsPage/components/MatchesHighlights/index.tsx @@ -8,6 +8,7 @@ import { SportIcon } from 'features/SportIcon' import { ArrowLoader } from 'features/ArrowLoader' import { isMobileDevice } from 'config/userAgent' +import { URL_AWS } from 'config' import { dateForIos } from 'helpers/dateForIos' @@ -75,7 +76,7 @@ export const MatchesHighlights = () => { {tournament.name_eng} diff --git a/src/utilits/mirage/Mirage.tsx b/src/utilits/mirage/Mirage.tsx index 41d8521f..b685e049 100644 --- a/src/utilits/mirage/Mirage.tsx +++ b/src/utilits/mirage/Mirage.tsx @@ -23,7 +23,7 @@ export function makeServer({ environment = 'test' } = {}) { this.passthrough('https://insports.tv/***') this.passthrough('https://images.insports.tv/***') this.passthrough('https://auth.insports.tv/***') - this.passthrough('https://cf-aws.insports.tv/***') + this.passthrough('${URL_AWS}/***') this.get('https://api.insports.tv/v1/survey/teams/1/131/30', (schema: any) => schema.all('surveys').models[0].attrs) }, })