Skip to content

Commit

Permalink
feat: use remote url when local icon is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
lgou2w committed Sep 20, 2023
1 parent d921699 commit f5044f9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/components/gacha/GachaItemView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export interface GachaItemViewProps {

export default function GachaItemView (props: GachaItemViewProps) {
const { facet, name, id, isWeapon, rank, size, usedPity, restricted, time } = props
// const src = getStaticResource(facet, isWeapon ? 'weapon' : 'character', id)
const icon = lookupAssetIcon(
facet,
isWeapon ? 'weapon' : 'character',
id
)

const category = isWeapon ? 'weapon' : 'character'
const icon = lookupAssetIcon(facet, category, id)

let src = icon?.[1]
if (!src) {
src = getRemoteResourceSrc(facet, category, id)
}

const title = !time
? name
Expand All @@ -42,16 +44,16 @@ export default function GachaItemView (props: GachaItemViewProps) {
data-restricted={restricted}
title={title}
>
<img src={icon?.[1]} alt={name} />
<img src={src} alt={name} />
{usedPity && <Typography className={`${GachaItemViewCls}-used-pity`}>{usedPity}</Typography>}
{restricted && <Typography className={`${GachaItemViewCls}-restricted`}>限定</Typography>}
</Box>
)
}

// function getStaticResource (facet: AccountFacet, namespace: string, itemIdOrName: string) {
// return `https://hoyo-gacha.lgou2w.com/static/${facet}/${namespace}/${itemIdOrName}.png`
// }
function getRemoteResourceSrc (facet: AccountFacet, category: string, itemIdOrName: string) {
return `https://hoyo-gacha.lgou2w.com/static/${facet}/${category}/${itemIdOrName}.png`
}

const GachaItemViewCls = 'gacha-item-view'
const GachaItemViewSx: SxProps<Theme> = {
Expand Down

0 comments on commit f5044f9

Please sign in to comment.