From d42927623ef0a3600e8dfee7b0cdccfe3026b57d Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 7 Jul 2023 05:43:02 -0700 Subject: [PATCH] Update all files with new object structure --- components/ElementToggle/index.tsx | 7 +- components/GridRep/index.tsx | 97 +++++------ components/HovercardHeader/index.tsx | 34 ++-- components/Layout/index.tsx | 2 +- components/MentionList/index.tsx | 8 +- components/about/ChangelogUnit/index.tsx | 4 +- .../CharacterConflictModal/index.tsx | 16 +- components/character/CharacterGrid/index.tsx | 34 ++-- .../character/CharacterHovercard/index.tsx | 23 ++- components/character/CharacterModal/index.tsx | 55 ++++--- .../character/CharacterResult/index.tsx | 8 +- components/character/CharacterUnit/index.tsx | 38 +++-- components/common/TableField/index.tsx | 39 ++--- components/extra/GuidebookResult/index.tsx | 2 +- components/extra/GuidebookUnit/index.tsx | 2 +- .../job/JobAccessoryItem/index.module.scss | 2 +- components/job/JobAccessoryItem/index.tsx | 4 +- .../job/JobAccessoryPopover/index.module.scss | 8 +- components/job/JobAccessoryPopover/index.tsx | 9 +- components/job/JobDropdown/index.tsx | 8 +- components/job/JobImage/index.tsx | 35 ++-- components/job/JobSection/index.tsx | 27 +-- components/job/JobSkillItem/index.tsx | 2 +- components/mastery/AxSelect/index.tsx | 2 +- components/mastery/RingSelect/index.tsx | 12 +- components/party/EditPartyModal/index.tsx | 35 ++-- components/party/Party/index.tsx | 103 ++++++------ components/party/PartyFooter/index.tsx | 24 +-- components/party/PartyHeader/index.tsx | 97 ++++++----- .../party/PartySegmentedControl/index.tsx | 22 +-- components/raids/RaidCombobox/index.tsx | 20 ++- components/reps/CharacterRep/index.tsx | 36 ++-- components/reps/SummonRep/index.tsx | 42 +++-- components/reps/WeaponRep/index.tsx | 25 ++- components/search/SearchModal/index.tsx | 4 +- components/summon/SummonGrid/index.tsx | 42 ++--- components/summon/SummonHovercard/index.tsx | 15 +- components/summon/SummonResult/index.tsx | 6 +- .../summon/SummonSearchFilterBar/index.tsx | 2 - components/summon/SummonUnit/index.tsx | 24 +-- .../weapon/WeaponConflictModal/index.tsx | 2 +- components/weapon/WeaponGrid/index.tsx | 71 ++++---- components/weapon/WeaponHovercard/index.tsx | 84 +++++----- components/weapon/WeaponKeySelect/index.tsx | 4 +- components/weapon/WeaponModal/index.tsx | 50 +++--- components/weapon/WeaponResult/index.tsx | 5 +- .../weapon/WeaponSearchFilterBar/index.tsx | 2 - components/weapon/WeaponUnit/index.tsx | 108 ++++++------ data/awakening.tsx | 2 +- data/ax.tsx | 154 +++++++++--------- data/overMastery.tsx | 58 +++---- pages/[username].tsx | 24 ++- pages/p/[party].tsx | 51 +++--- pages/saved.tsx | 14 +- pages/teams.tsx | 20 ++- transformers/CharacterTransformer.tsx | 2 +- transformers/GridCharacterTransformer.tsx | 4 +- transformers/GridSummonTransformer.tsx | 4 +- transformers/GridTransformer.tsx | 31 ++++ transformers/GridWeaponTransformer.tsx | 4 +- transformers/JobAccessoryTransformer.tsx | 2 +- transformers/JobTransformer.tsx | 2 +- transformers/PartyTransformer.tsx | 9 +- transformers/SummonTransformer.tsx | 2 +- transformers/WeaponKeyTransformer.tsx | 2 +- transformers/WeaponTransformer.tsx | 2 +- types/Grid.d.ts | 12 ++ types/GridCharacterParams.d.ts | 2 +- types/GridSummonParams.d.ts | 2 +- types/GridWeaponParams.d.ts | 2 +- types/Guidebook.d.ts | 2 +- types/ItemSkill.d.ts | 2 +- types/Party.d.ts | 7 +- utils/api.tsx | 2 +- utils/appState.tsx | 147 +++++++---------- utils/elementEmoji.tsx | 17 +- utils/elementalizeAetherialMastery.tsx | 8 +- utils/elements.tsx | 10 ++ utils/getElementForParty.tsx | 6 +- utils/mentionSuggestions.tsx | 12 +- 80 files changed, 990 insertions(+), 929 deletions(-) create mode 100644 transformers/GridTransformer.tsx create mode 100644 types/Grid.d.ts 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) ? ( - -