diff --git a/src/components/CharacterUnit/index.css b/src/components/CharacterUnit/index.css index ad331752..36451439 100644 --- a/src/components/CharacterUnit/index.css +++ b/src/components/CharacterUnit/index.css @@ -40,9 +40,12 @@ .CharacterUnit h3 { color: #333; + font-size: 14px; font-weight: 500; margin: 0; + max-width: 131px; text-align: center; + word-wrap: normal; } .CharacterUnit img { diff --git a/src/components/CharacterUnit/index.tsx b/src/components/CharacterUnit/index.tsx index 6c654e1b..e0ca2abf 100644 --- a/src/components/CharacterUnit/index.tsx +++ b/src/components/CharacterUnit/index.tsx @@ -1,9 +1,13 @@ -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import classnames from 'classnames' +import { useModal as useModal } from '~utils/useModal' + +import SearchModal from '~components/SearchModal' import UncapIndicator from '~components/UncapIndicator' import './index.css' +import images from '../../images/chara-main/*.jpg' import Plus from '../../../assets/plus.svg' interface Props { @@ -14,7 +18,8 @@ interface Props { } const CharacterUnit = (props: Props) => { - const openModal = () => {} + const [imageUrl, setImageUrl] = useState('') + const { open, openModal, closeModal } = useModal() const openModalIfEditable = (props.editable) ? openModal : () => {} @@ -26,19 +31,65 @@ const CharacterUnit = (props: Props) => { const character = props.character + useEffect(() => { + generateImageUrl() + }) + + function generateImageUrl() { + let imgSrc + if (props.character) { + const character = props.character! + + // Generate the correct source for the weapon + if (process.env.NODE_ENV === 'development') { + imgSrc = images[character.granblue_id] + } else if (process.env.NODE_ENV === 'production') { + imgSrc = `${process.env.SIERO_IMG_URL}/chara-main/${character.granblue_id}.jpg` + } + } + + setImageUrl(imgSrc) + } + + function sendData(object: Character | Weapon | Summon, position: number) { + if (isCharacter(object)) { + props.onReceiveData(object, position) + } + } + + function isCharacter(object: Character | Weapon | Summon): object is Character { + // There aren't really any unique fields here + return (object as Character).gender !== undefined + } + return (
+ { + (imageUrl != '') + ? + : + + } { (props.editable) ? : '' }

{character?.name.en}

+ {open ? ( + + ) : null}
) }