From 907d9f05e4497ddaf4ae844264f668b1c7607442 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Tue, 25 Jan 2022 14:27:48 -0800 Subject: [PATCH] Lift SearchModal out of CharacterUnit --- components/CharacterGrid/index.tsx | 34 +++++++++++++++++++++++++++++- components/CharacterUnit/index.tsx | 33 ++++------------------------- components/SearchModal/index.tsx | 1 + 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/components/CharacterGrid/index.tsx b/components/CharacterGrid/index.tsx index cb19fcb9..dc7b043f 100644 --- a/components/CharacterGrid/index.tsx +++ b/components/CharacterGrid/index.tsx @@ -1,5 +1,8 @@ import React, { useState } from 'react' +import { useModal as useModal } from '~utils/useModal' + import CharacterUnit from '~components/CharacterUnit' +import SearchModal from '~components/SearchModal' import './index.scss' @@ -19,12 +22,31 @@ interface Props { } const CharacterGrid = (props: Props) => { + const { open, openModal, closeModal } = useModal() + const [searchPosition, setSearchPosition] = useState(0) + const numCharacters: number = 5 + function isCharacter(object: Character | Weapon | Summon): object is Character { + // There aren't really any unique fields here + return (object as Character).gender !== undefined + } + + function openSearchModal(position: number) { + setSearchPosition(position) + openModal() + } + function receiveCharacter(character: Character, position: number) { props.onSelect(GridType.Character, character, position) } + function sendData(object: Character | Weapon | Summon, position: number) { + if (isCharacter(object)) { + receiveCharacter(object, position) + } + } + return (
) diff --git a/components/CharacterUnit/index.tsx b/components/CharacterUnit/index.tsx index 72149e2c..27b36ace 100644 --- a/components/CharacterUnit/index.tsx +++ b/components/CharacterUnit/index.tsx @@ -1,8 +1,6 @@ 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 PlusIcon from '~public/icons/plus.svg' @@ -10,7 +8,7 @@ import PlusIcon from '~public/icons/plus.svg' import './index.scss' interface Props { - onReceiveData: (character: Character, position: number) => void + onClick: () => void character: Character | undefined position: number editable: boolean @@ -18,9 +16,6 @@ interface Props { const CharacterUnit = (props: Props) => { const [imageUrl, setImageUrl] = useState('') - const { open, openModal, closeModal } = useModal() - - const openModalIfEditable = (props.editable) ? openModal : () => {} const classes = classnames({ CharacterUnit: true, @@ -40,27 +35,16 @@ const CharacterUnit = (props: Props) => { if (props.character) { const character = props.character! - imgSrc = `/images/chara-main/${character.granblue_id}.jpg` + imgSrc = `/images/chara-main/${character.granblue_id}_01.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 (
-
-
+
+
{character?.name.en} { (props.editable) ? : '' }
@@ -71,15 +55,6 @@ const CharacterUnit = (props: Props) => { />

{character?.name.en}

- {open ? ( - - ) : null}
) } diff --git a/components/SearchModal/index.tsx b/components/SearchModal/index.tsx index 3deb3b77..1e351c5e 100644 --- a/components/SearchModal/index.tsx +++ b/components/SearchModal/index.tsx @@ -15,6 +15,7 @@ import PlusIcon from '~public/icons/plus.svg' interface Props { close: () => void send: (object: Character | Weapon | Summon, position: number) => any + grid: GridArray placeholderText: string fromPosition: number object: 'weapons' | 'characters' | 'summons'