|
|
|
|
@ -1,5 +1,16 @@ |
|
|
|
|
import { |
|
|
|
|
Fragment, |
|
|
|
|
useEffect, |
|
|
|
|
useState, |
|
|
|
|
} from 'react' |
|
|
|
|
|
|
|
|
|
import { ProfileTypes, SportTypes } from 'config' |
|
|
|
|
import { getProfileFallbackLogo, getProfileLogo } from 'helpers' |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
getProfileFallbackLogo, |
|
|
|
|
getProfileLogo, |
|
|
|
|
readToken, |
|
|
|
|
} from 'helpers' |
|
|
|
|
|
|
|
|
|
import { Image } from 'features/Common' |
|
|
|
|
import type { ObjectWithName } from 'features/Name' |
|
|
|
|
@ -10,8 +21,7 @@ type ProfileImageProps = { |
|
|
|
|
altNameObj?: ObjectWithName, |
|
|
|
|
className?: string, |
|
|
|
|
id: number, |
|
|
|
|
isTournamentSuper?: boolean, |
|
|
|
|
lazy?: boolean, |
|
|
|
|
logoUrl?: string | null, |
|
|
|
|
nameAsTitle?: boolean, |
|
|
|
|
onLoad?: () => void, |
|
|
|
|
prefix?: string, |
|
|
|
|
@ -21,13 +31,19 @@ type ProfileImageProps = { |
|
|
|
|
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, |
|
|
|
|
className, |
|
|
|
|
id, |
|
|
|
|
isTournamentSuper, |
|
|
|
|
lazy = false, |
|
|
|
|
logoUrl, |
|
|
|
|
nameAsTitle, |
|
|
|
|
onLoad, |
|
|
|
|
prefix, |
|
|
|
|
@ -36,26 +52,66 @@ export const ProfileLogo = ({ |
|
|
|
|
sportType, |
|
|
|
|
title, |
|
|
|
|
}: ProfileImageProps) => { |
|
|
|
|
const [imageSource, setImageSource] = useState('') |
|
|
|
|
|
|
|
|
|
const altName = useName(altNameObj || {}, prefix) |
|
|
|
|
const titleText = nameAsTitle ? altName : title |
|
|
|
|
const src = getProfileLogo({ |
|
|
|
|
const awsSrc = getProfileLogo({ |
|
|
|
|
awsInError: false, |
|
|
|
|
id, |
|
|
|
|
profileType, |
|
|
|
|
size, |
|
|
|
|
sportType, |
|
|
|
|
}) |
|
|
|
|
const scoutSrc = getProfileLogo({ |
|
|
|
|
awsInError: true, |
|
|
|
|
id, |
|
|
|
|
isTournamentSuper, |
|
|
|
|
profileType, |
|
|
|
|
size, |
|
|
|
|
sportType, |
|
|
|
|
}) |
|
|
|
|
const fallbackSrc = getProfileFallbackLogo(profileType) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
(async () => { |
|
|
|
|
if (!logoUrl) { |
|
|
|
|
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]) |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<Image |
|
|
|
|
alt={alt || altName} |
|
|
|
|
src={lazy ? '' : src} |
|
|
|
|
dataSrc={lazy ? src : ''} |
|
|
|
|
fallbackSrc={fallbackSrc} |
|
|
|
|
className={className} |
|
|
|
|
onLoad={onLoad} |
|
|
|
|
title={titleText} |
|
|
|
|
/> |
|
|
|
|
<Fragment> |
|
|
|
|
{Boolean(imageSource) && ( |
|
|
|
|
<Image |
|
|
|
|
alt={alt || altName} |
|
|
|
|
src={imageSource} |
|
|
|
|
fallbackSrc={fallbackSrc} |
|
|
|
|
className={className} |
|
|
|
|
onLoad={onLoad} |
|
|
|
|
title={titleText} |
|
|
|
|
/> |
|
|
|
|
)} |
|
|
|
|
</Fragment> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|