hensei-web/components/WeaponUnit/index.tsx
Justin Edmund 7a50c4bce5 Pass down GridWeapon instead of Weapon
Previously, we stripped the Weapon out of the GridWeapon for simplicity. However, now that we need to display and manipulate data on the GridWeapon (unique data), we need to pass that down instead.
2022-02-01 05:06:27 -08:00

69 lines
2 KiB
TypeScript

import React, { useEffect, useState } from 'react'
import classnames from 'classnames'
import UncapIndicator from '~components/UncapIndicator'
import PlusIcon from '~public/icons/plus.svg'
import './index.scss'
interface Props {
onClick: () => void
gridWeapon: GridWeapon | undefined
position: number
editable: boolean
unitType: 0 | 1
}
const WeaponUnit = (props: Props) => {
const [imageUrl, setImageUrl] = useState('')
const classes = classnames({
WeaponUnit: true,
'mainhand': props.unitType == 0,
'grid': props.unitType == 1,
'editable': props.editable,
'filled': (props.gridWeapon !== undefined)
})
const weapon = props.gridWeapon?.weapon
useEffect(() => {
generateImageUrl()
})
function generateImageUrl() {
let imgSrc = ""
if (props.gridWeapon) {
const weapon = props.gridWeapon.weapon!
if (props.unitType == 0)
imgSrc = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-main/${weapon.granblue_id}.jpg`
else
imgSrc = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-grid/${weapon.granblue_id}.jpg`
}
setImageUrl(imgSrc)
}
return (
<div>
<div className={classes}>
<div className="WeaponImage" onClick={ (props.editable) ? props.onClick : () => {} }>
<img alt={weapon?.name.en} className="grid_image" src={imageUrl} />
{ (props.editable) ? <span className='icon'><PlusIcon /></span> : '' }
</div>
<h3 className="WeaponName">{weapon?.name.en}</h3>
<UncapIndicator
type="weapon"
ulb={weapon?.uncap.ulb || false}
flb={weapon?.uncap.flb || false}
uncapLevel={props.gridWeapon?.uncap_level!}
/>
</div>
</div>
)
}
export default WeaponUnit