diff --git a/components/SearchModal/index.tsx b/components/SearchModal/index.tsx index 1e351c5e..53243315 100644 --- a/components/SearchModal/index.tsx +++ b/components/SearchModal/index.tsx @@ -50,8 +50,17 @@ class SearchModal extends React.Component { } } + 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) => { - 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) => { const data = response.data const totalResults = data.length diff --git a/utils/api.tsx b/utils/api.tsx index 858a2c46..9eb66af0 100644 --- a/utils/api.tsx +++ b/utils/api.tsx @@ -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) } - search(object: string, query: string) { + search(object: string, query: string, excludes: string) { 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) {