mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
delay to reactive search
This commit is contained in:
parent
6fb5c922c1
commit
69365d3d93
@ -32,7 +32,7 @@ interface SearchState {
|
|||||||
|
|
||||||
class Search extends PureComponent<SearchProps, SearchState> {
|
class Search extends PureComponent<SearchProps, SearchState> {
|
||||||
public static contextType = User
|
public static contextType = User
|
||||||
|
public timeout: any = false
|
||||||
public state = {
|
public state = {
|
||||||
results: [],
|
results: [],
|
||||||
totalResults: 0,
|
totalResults: 0,
|
||||||
@ -134,10 +134,24 @@ class Search extends PureComponent<SearchProps, SearchState> {
|
|||||||
this.setState({
|
this.setState({
|
||||||
[event.currentTarget.name]: event.currentTarget.value
|
[event.currentTarget.name]: event.currentTarget.value
|
||||||
} as any, () => {
|
} as any, () => {
|
||||||
this.searchAssets()
|
this.pendingSearch()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private pendingSearch = () => {
|
||||||
|
this.setState({isLoading:true},()=>{
|
||||||
|
if(this.timeout){
|
||||||
|
clearTimeout(this.timeout)
|
||||||
|
}
|
||||||
|
this.timeout = setTimeout(this.executeSearch,250);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private executeSearch=()=>{
|
||||||
|
this.timeout = false
|
||||||
|
this.searchAssets()
|
||||||
|
}
|
||||||
|
|
||||||
public setCategory = (category: string) => {
|
public setCategory = (category: string) => {
|
||||||
this.setState({ category }, () => this.searchAssets())
|
this.setState({ category }, () => this.searchAssets())
|
||||||
}
|
}
|
||||||
@ -193,11 +207,13 @@ class Search extends PureComponent<SearchProps, SearchState> {
|
|||||||
|
|
||||||
{this.renderResults()}
|
{this.renderResults()}
|
||||||
|
|
||||||
<Pagination
|
{!this.state.isLoading && (
|
||||||
totalPages={totalPages}
|
<Pagination
|
||||||
currentPage={currentPage}
|
totalPages={totalPages}
|
||||||
handlePageClick={this.handlePageClick}
|
currentPage={currentPage}
|
||||||
/>
|
handlePageClick={this.handlePageClick}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Content>
|
</Content>
|
||||||
|
Loading…
Reference in New Issue
Block a user