Remove unused methods and props from WeaponGrid tree
This commit is contained in:
parent
9b505f5e20
commit
bc93565dc5
3 changed files with 3 additions and 33 deletions
|
|
@ -9,7 +9,6 @@ interface Props {
|
||||||
editable: boolean
|
editable: boolean
|
||||||
found?: boolean
|
found?: boolean
|
||||||
offset: number
|
offset: number
|
||||||
onClick: (position: number) => void
|
|
||||||
updateObject: (object: Character | Weapon | Summon, position: number) => void
|
updateObject: (object: Character | Weapon | Summon, position: number) => void
|
||||||
updateUncap: (id: string, position: number, uncap: number) => void
|
updateUncap: (id: string, position: number, uncap: number) => void
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +29,6 @@ const ExtraWeapons = (props: Props) => {
|
||||||
position={props.offset + i}
|
position={props.offset + i}
|
||||||
unitType={1}
|
unitType={1}
|
||||||
gridWeapon={props.grid[props.offset + i]}
|
gridWeapon={props.grid[props.offset + i]}
|
||||||
onClick={() => { props.onClick(props.offset + i)}}
|
|
||||||
updateObject={props.updateObject}
|
updateObject={props.updateObject}
|
||||||
updateUncap={props.updateUncap}
|
updateUncap={props.updateUncap}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@ import React, { useCallback, useContext, useEffect, useMemo, useState } from 're
|
||||||
import { useCookies } from 'react-cookie'
|
import { useCookies } from 'react-cookie'
|
||||||
import { useSnapshot } from 'valtio'
|
import { useSnapshot } from 'valtio'
|
||||||
|
|
||||||
import { useModal as useModal } from '~utils/useModal'
|
|
||||||
import state from '~utils/state'
|
|
||||||
|
|
||||||
import { AxiosResponse } from 'axios'
|
import { AxiosResponse } from 'axios'
|
||||||
import debounce from 'lodash.debounce'
|
import debounce from 'lodash.debounce'
|
||||||
|
|
||||||
|
|
@ -13,6 +10,8 @@ import WeaponUnit from '~components/WeaponUnit'
|
||||||
import ExtraWeapons from '~components/ExtraWeapons'
|
import ExtraWeapons from '~components/ExtraWeapons'
|
||||||
|
|
||||||
import api from '~utils/api'
|
import api from '~utils/api'
|
||||||
|
import state from '~utils/state'
|
||||||
|
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
|
|
||||||
// Props
|
// Props
|
||||||
|
|
@ -41,16 +40,9 @@ const WeaponGrid = (props: Props) => {
|
||||||
const [found, setFound] = useState(false)
|
const [found, setFound] = useState(false)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
|
||||||
// Set up states for Search
|
|
||||||
const { open, openModal, closeModal } = useModal()
|
|
||||||
const [itemPositionForSearch, setItemPositionForSearch] = useState(0)
|
|
||||||
|
|
||||||
// Create a temporary state to store previous weapon uncap values
|
// Create a temporary state to store previous weapon uncap values
|
||||||
const [previousUncapValues, setPreviousUncapValues] = useState<{[key: number]: number}>({})
|
const [previousUncapValues, setPreviousUncapValues] = useState<{[key: number]: number}>({})
|
||||||
|
|
||||||
// Create a state dictionary to store pure objects for Search
|
|
||||||
const [searchGrid, setSearchGrid] = useState<GridArray<Weapon>>({})
|
|
||||||
|
|
||||||
// Fetch data from the server
|
// Fetch data from the server
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const shortcode = (props.slug) ? props.slug : slug
|
const shortcode = (props.slug) ? props.slug : slug
|
||||||
|
|
@ -68,16 +60,6 @@ const WeaponGrid = (props: Props) => {
|
||||||
setPreviousUncapValues(initialPreviousUncapValues)
|
setPreviousUncapValues(initialPreviousUncapValues)
|
||||||
}, [state.grid.weapons.mainWeapon, state.grid.weapons.allWeapons])
|
}, [state.grid.weapons.mainWeapon, state.grid.weapons.allWeapons])
|
||||||
|
|
||||||
// Update search grid whenever weapons or the mainhand are updated
|
|
||||||
useEffect(() => {
|
|
||||||
let newSearchGrid = Object.values(grid.weapons.allWeapons).map((o) => o.weapon)
|
|
||||||
|
|
||||||
if (state.grid.weapons.mainWeapon)
|
|
||||||
newSearchGrid.unshift(state.grid.weapons.mainWeapon.weapon)
|
|
||||||
|
|
||||||
setSearchGrid(newSearchGrid)
|
|
||||||
}, [state.grid.weapons.mainWeapon, state.grid.weapons.allWeapons])
|
|
||||||
|
|
||||||
// Methods: Fetching an object from the server
|
// Methods: Fetching an object from the server
|
||||||
async function fetchGrid(shortcode: string) {
|
async function fetchGrid(shortcode: string) {
|
||||||
return api.endpoints.parties.getOneWithObject({ id: shortcode, object: 'weapons' })
|
return api.endpoints.parties.getOneWithObject({ id: shortcode, object: 'weapons' })
|
||||||
|
|
@ -132,12 +114,6 @@ const WeaponGrid = (props: Props) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methods: Adding an object from search
|
|
||||||
function openSearchModal(position: number) {
|
|
||||||
setItemPositionForSearch(position)
|
|
||||||
openModal()
|
|
||||||
}
|
|
||||||
|
|
||||||
function receiveWeaponFromSearch(object: Character | Weapon | Summon, position: number) {
|
function receiveWeaponFromSearch(object: Character | Weapon | Summon, position: number) {
|
||||||
const weapon = object as Weapon
|
const weapon = object as Weapon
|
||||||
if (position == 1)
|
if (position == 1)
|
||||||
|
|
@ -251,7 +227,6 @@ const WeaponGrid = (props: Props) => {
|
||||||
key="grid_mainhand"
|
key="grid_mainhand"
|
||||||
position={-1}
|
position={-1}
|
||||||
unitType={0}
|
unitType={0}
|
||||||
onClick={() => { openSearchModal(-1) }}
|
|
||||||
updateObject={receiveWeaponFromSearch}
|
updateObject={receiveWeaponFromSearch}
|
||||||
updateUncap={initiateUncapUpdate}
|
updateUncap={initiateUncapUpdate}
|
||||||
/>
|
/>
|
||||||
|
|
@ -266,7 +241,6 @@ const WeaponGrid = (props: Props) => {
|
||||||
editable={party.editable}
|
editable={party.editable}
|
||||||
position={i}
|
position={i}
|
||||||
unitType={1}
|
unitType={1}
|
||||||
onClick={() => { openSearchModal(i) }}
|
|
||||||
updateObject={receiveWeaponFromSearch}
|
updateObject={receiveWeaponFromSearch}
|
||||||
updateUncap={initiateUncapUpdate}
|
updateUncap={initiateUncapUpdate}
|
||||||
/>
|
/>
|
||||||
|
|
@ -280,7 +254,6 @@ const WeaponGrid = (props: Props) => {
|
||||||
grid={state.grid.weapons.allWeapons}
|
grid={state.grid.weapons.allWeapons}
|
||||||
editable={party.editable}
|
editable={party.editable}
|
||||||
offset={numWeapons}
|
offset={numWeapons}
|
||||||
onClick={openSearchModal}
|
|
||||||
updateObject={receiveWeaponFromSearch}
|
updateObject={receiveWeaponFromSearch}
|
||||||
updateUncap={initiateUncapUpdate}
|
updateUncap={initiateUncapUpdate}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ interface Props {
|
||||||
unitType: 0 | 1
|
unitType: 0 | 1
|
||||||
position: number
|
position: number
|
||||||
editable: boolean
|
editable: boolean
|
||||||
onClick: () => void
|
|
||||||
updateObject: (object: Character | Weapon | Summon, position: number) => void
|
updateObject: (object: Character | Weapon | Summon, position: number) => void
|
||||||
updateUncap: (id: string, position: number, uncap: number) => void
|
updateUncap: (id: string, position: number, uncap: number) => void
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +61,7 @@ const WeaponUnit = (props: Props) => {
|
||||||
fromPosition={props.position}
|
fromPosition={props.position}
|
||||||
object="weapons"
|
object="weapons"
|
||||||
send={props.updateObject}>
|
send={props.updateObject}>
|
||||||
<div className="WeaponImage" onClick={ (props.editable) ? props.onClick : () => {} }>
|
<div className="WeaponImage">
|
||||||
<img alt={weapon?.name.en} className="grid_image" src={imageUrl} />
|
<img alt={weapon?.name.en} className="grid_image" src={imageUrl} />
|
||||||
{ (props.editable) ? <span className='icon'><PlusIcon /></span> : '' }
|
{ (props.editable) ? <span className='icon'><PlusIcon /></span> : '' }
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue