1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

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

View File

@ -10,7 +10,7 @@ import styles from './Search.module.scss'
interface SearchProps { interface SearchProps {
location: Location location: Location
history: History history: any
} }
interface SearchState { interface SearchState {
@ -34,8 +34,16 @@ export default class Search extends PureComponent<SearchProps, SearchState> {
private readonly searchTerm = queryString.parse(this.props.location.search) private readonly searchTerm = queryString.parse(this.props.location.search)
.text .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() this.searchAssets()
} }
@ -65,6 +73,11 @@ export default class Search extends PureComponent<SearchProps, SearchState> {
} }
private setPage = async (page: number) => { 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.setState({ currentPage: page, isLoading: true })
await this.searchAssets() await this.searchAssets()
} }