diff --git a/client/app/components/SearchRequest.jsx b/client/app/components/SearchRequest.jsx index 2102cd6..38b1cfb 100644 --- a/client/app/components/SearchRequest.jsx +++ b/client/app/components/SearchRequest.jsx @@ -4,9 +4,10 @@ import MovieObject from './MovieObject.jsx'; // StyleComponents import searchStyle from './styles/searchRequestStyle.jsx'; -import movieStyle from './styles/movieObjectStyle.jsx' +import movieStyle from './styles/movieObjectStyle.jsx'; import URI from 'urijs'; +import InfiniteScroll from 'react-infinite-scroller'; // TODO add option for searching multi, movies or tv shows class SearchRequest extends React.Component { @@ -21,7 +22,9 @@ class SearchRequest extends React.Component { showFilter: false, discoverType: '', page: 1, - resultHeader: '' + resultHeader: '', + loadResults: false, + scrollHasMore: true } this.allowedListTypes = [ @@ -45,6 +48,8 @@ class SearchRequest extends React.Component { componentDidMount(){ var that = this; // this.setState({responseMovieList: null}) + this.resetPageNumber(); + this.state.loadResults = true; this.fetchTmdbList('upcoming'); } @@ -62,7 +67,7 @@ class SearchRequest extends React.Component { responseMovieList:

Nothing found for search query: { this.findQueryInURI(uri) }

}) } - console.log(error); + console.log('handleQueryError: ', error); } return response; } @@ -75,6 +80,14 @@ class SearchRequest extends React.Component { return queryValue; } + // Unpacks the page value of a uri + findPageValueInURI(uri) { + let uriSearchValues = uri.query(true); + let queryValue = uriSearchValues['page'] + + return queryValue; + } + resetPageNumber() { this.state.page = 1; } @@ -116,8 +129,18 @@ class SearchRequest extends React.Component { // If we get a error code for the request if (!response.ok) { if (response.status === 404) { - let errorMsg = 'Nothing found for the search query: ' + this.findQueryValueInURI(uri); - this.fillResponseMovieListWithError(errorMsg) + if (this.findPageValueInURI(new URI(response.url)) > 1) { + this.state.scrollHasMore = false; + console.log(this.state.scrollHasMore) + return null + let returnMessage = 'this is the return mesasge than will never be delivered' + let theSecondReturnMsg = 'this is the second return messag ethat will NEVE be delivered' + } + else { + + let errorMsg = 'Nothing found for the search query: ' + this.findQueryValueInURI(uri); + this.fillResponseMovieListWithError(errorMsg) + } } else { let errorMsg = 'Error fetching query from server ' + this.response.status; @@ -144,7 +167,7 @@ class SearchRequest extends React.Component { } }) .catch((error) => { - console.log(error) + console.log('CallSearchFillMovieList: ', error) }) }) .catch(() => { @@ -196,6 +219,8 @@ class SearchRequest extends React.Component { } searchSeasonedRequest() { + this.state.resultHeader = 'Search result for: ' + this.state.searchQuery; + // Build uri with the url for searching requests var uri = new URI(this.URLs.searchRequest); // Add input of search query and page count to the uri payload @@ -203,16 +228,21 @@ class SearchRequest extends React.Component { if (this.state.showFilter) uri = uri.addSearch('type', 'show'); + else + if (this.state.movieFilter) + uri = uri.addSearch('type', 'movie') // Send uri to call and fill the response list with movie/show objects this.callSearchFillMovieList(uri); } fetchTmdbList(tmdbListType) { + console.log(tmdbListType) // Check if it is a whitelisted list, this should be replaced with checking if the return call is 500 if (this.allowedListTypes.indexOf(tmdbListType) === -1) throw Error('Invalid discover type: ' + tmdbListType); + this.state.responseMovieList = [] // Captialize the first letter of and save the discoverQueryType to resultHeader state. this.state.resultHeader = tmdbListType.toLowerCase().replace(/\b[a-z]/g, function(letter) { return letter.toUpperCase(); @@ -310,53 +340,75 @@ class SearchRequest extends React.Component { this.state.page = pageNumber; } - - render(){ - return( -
- - - - - -
-
- Request new movies or tv shows -
- -
-
- - - this._handleQueryKeyPress(event)} - onChange={event => this.updateQueryState(event)} - value={this.state.searchQuery}/> - - {this.toggleFilter('movies')}} id="category_active">Movies - {this.toggleFilter('movies')}} + id="category_active">Movies + } + + showToggle() { + if (this.state.showFilter) + return {this.toggleFilter('shows')}} - id="category_inactive">TV Shows -
-
-
+ id="category_active">TV Shows + else + return {this.toggleFilter('shows')}} + id="category_active">TV Shows + } -
- -

{this.state.resultHeader}

- - {this.state.responseMovieList} -
- -
- - -
-
+ + render(){ + const loader =
Loading ...

; + + + return( + + +
+
+
+ Request new content +
+ +
+
+ + + this._handleQueryKeyPress(event)} + onChange={event => this.updateQueryState(event)} + value={this.state.searchQuery}/> + +
+
+
+ +
+ +

{this.state.resultHeader}

+ + {this.state.responseMovieList} +
+ +
+
+
+
) }