From 633fb45d499e1ff8e50e1a841d81c5de3adb61d1 Mon Sep 17 00:00:00 2001 From: Amr Adel Date: Sat, 14 Apr 2018 14:32:31 +0200 Subject: [PATCH 1/2] Update .gitignore file to untrack files that is auto generated by rubymine --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index edd6964c..bd24352d 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,7 @@ node_modules # Ignore Byebug command history file. .byebug_history +# Ignore Files that auto generated by rubymine +.idea/ + *~ \ No newline at end of file From 0d2d609a872e7d1bff13331beb36e769c74108c2 Mon Sep 17 00:00:00 2001 From: Amr Adel Date: Sat, 28 Apr 2018 16:02:55 +0200 Subject: [PATCH 2/2] checking if it is in bigscreen mode, perform 4 requests to render more books --- .../javascripts/components/Profile.es6.jsx | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/components/Profile.es6.jsx b/app/assets/javascripts/components/Profile.es6.jsx index c5999f3d..7e22c23e 100644 --- a/app/assets/javascripts/components/Profile.es6.jsx +++ b/app/assets/javascripts/components/Profile.es6.jsx @@ -7,8 +7,9 @@ class Profile extends React.Component { showingBooks: true, books: this.props.books, requestMoreBooksSent: false, - pageNumber: 2, + pageNumber: 1, dashHeight: 0, + maxNumberOfBigScreenRequests: 4 }; this.renderAllBooks = this.renderAllBooks.bind(this); this.renderAuthoredBooks = this.renderAuthoredBooks.bind(this); @@ -25,10 +26,29 @@ class Profile extends React.Component { this.loadMoreBooks = this.loadMoreBooks.bind(this); this.loadBooksRequest = this.loadBooksRequest.bind(this); this.renderBookLoader = this.renderBookLoader.bind(this); + this.checkBigScreen = this.checkBigScreen.bind(this); } componentDidMount(){ window.addEventListener('scroll', this.loadMoreBooksOnScroll); + this.checkBigScreen(); + } + + checkBigScreen(){ + if(this.isBigScreen() && this.state.maxNumberOfBigScreenRequests > 0){ + this.setState({ + maxNumberOfBigScreenRequests: this.state.maxNumberOfBigScreenRequests - 1 + }) + this.loadBooksRequest(); + }else{ + this.setState({ + maxNumberOfBigScreenRequests: 0 + }) + } + } + + isBigScreen(){ + return document.documentElement.clientHeight == document.documentElement.scrollHeight; } loadMoreBooksOnScroll(){ @@ -60,7 +80,7 @@ class Profile extends React.Component { URL = cut_path_with_slashes[0] + "//" + cut_path_with_slashes[2]; $.ajax({ url: URL + "/books/show_more", - data: {page: this.state.pageNumber}, + data: {page: this.state.pageNumber + 1}, method: "GET", success: function(data, textStatus, jqXHR) { if(data.length > 0){ @@ -80,6 +100,13 @@ class Profile extends React.Component { }.bind(this), error: function(jqXHR, textStatus, errorThrown) { this.requestMoreBooksSent = false; + }.bind(this), + complete: function(textStatus, jqXHR){ + if(this.isBigScreen()){ + if(this.state.maxNumberOfBigScreenRequests > 0){ + setTimeout(this.checkBigScreen, 1000) + } + } }.bind(this) }); }