Skip to content

Commit 4695211

Browse files
committed
Add ability to disable pagination
Thumbnails are hidden if there are 1,000 or more search results.
1 parent a9bf0d4 commit 4695211

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

search/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<table class="search-table"></table>
2828
<input type="checkbox" id="filter" checked> <label for="filter">Filter NSFW entries</label>
2929
<input type="checkbox" id="any"> <label for="any">Match any</label>
30+
<input type="checkbox" id="paginate" checked> <label for="paginate">Paginate</label>
3031
<button class="search-button">Search</button>
3132
</div>
3233
<div class="results">

search/search.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ let fpdb = {
66
list: [],
77
pages: 0,
88
currentPage: 1,
9+
resultsPerPage: 100,
10+
displayedResults: 0,
11+
thumbnailLimit: 1000,
912
lastScrollPos: 0,
1013
metaMap: {
1114
title: "Title",
@@ -155,7 +158,17 @@ function performSearch() {
155158

156159
fetch(`${fpdb.api}/search?${params.join('&')}&fields=id,title,developer,publisher,platform,library,tags,originalDescription,dateAdded,dateModified`).then(r => r.json()).then(json => {
157160
fpdb.list = json;
158-
fpdb.pages = Math.ceil(fpdb.list.length / 100);
161+
162+
if (document.querySelector('#paginate').checked) {
163+
fpdb.pages = Math.ceil(fpdb.list.length / fpdb.resultsPerPage);
164+
fpdb.displayedResults = fpdb.resultsPerPage;
165+
document.querySelector('.results-per-page').hidden = false;
166+
}
167+
else {
168+
fpdb.pages = 1;
169+
fpdb.displayedResults = fpdb.list.length;
170+
document.querySelector('.results-per-page').hidden = true;
171+
}
159172

160173
document.querySelector('.results-total').textContent = fpdb.list.length.toLocaleString();
161174
document.querySelectorAll('.results-max-pages').forEach(elem => { elem.textContent = fpdb.pages.toLocaleString(); });
@@ -202,15 +215,18 @@ function loadPage(page) {
202215
document.querySelectorAll('.results-current-page').forEach(elem => { elem.textContent = fpdb.currentPage.toLocaleString(); });
203216
document.querySelector('.results').scrollTop = 0;
204217

205-
for (let i = (page - 1) * 100; i < Math.min(fpdb.list.length, page * 100); i++) {
218+
for (let i = (page - 1) * fpdb.displayedResults; i < Math.min(fpdb.list.length, page * fpdb.displayedResults); i++) {
206219
let entry = document.createElement('div')
207220
entry.className = 'entry';
208221

209-
let logo = document.createElement('div');
210-
logo.className = 'entry-logo';
211-
logo.setAttribute('view', i);
212-
logo.style.backgroundImage = `url("${fpdb.images}/Logos/${fpdb.list[i].id.substring(0, 2)}/${fpdb.list[i].id.substring(2, 4)}/${fpdb.list[i].id}.png?type=jpg")`;
213-
logo.addEventListener('click', loadEntry);
222+
if (fpdb.displayedResults < fpdb.thumbnailLimit) {
223+
let logo = document.createElement('div');
224+
logo.className = 'entry-logo';
225+
logo.setAttribute('view', i);
226+
logo.style.backgroundImage = `url("${fpdb.images}/Logos/${fpdb.list[i].id.substring(0, 2)}/${fpdb.list[i].id.substring(2, 4)}/${fpdb.list[i].id}.png?type=jpg")`;
227+
logo.addEventListener('click', loadEntry);
228+
entry.append(logo);
229+
}
214230

215231
let text = document.createElement('div');
216232
text.className = 'entry-text';
@@ -254,7 +270,7 @@ function loadPage(page) {
254270
header.append(title, developer);
255271
subHeader.append(type, tags);
256272
text.append(header, subHeader, description);
257-
entry.append(logo, text);
273+
entry.append(text);
258274
htmlList.append(entry);
259275
}
260276
}

0 commit comments

Comments
 (0)