Skip to content
Snippets Groups Projects
Commit 04e2f59f authored by Jörn Friedrich Dreyer's avatar Jörn Friedrich Dreyer
Browse files

use cancelable timeout, on scroll only fetch next page if last query had any results

parent 357fbd88
Branches
No related tags found
No related merge requests found
......@@ -84,7 +84,8 @@
var lastInApps = [];
var lastPage = 0;
var lastSize = 30;
var lastResults = {};
var lastResults = [];
var timeoutID = null;
this.getLastQuery = function() {
return lastQuery;
......@@ -94,7 +95,7 @@
* Do a search query and display the results
* @param {string} query the search query
*/
this.search = _.debounce(function(query, inApps, page, size) {
this.search = function(query, inApps, page, size) {
if (query) {
OC.addStyle('search','results');
if (typeof page !== 'number') {
......@@ -115,6 +116,8 @@
if ($searchResults && query === lastQuery && page === lastPage && size === lastSize) {
return;
}
window.clearTimeout(timeoutID);
timeoutID = window.setTimeout(function() {
lastQuery = query;
lastInApps = inApps;
lastPage = page;
......@@ -133,8 +136,9 @@
addResults(results);
}
});
}
}, 500);
}
};
//TODO should be a core method, see https://github.com/owncloud/core/issues/12557
function getCurrentApp() {
......@@ -243,7 +247,7 @@
* This appends/renders the next page of entries when reaching the bottom.
*/
function onScroll(e) {
if ($searchResults && lastQuery !== false) {
if ($searchResults && lastQuery !== false && lastResults.length > 0) {
var resultsBottom = $searchResults.offset().top + $searchResults.height();
var containerBottom = $searchResults.offsetParent().offset().top + $searchResults.offsetParent().height();
if ( resultsBottom < containerBottom * 1.2 ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment