delay to reactive search

This commit is contained in:
Jernej Pregelj 2019-08-06 11:07:14 +02:00 committed by Matthias Kretschmann
parent 6fb5c922c1
commit 69365d3d93
Signed by: m
GPG Key ID: 606EEEF3C479A91F
1 changed files with 23 additions and 7 deletions

View File

@ -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>