diff --git a/components/ElementToggle/index.tsx b/components/ElementToggle/index.tsx index b87e85fb..d3cdd79d 100644 --- a/components/ElementToggle/index.tsx +++ b/components/ElementToggle/index.tsx @@ -3,12 +3,13 @@ import { useRouter } from 'next/router' import { useTranslation } from 'next-i18next' import classNames from 'classnames' +import * as ElementTransformer from '~transformers/ElementTransformer' import * as ToggleGroup from '@radix-ui/react-toggle-group' import styles from './index.module.scss' interface Props { - currentElement: number - sendValue: (value: number) => void + currentElement: GranblueElement + sendValue: (value: GranblueElement) => void } const ElementToggle = ({ currentElement, sendValue, ...props }: Props) => { @@ -24,7 +25,7 @@ const ElementToggle = ({ currentElement, sendValue, ...props }: Props) => { // Methods: Handlers const handleElementChange = (value: string) => { - const newElement = parseInt(value) + const newElement = ElementTransformer.toObject(parseInt(value)) setElement(newElement) sendValue(newElement) } diff --git a/components/GridRep/index.tsx b/components/GridRep/index.tsx index 11220f95..b1c92db6 100644 --- a/components/GridRep/index.tsx +++ b/components/GridRep/index.tsx @@ -8,6 +8,7 @@ import 'fix-date' import { accountState } from '~utils/accountState' import { formatTimeAgo } from '~utils/timeAgo' +import { ElementMap } from '~utils/elements' import Button from '~components/common/Button' @@ -19,8 +20,11 @@ interface Props { shortcode: string id: string name: string - raid: Raid - grid: GridWeapon[] + raid?: Raid + weapons: { + mainWeapon?: GridWeapon + allWeapons: GridArray + } user?: User fullAuto: boolean autoGuard: boolean @@ -69,27 +73,10 @@ const GridRep = (props: Props) => { }) useEffect(() => { - const newWeapons = Array(numWeapons) - const gridWeapons = Array(numWeapons) - - let foundMainhand = false - for (const [key, value] of Object.entries(props.grid)) { - if (value.position == -1) { - setMainhand(value.object) - foundMainhand = true - } else if (!value.mainhand && value.position != null) { - newWeapons[value.position] = value.object - gridWeapons[value.position] = value - } - } - - if (!foundMainhand) { - setMainhand(undefined) - } - - setWeapons(newWeapons) - setGrid(gridWeapons) - }, [props.grid]) + setMainhand(props.weapons.mainWeapon?.object) + setWeapons(Object.values(props.weapons.allWeapons).map((w) => w?.object)) + setGrid(props.weapons.allWeapons) + }, [props.weapons]) function navigate() { props.onClick(props.shortcode) @@ -99,22 +86,16 @@ const GridRep = (props: Props) => { let url = '' if (mainhand) { - const weapon = Object.values(props.grid).find( - (w) => w && w.object.id === mainhand.id - ) + const weapon = props.weapons.mainWeapon - if (mainhand.element == 0 && weapon && weapon.element) { - url = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-main/${mainhand.granblue_id}_${weapon.element}.jpg` + if (mainhand.element === ElementMap.null && weapon && weapon.element) { + url = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-main/${mainhand.granblueId}_${weapon.element}.jpg` } else { - url = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-main/${mainhand.granblue_id}.jpg` + url = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-main/${mainhand.granblueId}.jpg` } } - return mainhand && props.grid[0] ? ( - {mainhand.name[locale]} - ) : ( - '' - ) + return mainhand && {mainhand.name[locale]} } function generateGridImage(position: number) { @@ -124,17 +105,17 @@ const GridRep = (props: Props) => { const gridWeapon = grid[position] if (weapon && gridWeapon) { - if (weapon.element == 0 && gridWeapon.element) { - url = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-grid/${weapon.granblue_id}_${gridWeapon.element}.jpg` + if (weapon.element === ElementMap.null && gridWeapon.element) { + url = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-grid/${weapon.granblueId}_${gridWeapon.element}.jpg` } else { - url = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-grid/${weapon.granblue_id}.jpg` + url = `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-grid/${weapon.granblueId}.jpg` } } - return weapons[position] ? ( - {weapons[position]?.name[locale]} - ) : ( - '' + return ( + weapons[position] && ( + {weapons[position]?.name[locale]} + ) ) } @@ -215,24 +196,22 @@ const GridRep = (props: Props) => { {account.authorized && - ((props.user && account.user && account.user.id !== props.user.id) || - !props.user) ? ( - -