From d0535d603131073c71ccaf3c9f7bf31629f3819b Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 7 Jul 2023 07:00:44 -0700 Subject: [PATCH] Fix bugs relating to [party] --- components/character/CharacterGrid/index.tsx | 28 ++--- components/job/JobSection/index.tsx | 4 +- components/party/Party/index.tsx | 109 +++++++++--------- .../party/PartySegmentedControl/index.tsx | 12 +- components/reps/SummonRep/index.tsx | 4 +- components/reps/WeaponRep/index.tsx | 2 +- components/summon/SummonGrid/index.tsx | 91 ++++++++------- components/weapon/WeaponGrid/index.tsx | 68 ++++++----- 8 files changed, 165 insertions(+), 153 deletions(-) diff --git a/components/character/CharacterGrid/index.tsx b/components/character/CharacterGrid/index.tsx index 453740f7..4be3b5c3 100644 --- a/components/character/CharacterGrid/index.tsx +++ b/components/character/CharacterGrid/index.tsx @@ -46,7 +46,7 @@ const CharacterGrid = (props: Props) => { const [errorAlertOpen, setErrorAlertOpen] = useState(false) // Set up state for view management - const { party, grid } = useSnapshot(appState) + const { party } = useSnapshot(appState) const [modalOpen, setModalOpen] = useState(false) // Set up state for conflict management @@ -88,7 +88,7 @@ const CharacterGrid = (props: Props) => { o ? (initialPreviousUncapValues[o.position] = o.uncapLevel) : 0 }) setPreviousUncapValues(initialPreviousUncapValues) - }, [appState.grid.characters]) + }, [appState.party.grid.characters]) // Methods: Adding an object from search function receiveCharacterFromSearch( @@ -146,7 +146,7 @@ const CharacterGrid = (props: Props) => { } function storeGridCharacter(gridCharacter: GridCharacter) { - appState.grid.characters[gridCharacter.position] = gridCharacter + appState.party.grid.characters[gridCharacter.position] = gridCharacter } async function resolveConflict() { @@ -164,7 +164,7 @@ const CharacterGrid = (props: Props) => { // Remove conflicting characters from state conflicts.forEach( - (c) => (appState.grid.characters[c.position] = undefined) + (c) => (appState.party.grid.characters[c.position] = undefined) ) // Reset conflict @@ -186,7 +186,7 @@ const CharacterGrid = (props: Props) => { async function removeCharacter(id: string) { try { const response = await api.endpoints.grid_characters.destroy({ id: id }) - appState.grid.characters[response.data.position] = undefined + appState.party.grid.characters[response.data.position] = undefined } catch (error) { console.error(error) } @@ -378,10 +378,10 @@ const CharacterGrid = (props: Props) => { position: number, uncapLevel: number | undefined ) => { - const character = appState.grid.characters[position] + const character = appState.party.grid.characters[position] if (character && uncapLevel) { character.uncapLevel = uncapLevel - appState.grid.characters[position] = character + appState.party.grid.characters[position] = character } } @@ -389,8 +389,8 @@ const CharacterGrid = (props: Props) => { // Save the current value in case of an unexpected result let newPreviousValues = { ...previousUncapValues } - if (grid.characters[position]) { - newPreviousValues[position] = grid.characters[position]?.uncapLevel + if (party.grid.characters[position]) { + newPreviousValues[position] = party.grid.characters[position]?.uncapLevel setPreviousUncapValues(newPreviousValues) } } @@ -474,10 +474,10 @@ const CharacterGrid = (props: Props) => { position: number, stage: number | undefined ) => { - const character = appState.grid.characters[position] + const character = appState.party.grid.characters[position] if (character && stage !== undefined) { character.transcendenceStep = stage - appState.grid.characters[position] = character + appState.party.grid.characters[position] = character } } @@ -485,8 +485,8 @@ const CharacterGrid = (props: Props) => { // Save the current value in case of an unexpected result let newPreviousValues = { ...previousUncapValues } - if (grid.characters[position]) { - newPreviousValues[position] = grid.characters[position]?.uncapLevel + if (party.grid.characters[position]) { + newPreviousValues[position] = party.grid.characters[position]?.uncapLevel setPreviousTranscendenceStages(newPreviousValues) } } @@ -540,7 +540,7 @@ const CharacterGrid = (props: Props) => { return (
  • void diff --git a/components/party/Party/index.tsx b/components/party/Party/index.tsx index 29e3b822..5154f5ac 100644 --- a/components/party/Party/index.tsx +++ b/components/party/Party/index.tsx @@ -58,7 +58,7 @@ const Party = (props: Props) => { // Reset state on first load useEffect(() => { const resetState = clonedeep(initialAppState) - appState.grid = resetState.grid + appState.party.grid = resetState.party.grid if (props.party) { storeParty(props.party) setUpdatedParty(props.party) @@ -268,10 +268,12 @@ const Party = (props: Props) => { appState.party.name = team.name appState.party.description = team.description ? team.description : '' appState.party.raid = team.raid - appState.party.protagonist.job = team.job - appState.party.protagonist.skills = team.job_skills - appState.party.protagonist.accessory = team.accessory - + appState.party.protagonist.job = team.protagonist.job + appState.party.protagonist.skills = team.protagonist.skills + appState.party.protagonist.accessory = team.protagonist.accessory + appState.party.protagonist.masterLevel = team.protagonist.master_level + appState.party.protagonist.ultimateMastery = + team.protagonist.ultimate_mastery appState.party.details.chargeAttack = team.charge_attack appState.party.details.fullAuto = team.full_auto appState.party.details.autoGuard = team.auto_guard @@ -296,17 +298,14 @@ const Party = (props: Props) => { appState.party.timestamps.createdAt = team.created_at appState.party.timestamps.updatedAt = team.updated_at + appState.party.grid = team.grid + // Store the edit key in local storage if (team.edit_key) { storeEditKey(team.id, team.edit_key) setEditKey(team.id, team.user) } - // Populate state - storeCharacters(team.characters) - storeWeapons(team.weapons) - storeSummons(team.summons) - // Create a string to send the user back to the tab they're currently on let tab = '' if (props.selectedTab === GridType.Character) { @@ -324,56 +323,56 @@ const Party = (props: Props) => { } const storeCharacters = (list: Array) => { - list.forEach((object: GridCharacter) => { - let character = clonedeep(object) - - if (character.mastery.overMastery) { - const overMastery: CharacterOverMastery = { - 1: object.mastery.overMastery[0], - 2: object.mastery.overMastery[1], - 3: object.mastery.overMastery[2], - 4: object.mastery.overMastery[3], - } - - character.mastery.overMastery = overMastery - } - - if (character.position != null) { - appState.grid.characters[object.position] = character - } - }) + // list.forEach((object: GridCharacter) => { + // let character = clonedeep(object) + // if (character.mastery.overMastery) { + // const overMastery: CharacterOverMastery = { + // 1: object.mastery.overMastery[0], + // 2: object.mastery.overMastery[1], + // 3: object.mastery.overMastery[2], + // 4: object.mastery.overMastery[3], + // } + // character.mastery.overMastery = overMastery + // } + // if (character.position != null) { + // appState.grid.characters[object.position] = character + // } + // }) } - const storeWeapons = (list: Array) => { - list.forEach((gridObject: GridWeapon) => { - if (gridObject.mainhand) { - appState.grid.weapons.mainWeapon = gridObject - appState.party.element = gridObject.object.element - } else if (!gridObject.mainhand && gridObject.position !== null) { - let weapon = clonedeep(gridObject) - if ( - weapon.object.element === ElementMap.null && - weapon.element === ElementMap.null - ) - weapon.element = gridObject.object.element - - appState.grid.weapons.allWeapons[gridObject.position] = weapon - } - }) + const storeWeapons = ( + allWeapons: Array, + mainWeapon?: GridWeapon + ) => { + // appState.grid.weapons.mainWeapon = mainWeapon + // list.forEach((gridObject: GridWeapon) => { + // if (gridObject.mainhand) { + // appState.grid.weapons.mainWeapon = gridObject + // appState.party.element = gridObject.object.element + // } else if (!gridObject.mainhand && gridObject.position !== null) { + // let weapon = clonedeep(gridObject) + // if ( + // weapon.object.element === ElementMap.null && + // weapon.element === ElementMap.null + // ) + // weapon.element = gridObject.object.element + // appState.grid.weapons.allWeapons[gridObject.position] = weapon + // } + // }) } const storeSummons = (list: Array) => { - list.forEach((gridObject: GridSummon) => { - if (gridObject.main) appState.grid.summons.mainSummon = gridObject - else if (gridObject.friend) - appState.grid.summons.friendSummon = gridObject - else if ( - !gridObject.main && - !gridObject.friend && - gridObject.position != null - ) - appState.grid.summons.allSummons[gridObject.position] = gridObject - }) + // list.forEach((gridObject: GridSummon) => { + // if (gridObject.main) appState.grid.summons.mainSummon = gridObject + // else if (gridObject.friend) + // appState.grid.summons.friendSummon = gridObject + // else if ( + // !gridObject.main && + // !gridObject.friend && + // gridObject.position != null + // ) + // appState.grid.summons.allSummons[gridObject.position] = gridObject + // }) } // Methods: Navigating with segmented control diff --git a/components/party/PartySegmentedControl/index.tsx b/components/party/PartySegmentedControl/index.tsx index 15cca916..b2d3126f 100644 --- a/components/party/PartySegmentedControl/index.tsx +++ b/components/party/PartySegmentedControl/index.tsx @@ -31,12 +31,12 @@ const PartySegmentedControl = (props: Props) => { // Set up translations const { t } = useTranslation('common') - const { party, grid } = useSnapshot(appState) + const { party } = useSnapshot(appState) const getElement = () => { let element: GranblueElement - if (party.element === ElementMap.null && grid.weapons.mainWeapon) - element = grid.weapons.mainWeapon.element + if (party.element === ElementMap.null && party.grid.weapons.mainWeapon) + element = party.grid.weapons.mainWeapon?.element else if (party.element) element = party.element else element = ElementMap.null @@ -71,7 +71,7 @@ const PartySegmentedControl = (props: Props) => { gender={ accountState.account.user ? accountState.account.user.gender : 0 } - grid={grid.characters} + grid={party.grid.characters} /> ) @@ -87,7 +87,7 @@ const PartySegmentedControl = (props: Props) => { selected={props.selectedTab === GridType.Weapon} onClick={props.onClick} > - + ) } @@ -102,7 +102,7 @@ const PartySegmentedControl = (props: Props) => { selected={props.selectedTab === GridType.Summon} onClick={props.onClick} > - + ) } diff --git a/components/reps/SummonRep/index.tsx b/components/reps/SummonRep/index.tsx index b728b9fb..e0e291ed 100644 --- a/components/reps/SummonRep/index.tsx +++ b/components/reps/SummonRep/index.tsx @@ -5,8 +5,8 @@ import styles from './index.module.scss' interface Props { grid: { - mainSummon: GridSummon | undefined - friendSummon: GridSummon | undefined + mainSummon?: GridSummon | undefined + friendSummon?: GridSummon | undefined allSummons: GridArray } } diff --git a/components/reps/WeaponRep/index.tsx b/components/reps/WeaponRep/index.tsx index de1f685c..15213a99 100644 --- a/components/reps/WeaponRep/index.tsx +++ b/components/reps/WeaponRep/index.tsx @@ -5,7 +5,7 @@ import styles from './index.module.scss' interface Props { grid: { - mainWeapon: GridWeapon | undefined + mainWeapon?: GridWeapon | undefined allWeapons: GridArray } } diff --git a/components/summon/SummonGrid/index.tsx b/components/summon/SummonGrid/index.tsx index 716a4491..7579a501 100644 --- a/components/summon/SummonGrid/index.tsx +++ b/components/summon/SummonGrid/index.tsx @@ -49,7 +49,7 @@ const SummonGrid = (props: Props) => { const [errorAlertOpen, setErrorAlertOpen] = useState(false) // Set up state for view management - const { party, grid } = useSnapshot(appState) + const { party } = useSnapshot(appState) // Create a temporary state to store previous weapon uncap values and transcendence stages const [previousUncapValues, setPreviousUncapValues] = useState<{ @@ -64,13 +64,13 @@ const SummonGrid = (props: Props) => { useEffect(() => { let initialPreviousUncapValues: { [key: number]: number } = {} - if (appState.grid.summons.mainSummon) + if (appState.party.grid.summons.mainSummon) initialPreviousUncapValues[-1] = - appState.grid.summons.mainSummon.uncapLevel + appState.party.grid.summons.mainSummon.uncapLevel - if (appState.grid.summons.friendSummon) + if (appState.party.grid.summons.friendSummon) initialPreviousUncapValues[6] = - appState.grid.summons.friendSummon.uncapLevel + appState.party.grid.summons.friendSummon.uncapLevel Object.values(appState.party.grid.summons.allSummons).map((o) => o ? (initialPreviousUncapValues[o.position] = o.uncapLevel) : 0 @@ -78,9 +78,9 @@ const SummonGrid = (props: Props) => { setPreviousUncapValues(initialPreviousUncapValues) }, [ - appState.grid.summons.mainSummon, - appState.grid.summons.friendSummon, - appState.grid.summons.allSummons, + appState.party.grid.summons.mainSummon, + appState.party.grid.summons.friendSummon, + appState.party.grid.summons.allSummons, ]) // Methods: Adding an object from search @@ -119,11 +119,11 @@ const SummonGrid = (props: Props) => { const position = data.meta['replaced'] if (position == -1) { - appState.grid.summons.mainSummon = undefined + appState.party.grid.summons.mainSummon = undefined } else if (position == 6) { - appState.grid.summons.friendSummon = undefined + appState.party.grid.summons.friendSummon = undefined } else { - appState.grid.summons.allSummons[position] = undefined + appState.party.grid.summons.allSummons[position] = undefined } } } @@ -147,10 +147,12 @@ const SummonGrid = (props: Props) => { } function storeGridSummon(gridSummon: GridSummon) { - if (gridSummon.position == -1) appState.grid.summons.mainSummon = gridSummon + if (gridSummon.position == -1) + appState.party.grid.summons.mainSummon = gridSummon else if (gridSummon.position == 6) - appState.grid.summons.friendSummon = gridSummon - else appState.grid.summons.allSummons[gridSummon.position] = gridSummon + appState.party.grid.summons.friendSummon = gridSummon + else + appState.party.grid.summons.allSummons[gridSummon.position] = gridSummon } // Methods: Updating uncap level @@ -216,15 +218,15 @@ const SummonGrid = (props: Props) => { ) const updateUncapLevel = (position: number, uncapLevel: number) => { - if (appState.grid.summons.mainSummon && position == -1) - appState.grid.summons.mainSummon.uncapLevel = uncapLevel - else if (appState.grid.summons.friendSummon && position == 6) - appState.grid.summons.friendSummon.uncapLevel = uncapLevel + if (appState.party.grid.summons.mainSummon && position == -1) + appState.party.grid.summons.mainSummon.uncapLevel = uncapLevel + else if (appState.party.grid.summons.friendSummon && position == 6) + appState.party.grid.summons.friendSummon.uncapLevel = uncapLevel else { - const summon = appState.grid.summons.allSummons[position] + const summon = appState.party.grid.summons.allSummons[position] if (summon) { summon.uncapLevel = uncapLevel - appState.grid.summons.allSummons[position] = summon + appState.party.grid.summons.allSummons[position] = summon } } } @@ -233,13 +235,14 @@ const SummonGrid = (props: Props) => { // Save the current value in case of an unexpected result let newPreviousValues = { ...previousUncapValues } - if (appState.grid.summons.mainSummon && position == -1) - newPreviousValues[position] = appState.grid.summons.mainSummon.uncapLevel - else if (appState.grid.summons.friendSummon && position == 6) + if (appState.party.grid.summons.mainSummon && position == -1) newPreviousValues[position] = - appState.grid.summons.friendSummon.uncapLevel + appState.party.grid.summons.mainSummon.uncapLevel + else if (appState.party.grid.summons.friendSummon && position == 6) + newPreviousValues[position] = + appState.party.grid.summons.friendSummon.uncapLevel else { - const summon = appState.grid.summons.allSummons[position] + const summon = appState.party.grid.summons.allSummons[position] newPreviousValues[position] = summon ? summon.uncapLevel : 0 } @@ -320,15 +323,15 @@ const SummonGrid = (props: Props) => { ) const updateTranscendenceStage = (position: number, stage: number) => { - if (appState.grid.summons.mainSummon && position == -1) - appState.grid.summons.mainSummon.transcendenceStep = stage - else if (appState.grid.summons.friendSummon && position == 6) - appState.grid.summons.friendSummon.transcendenceStep = stage + if (appState.party.grid.summons.mainSummon && position == -1) + appState.party.grid.summons.mainSummon.transcendenceStep = stage + else if (appState.party.grid.summons.friendSummon && position == 6) + appState.party.grid.summons.friendSummon.transcendenceStep = stage else { - const summon = appState.grid.summons.allSummons[position] + const summon = appState.party.grid.summons.allSummons[position] if (summon) { summon.transcendenceStep = stage - appState.grid.summons.allSummons[position] = summon + appState.party.grid.summons.allSummons[position] = summon } } } @@ -337,13 +340,14 @@ const SummonGrid = (props: Props) => { // Save the current value in case of an unexpected result let newPreviousValues = { ...previousUncapValues } - if (appState.grid.summons.mainSummon && position == -1) - newPreviousValues[position] = appState.grid.summons.mainSummon.uncapLevel - else if (appState.grid.summons.friendSummon && position == 6) + if (appState.party.grid.summons.mainSummon && position == -1) newPreviousValues[position] = - appState.grid.summons.friendSummon.uncapLevel + appState.party.grid.summons.mainSummon.uncapLevel + else if (appState.party.grid.summons.friendSummon && position == 6) + newPreviousValues[position] = + appState.party.grid.summons.friendSummon.uncapLevel else { - const summon = appState.grid.summons.allSummons[position] + const summon = appState.party.grid.summons.allSummons[position] newPreviousValues[position] = summon ? summon.uncapLevel : 0 } @@ -356,11 +360,12 @@ const SummonGrid = (props: Props) => { const data = response.data if (data.position === -1) { - appState.grid.summons.mainSummon = undefined + appState.party.grid.summons.mainSummon = undefined } else if (data.position === 6) { - appState.grid.summons.friendSummon = undefined + appState.party.grid.summons.friendSummon = undefined } else { - appState.grid.summons.allSummons[response.data.position] = undefined + appState.party.grid.summons.allSummons[response.data.position] = + undefined } } catch (error) { console.error(error) @@ -384,7 +389,7 @@ const SummonGrid = (props: Props) => {
    {t('summons.main')}
    { {t('summons.friend')}
    { return (
  • { const subAuraSummonElement = ( { useEffect(() => { let initialPreviousUncapValues: { [key: number]: number } = {} - if (appState.grid.weapons.mainWeapon) + if (appState.party.grid.weapons.mainWeapon) initialPreviousUncapValues[-1] = - appState.grid.weapons.mainWeapon.uncapLevel + appState.party.grid.weapons.mainWeapon.uncapLevel Object.values(appState.party.grid.weapons.allWeapons).map((o) => o ? (initialPreviousUncapValues[o.position] = o.uncapLevel) : 0 ) setPreviousUncapValues(initialPreviousUncapValues) - }, [appState.grid.weapons.mainWeapon, appState.grid.weapons.allWeapons]) + }, [ + appState.party.grid.weapons.mainWeapon, + appState.party.grid.weapons.allWeapons, + ]) // Methods: Adding an object from search function receiveWeaponFromSearch(object: SearchableObject, position: number) { @@ -147,10 +150,10 @@ const WeaponGrid = (props: Props) => { const position = data.meta['replaced'] if (position == -1) { - appState.grid.weapons.mainWeapon = undefined + appState.party.grid.weapons.mainWeapon = undefined appState.party.element = ElementMap.null } else { - appState.grid.weapons.allWeapons[position] = undefined + appState.party.grid.weapons.allWeapons[position] = undefined } } } @@ -164,16 +167,17 @@ const WeaponGrid = (props: Props) => { let post = false if ( position === -1 && - (!appState.grid.weapons.mainWeapon || - (appState.grid.weapons.mainWeapon && - appState.grid.weapons.mainWeapon.object.id !== weapon.id)) + (!appState.party.grid.weapons.mainWeapon || + (appState.party.grid.weapons.mainWeapon && + appState.party.grid.weapons.mainWeapon.object.id !== weapon.id)) ) { post = true } else if ( position !== -1 && - (!appState.grid.weapons.allWeapons[position] || - (appState.grid.weapons.allWeapons[position] && - appState.grid.weapons.allWeapons[position]?.object.id !== weapon.id)) + (!appState.party.grid.weapons.allWeapons[position] || + (appState.party.grid.weapons.allWeapons[position] && + appState.party.grid.weapons.allWeapons[position]?.object.id !== + weapon.id)) ) { post = true } @@ -193,11 +197,11 @@ const WeaponGrid = (props: Props) => { function storeGridWeapon(gridWeapon: GridWeapon) { if (gridWeapon.position === -1) { - appState.grid.weapons.mainWeapon = gridWeapon + appState.party.grid.weapons.mainWeapon = gridWeapon appState.party.element = gridWeapon.object.element } else { // Store the grid unit at the correct position - appState.grid.weapons.allWeapons[gridWeapon.position] = gridWeapon + appState.party.grid.weapons.allWeapons[gridWeapon.position] = gridWeapon } } @@ -213,11 +217,13 @@ const WeaponGrid = (props: Props) => { .then((response) => { // Remove conflicting characters from state conflicts.forEach((c) => { - if (appState.grid.weapons.mainWeapon?.object.id === c.object.id) { - appState.grid.weapons.mainWeapon = undefined + if ( + appState.party.grid.weapons.mainWeapon?.object.id === c.object.id + ) { + appState.party.grid.weapons.mainWeapon = undefined appState.party.element = ElementMap.null } else { - appState.grid.weapons.allWeapons[c.position] = undefined + appState.party.grid.weapons.allWeapons[c.position] = undefined } }) @@ -245,9 +251,10 @@ const WeaponGrid = (props: Props) => { const data = response.data if (data.position === -1) { - appState.grid.weapons.mainWeapon = undefined + appState.party.grid.weapons.mainWeapon = undefined } else { - appState.grid.weapons.allWeapons[response.data.position] = undefined + appState.party.grid.weapons.allWeapons[response.data.position] = + undefined } } catch (error) { console.error(error) @@ -311,13 +318,13 @@ const WeaponGrid = (props: Props) => { const updateUncapLevel = (position: number, uncapLevel: number) => { // console.log(`Updating uncap level at position ${position} to ${uncapLevel}`) - if (appState.grid.weapons.mainWeapon && position == -1) - appState.grid.weapons.mainWeapon.uncapLevel = uncapLevel + if (appState.party.grid.weapons.mainWeapon && position == -1) + appState.party.grid.weapons.mainWeapon.uncapLevel = uncapLevel else { - const weapon = appState.grid.weapons.allWeapons[position] + const weapon = appState.party.grid.weapons.allWeapons[position] if (weapon) { weapon.uncapLevel = uncapLevel - appState.grid.weapons.allWeapons[position] = weapon + appState.party.grid.weapons.allWeapons[position] = weapon } } } @@ -326,10 +333,11 @@ const WeaponGrid = (props: Props) => { // Save the current value in case of an unexpected result let newPreviousValues = { ...previousUncapValues } - if (appState.grid.weapons.mainWeapon && position == -1) { - newPreviousValues[position] = appState.grid.weapons.mainWeapon.uncapLevel + if (appState.party.grid.weapons.mainWeapon && position == -1) { + newPreviousValues[position] = + appState.party.grid.weapons.mainWeapon.uncapLevel } else { - const weapon = appState.grid.weapons.allWeapons[position] + const weapon = appState.party.grid.weapons.allWeapons[position] if (weapon) { newPreviousValues[position] = weapon.uncapLevel } else { @@ -349,7 +357,7 @@ const WeaponGrid = (props: Props) => { // Render: JSX components const mainhandElement = ( { const weaponGridElement = Array.from(Array(numWeapons)).map((x, i) => { const itemClasses = classNames({ - Empty: appState.grid.weapons.allWeapons[i] === undefined, + Empty: appState.party.grid.weapons.allWeapons[i] === undefined, }) return (
  • { }) const extraElement = () => { - if (appState.party.raid && appState.party.raid.group.extra) { + if (appState.party.raid && appState.party.raid.group?.extra) { return ( {appState.party.raid && appState.party.raid.group.extra && (