From f7b3139abfa436b82b4185dacaf340b596e81ebd Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 2 Jul 2023 16:19:19 -0700 Subject: [PATCH] Normalize over mastery object The over mastery object was sometimes 0-index, sometimes 1-index. This normalizes it to be 1-indexed, even though that is a little silly. I think this is the lesser amount of work though, since normalizing against 0-index might require API changes --- components/character/CharacterUnit/index.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/components/character/CharacterUnit/index.tsx b/components/character/CharacterUnit/index.tsx index 45bcf17e..b643bf35 100644 --- a/components/character/CharacterUnit/index.tsx +++ b/components/character/CharacterUnit/index.tsx @@ -4,6 +4,7 @@ import { useSnapshot } from 'valtio' import { Trans, useTranslation } from 'next-i18next' import { AxiosResponse } from 'axios' import classNames from 'classnames' +import cloneDeep from 'lodash.clonedeep' import Alert from '~components/common/Alert' import Button from '~components/common/Button' @@ -26,6 +27,7 @@ import SettingsIcon from '~public/icons/Settings.svg' // Types import type { + CharacterOverMastery, GridCharacterObject, PerpetuityObject, SearchableObject, @@ -143,7 +145,20 @@ const CharacterUnit = ({ // Save the server's response to state function processResult(response: AxiosResponse) { const gridCharacter: GridCharacter = response.data - appState.grid.characters[gridCharacter.position] = gridCharacter + let character = cloneDeep(gridCharacter) + + if (character.over_mastery) { + const overMastery: CharacterOverMastery = { + 1: gridCharacter.over_mastery[0], + 2: gridCharacter.over_mastery[1], + 3: gridCharacter.over_mastery[2], + 4: gridCharacter.over_mastery[3], + } + + character.over_mastery = overMastery + } + + appState.grid.characters[gridCharacter.position] = character } function processError(error: any) {