Merge pull request #90 from oceanprotocol/feature/search-pages

Make page numbers part of URL
This commit is contained in:
Matthias Kretschmann 2019-04-09 14:48:43 +02:00 committed by GitHub
commit 3d7560648c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -10,7 +10,7 @@ import styles from './Search.module.scss'
interface SearchProps {
location: Location
history: History
history: any
}
interface SearchState {
@ -34,8 +34,16 @@ export default class Search extends PureComponent<SearchProps, SearchState> {
private readonly searchTerm = queryString.parse(this.props.location.search)
.text
private readonly searchPage = queryString.parse(this.props.location.search)
.page
public async componentDidMount() {
// switch to respective page if query string is present
if (this.searchPage) {
const currentPage = Number(this.searchPage)
await this.setState({ currentPage })
}
public componentDidMount() {
this.searchAssets()
}
@ -65,6 +73,11 @@ export default class Search extends PureComponent<SearchProps, SearchState> {
}
private setPage = async (page: number) => {
this.props.history.push({
pathname: this.props.location.pathname,
search: `?text=${this.searchTerm}&page=${page}`
})
await this.setState({ currentPage: page, isLoading: true })
await this.searchAssets()
}