From efbfd91c652f6fe9021cf4f12ac67365be7367b4 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 9 Apr 2019 13:12:58 +0200 Subject: [PATCH 1/2] switch to respective page if query string is present --- client/src/routes/Search.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/src/routes/Search.tsx b/client/src/routes/Search.tsx index 85c41ec..e742367 100644 --- a/client/src/routes/Search.tsx +++ b/client/src/routes/Search.tsx @@ -34,8 +34,16 @@ export default class Search extends PureComponent { 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() } From a77f01d595fea9b20b06f9683e2516701cee83a8 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 9 Apr 2019 13:51:00 +0200 Subject: [PATCH 2/2] add page to url --- client/src/routes/Search.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/src/routes/Search.tsx b/client/src/routes/Search.tsx index e742367..e8be6fb 100644 --- a/client/src/routes/Search.tsx +++ b/client/src/routes/Search.tsx @@ -10,7 +10,7 @@ import styles from './Search.module.scss' interface SearchProps { location: Location - history: History + history: any } interface SearchState { @@ -73,6 +73,11 @@ export default class Search extends PureComponent { } 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() }