Add exclusion for Characters

Users should not be able to add multiple characters of the same name to multiple positions.
This commit is contained in:
Justin Edmund 2022-01-25 16:49:14 -08:00
parent 907d9f05e4
commit 9e0a1219d5
2 changed files with 15 additions and 3 deletions

View file

@ -50,8 +50,17 @@ class SearchModal extends React.Component<Props, State> {
} }
} }
filterExclusions = (o: Character | Weapon | Summon) => {
if (this.props.grid[this.props.fromPosition] &&
o.granblue_id == this.props.grid[this.props.fromPosition].granblue_id) {
return null
} else return o
}
fetchResults = (query: string) => { fetchResults = (query: string) => {
api.search(this.props.object, query) const excludes = Object.values(this.props.grid).filter(this.filterExclusions).map((o) => { return o.name.en }).join(',')
api.search(this.props.object, query, excludes)
.then((response) => { .then((response) => {
const data = response.data const data = response.data
const totalResults = data.length const totalResults = data.length

View file

@ -49,9 +49,12 @@ class Api {
return axios.post(`${ process.env.REACT_APP_SIERO_OAUTH_URL || 'http://127.0.0.1:3000/oauth' }/token`, object) return axios.post(`${ process.env.REACT_APP_SIERO_OAUTH_URL || 'http://127.0.0.1:3000/oauth' }/token`, object)
} }
search(object: string, query: string) { search(object: string, query: string, excludes: string) {
const resourceUrl = `${this.url}/${name}` const resourceUrl = `${this.url}/${name}`
return axios.get(`${resourceUrl}search/${object}?query=${query}`) const url = (excludes.length > 0) ?
`${resourceUrl}search/${object}?query=${query}&excludes=${excludes}` :
`${resourceUrl}search/${object}?query=${query}`
return axios.get(url)
} }
check(resource: string, value: string) { check(resource: string, value: string) {