From aee641f27e78db02b83b01c6b15ac8c51d201261 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 18 Jun 2023 15:36:24 -0700 Subject: [PATCH] Use snapshot for segment reps Using snapshots lets that data be reactive. Also removed extra dependencies and fixed a bug in how SummonRep displayed sub-summons --- .../party/PartySegmentedControl/index.tsx | 35 +++++++++++-------- components/reps/SummonRep/index.tsx | 7 ++-- components/reps/WeaponRep/index.tsx | 3 -- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/components/party/PartySegmentedControl/index.tsx b/components/party/PartySegmentedControl/index.tsx index b84caaf4..e45fb56e 100644 --- a/components/party/PartySegmentedControl/index.tsx +++ b/components/party/PartySegmentedControl/index.tsx @@ -1,20 +1,25 @@ import React from 'react' import { useSnapshot } from 'valtio' import { useTranslation } from 'next-i18next' +import classNames from 'classnames' import { appState } from '~utils/appState' +import { accountState } from '~utils/accountState' import SegmentedControl from '~components/common/SegmentedControl' +import RepSegment from '~components/reps/RepSegment' +import CharacterRep from '~components/reps/CharacterRep' +import WeaponRep from '~components/reps/WeaponRep' +import SummonRep from '~components/reps/SummonRep' import { GridType } from '~utils/enums' import './index.scss' -import classNames from 'classnames' -import RepSegment from '~components/reps/RepSegment' -import CharacterRep from '~components/reps/CharacterRep' -import { accountState } from '~utils/accountState' -import WeaponRep from '~components/reps/WeaponRep' -import SummonRep from '~components/reps/SummonRep' + +// Fix for valtio readonly array +declare module 'valtio' { + function useSnapshot(p: T): T +} interface Props { selectedTab: GridType @@ -27,7 +32,7 @@ const PartySegmentedControl = (props: Props) => { const { party, grid } = useSnapshot(appState) - function getElement() { + const getElement = () => { let element: number = 0 if (party.element == 0 && grid.weapons.mainWeapon) element = grid.weapons.mainWeapon.element @@ -55,16 +60,16 @@ const PartySegmentedControl = (props: Props) => { controlGroup="grid" inputName="characters" name={t('party.segmented_control.characters')} - selected={props.selectedTab == GridType.Character} + selected={props.selectedTab === GridType.Character} onClick={props.onClick} > ) @@ -77,10 +82,10 @@ const PartySegmentedControl = (props: Props) => { controlGroup="grid" inputName="weapons" name="Weapons" - selected={props.selectedTab == GridType.Weapon} + selected={props.selectedTab === GridType.Weapon} onClick={props.onClick} > - + ) } @@ -92,10 +97,10 @@ const PartySegmentedControl = (props: Props) => { controlGroup="grid" inputName="summons" name="Summons" - selected={props.selectedTab == GridType.Summon} + selected={props.selectedTab === GridType.Summon} onClick={props.onClick} > - + ) } diff --git a/components/reps/SummonRep/index.tsx b/components/reps/SummonRep/index.tsx index a1a377d5..86ff0b76 100644 --- a/components/reps/SummonRep/index.tsx +++ b/components/reps/SummonRep/index.tsx @@ -1,7 +1,5 @@ import React, { useEffect, useState } from 'react' import { useRouter } from 'next/router' -import { useTranslation } from 'next-i18next' -import 'fix-date' import './index.scss' @@ -18,7 +16,6 @@ const SUMMONS_COUNT = 4 const SummonRep = (props: Props) => { // Localization for alt tags const router = useRouter() - const { t } = useTranslation('common') const locale = router.locale && ['en', 'ja'].includes(router.locale) ? router.locale : 'en' @@ -159,8 +156,8 @@ const SummonRep = (props: Props) => {
    {Array.from(Array(SUMMONS_COUNT)).map((x, i) => { return ( -
  • - {generateGridImage(i + 1)} +
  • + {generateGridImage(i)}
  • ) })} diff --git a/components/reps/WeaponRep/index.tsx b/components/reps/WeaponRep/index.tsx index 4cecdd29..53fa18b2 100644 --- a/components/reps/WeaponRep/index.tsx +++ b/components/reps/WeaponRep/index.tsx @@ -1,7 +1,5 @@ import React, { useEffect, useState } from 'react' import { useRouter } from 'next/router' -import { useTranslation } from 'next-i18next' -import 'fix-date' import './index.scss' @@ -17,7 +15,6 @@ const WEAPONS_COUNT = 9 const WeaponRep = (props: Props) => { // Localization for alt tags const router = useRouter() - const { t } = useTranslation('common') const locale = router.locale && ['en', 'ja'].includes(router.locale) ? router.locale : 'en'