mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
category search fixes
This commit is contained in:
parent
1b1ac5c9ef
commit
7fc99699c7
@ -39,24 +39,25 @@ export default class Search extends PureComponent<SearchProps, SearchState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async componentDidMount() {
|
public async componentDidMount() {
|
||||||
const searchTerm = await queryString.parse(this.props.location.search)
|
const { search } = this.props.location
|
||||||
.text
|
const { text, page, categories } = queryString.parse(search)
|
||||||
const searchPage = await queryString.parse(this.props.location.search)
|
|
||||||
.page
|
|
||||||
const searchCategories = await queryString.parse(
|
|
||||||
this.props.location.search
|
|
||||||
).categories
|
|
||||||
|
|
||||||
if (searchTerm || searchCategories) {
|
if (text) {
|
||||||
|
await this.setState({
|
||||||
|
searchTerm: `${text}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (categories) {
|
||||||
await this.setState({
|
await this.setState({
|
||||||
searchTerm: encodeURIComponent(`${searchTerm}`),
|
searchTerm: encodeURIComponent(`${searchTerm}`),
|
||||||
searchCategories: `${searchCategories}`
|
searchCategories: `${categories}`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch to respective page if query string is present
|
// switch to respective page if query string is present
|
||||||
if (searchPage) {
|
if (page) {
|
||||||
const currentPage = Number(searchPage)
|
const currentPage = Number(page)
|
||||||
await this.setState({ currentPage })
|
await this.setState({ currentPage })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,12 +68,18 @@ export default class Search extends PureComponent<SearchProps, SearchState> {
|
|||||||
const { ocean } = this.context
|
const { ocean } = this.context
|
||||||
const { offset, currentPage, searchTerm, searchCategories } = this.state
|
const { offset, currentPage, searchTerm, searchCategories } = this.state
|
||||||
|
|
||||||
|
const queryValues =
|
||||||
|
searchCategories !== '' && searchTerm !== ''
|
||||||
|
? { text: [searchTerm], categories: [searchCategories] }
|
||||||
|
: searchCategories !== '' && searchTerm === ''
|
||||||
|
? { categories: [searchCategories] }
|
||||||
|
: { text: [searchTerm] }
|
||||||
|
|
||||||
const searchQuery = {
|
const searchQuery = {
|
||||||
offset,
|
offset,
|
||||||
page: currentPage,
|
page: currentPage,
|
||||||
query: {
|
query: {
|
||||||
text: [decodeURIComponent(searchTerm)],
|
...queryValues,
|
||||||
categories: [decodeURIComponent(searchCategories)],
|
|
||||||
price: [-1, 1]
|
price: [-1, 1]
|
||||||
},
|
},
|
||||||
sort: {
|
sort: {
|
||||||
|
Loading…
Reference in New Issue
Block a user