From 00d000b8f8264599c4e57508ea6275fa29c2c408 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Thu, 21 Sep 2017 15:03:33 +0200 Subject: [PATCH] Started working in the infinate scroll so it loads the next page when visible on page. This commit was under_development bugs as of now. --- client/app/components/SearchRequest.jsx | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/client/app/components/SearchRequest.jsx b/client/app/components/SearchRequest.jsx index c0b78ea..41edd5c 100644 --- a/client/app/components/SearchRequest.jsx +++ b/client/app/components/SearchRequest.jsx @@ -129,10 +129,24 @@ class SearchRequest extends React.Component { // mapped as a movieObject. response.json() .then(responseData => { - this.setState({ - responseMovieList: responseData.results.map(searchResultItem => this.createMovieObjects(searchResultItem)), - lastApiCallURI: uri // Save the value of the last sucessfull api call - }) + if (this.state.page === 1) { + this.setState({ + responseMovieList: responseData.results.map(searchResultItem => this.createMovieObjects(searchResultItem)), + lastApiCallURI: uri // Save the value of the last sucessfull api call + }) + } else { + let responseMovieObjects = responseData.results.map(searchResultItem => this.createMovieObjects(searchResultItem)); + console.log(responseMovieObjects) + console.log(this.state.responseMovieList) + let growingReponseMovieObjectList = this.state.responseMovieList.concat(responseMovieObjects); + this.setState({ + responseMovieList: growingReponseMovieObjectList, + lastApiCallURI: uri // Save the value of the last sucessfull api call + }) + } + }) + .catch((error) => { + console.log(error) }) }) .catch(() => { @@ -216,8 +230,6 @@ class SearchRequest extends React.Component { - - // Updates the internal state of the query search field. updateQueryState(event){ this.setState({