Update SearchModal to use new keys
This commit is contained in:
parent
36f4766620
commit
f76d28b5f0
1 changed files with 16 additions and 18 deletions
|
|
@ -26,7 +26,7 @@ const SearchModal = (props: Props) => {
|
||||||
|
|
||||||
let searchInput = React.createRef<HTMLInputElement>()
|
let searchInput = React.createRef<HTMLInputElement>()
|
||||||
|
|
||||||
const [pool, setPool] = useState(Array<Character | Weapon | Summon>())
|
const [objects, setObjects] = useState<{[id: number]: GridCharacter | GridWeapon | GridSummon}>()
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const [query, setQuery] = useState('')
|
const [query, setQuery] = useState('')
|
||||||
const [results, setResults] = useState({})
|
const [results, setResults] = useState({})
|
||||||
|
|
@ -34,14 +34,8 @@ const SearchModal = (props: Props) => {
|
||||||
const [message, setMessage] = useState('')
|
const [message, setMessage] = useState('')
|
||||||
const [totalResults, setTotalResults] = useState(0)
|
const [totalResults, setTotalResults] = useState(0)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.object === 'characters') {
|
setObjects(grid[props.object])
|
||||||
setPool(Object.values(grid.characters).map(o => o.character))
|
|
||||||
} else if (props.object === 'weapons') {
|
|
||||||
setPool(Object.values(grid.weapons.allWeapons).map(o => o.weapon))
|
|
||||||
} else if (props.object === 'summons') {
|
|
||||||
setPool(Object.values(grid.summons.allSummons).map(o => o.summon))
|
|
||||||
}
|
|
||||||
}, [grid, props.object])
|
}, [grid, props.object])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -49,13 +43,6 @@ const SearchModal = (props: Props) => {
|
||||||
searchInput.current.focus()
|
searchInput.current.focus()
|
||||||
}, [searchInput])
|
}, [searchInput])
|
||||||
|
|
||||||
function filterExclusions(object: Character | Weapon | Summon) {
|
|
||||||
if (pool[props.fromPosition] &&
|
|
||||||
object.granblue_id === pool[props.fromPosition].granblue_id)
|
|
||||||
return null
|
|
||||||
else return object
|
|
||||||
}
|
|
||||||
|
|
||||||
function inputChanged(event: React.ChangeEvent<HTMLInputElement>) {
|
function inputChanged(event: React.ChangeEvent<HTMLInputElement>) {
|
||||||
const text = event.target.value
|
const text = event.target.value
|
||||||
if (text.length) {
|
if (text.length) {
|
||||||
|
|
@ -73,9 +60,13 @@ const SearchModal = (props: Props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchResults() {
|
function fetchResults() {
|
||||||
const excludes = Object.values(pool)
|
// Exclude objects in grid from search results
|
||||||
|
// unless the object is in the position that the user clicked
|
||||||
|
// so that users can replace object versions with
|
||||||
|
// compatible other objects.
|
||||||
|
const excludes = (objects) ? Object.values(objects)
|
||||||
.filter(filterExclusions)
|
.filter(filterExclusions)
|
||||||
.map((o) => { return o.name.en }).join(',')
|
.map((o) => { return (o.object) ? o.object.name.en : undefined }).join(',') : ''
|
||||||
|
|
||||||
api.search(props.object, query, excludes)
|
api.search(props.object, query, excludes)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
@ -89,6 +80,13 @@ const SearchModal = (props: Props) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filterExclusions(gridObject: GridCharacter | GridWeapon | GridSummon) {
|
||||||
|
if (objects && gridObject.object &&
|
||||||
|
gridObject.object.granblue_id === objects[props.fromPosition]?.object.granblue_id)
|
||||||
|
return null
|
||||||
|
else return gridObject
|
||||||
|
}
|
||||||
|
|
||||||
function sendData(result: Character | Weapon | Summon) {
|
function sendData(result: Character | Weapon | Summon) {
|
||||||
props.send(result, props.fromPosition)
|
props.send(result, props.fromPosition)
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue