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> {
|
||||
public static contextType = User
|
||||
|
||||
public timeout: any = false
|
||||
public state = {
|
||||
results: [],
|
||||
totalResults: 0,
|
||||
@ -134,10 +134,24 @@ class Search extends PureComponent<SearchProps, SearchState> {
|
||||
this.setState({
|
||||
[event.currentTarget.name]: event.currentTarget.value
|
||||
} 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) => {
|
||||
this.setState({ category }, () => this.searchAssets())
|
||||
}
|
||||
@ -193,11 +207,13 @@ class Search extends PureComponent<SearchProps, SearchState> {
|
||||
|
||||
{this.renderResults()}
|
||||
|
||||
<Pagination
|
||||
totalPages={totalPages}
|
||||
currentPage={currentPage}
|
||||
handlePageClick={this.handlePageClick}
|
||||
/>
|
||||
{!this.state.isLoading && (
|
||||
<Pagination
|
||||
totalPages={totalPages}
|
||||
currentPage={currentPage}
|
||||
handlePageClick={this.handlePageClick}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Content>
|
||||
|
Loading…
Reference in New Issue
Block a user