Refine browse artist pagination normalization
This commit is contained in:
parent
9fb5abf519
commit
c5d4021e18
1 changed files with 8 additions and 12 deletions
20
script.js
20
script.js
|
@ -1122,18 +1122,17 @@
|
|||
pageSize: defaultPageSize,
|
||||
};
|
||||
|
||||
function normalizePaginationState() {
|
||||
function getNormalizedPagination() {
|
||||
let pageSize = Number(state.pageSize);
|
||||
if (!Number.isFinite(pageSize) || pageSize <= 0) pageSize = defaultPageSize;
|
||||
else pageSize = Math.max(1, Math.floor(pageSize));
|
||||
if (state.pageSize !== pageSize) state.pageSize = pageSize;
|
||||
|
||||
let page = Number(state.page);
|
||||
if (!Number.isFinite(page) || page <= 0) page = 1;
|
||||
else page = Math.max(1, Math.floor(page));
|
||||
if (state.pageSize !== pageSize) state.pageSize = pageSize;
|
||||
if (state.page !== page) state.page = page;
|
||||
|
||||
return { page, pageSize };
|
||||
const offset = Math.max(0, (page - 1) * pageSize);
|
||||
return { page, pageSize, offset };
|
||||
}
|
||||
|
||||
function escapeLike(str) {
|
||||
|
@ -1210,8 +1209,7 @@
|
|||
const useUnfilteredQuery = !typedFilter && !state.prefix;
|
||||
listState.showLoading('Loading…');
|
||||
|
||||
let { page, pageSize } = normalizePaginationState();
|
||||
let offset = (page - 1) * pageSize;
|
||||
let { page, pageSize, offset } = getNormalizedPagination();
|
||||
let total = 0;
|
||||
const rows = [];
|
||||
let usedFts = false;
|
||||
|
@ -1225,8 +1223,7 @@
|
|||
if (total > 0) {
|
||||
if (offset >= total) {
|
||||
state.page = Math.max(1, Math.ceil(total / pageSize));
|
||||
({ page, pageSize } = normalizePaginationState());
|
||||
offset = (page - 1) * pageSize;
|
||||
({ page, pageSize, offset } = getNormalizedPagination());
|
||||
}
|
||||
const ftsRowsStmt = db.prepare(applyFtsMatch(ftsRowsSql, ftsMatch));
|
||||
ftsRowsStmt.bind([pageSize, offset]);
|
||||
|
@ -1250,8 +1247,7 @@
|
|||
|
||||
if (offset >= total) {
|
||||
state.page = Math.max(1, Math.ceil(total / pageSize));
|
||||
({ page, pageSize } = normalizePaginationState());
|
||||
offset = (page - 1) * pageSize;
|
||||
({ page, pageSize, offset } = getNormalizedPagination());
|
||||
}
|
||||
|
||||
const rowsStmt = db.prepare(useUnfilteredQuery ? baseRowsSql : rowsSql);
|
||||
|
@ -1272,7 +1268,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
({ page, pageSize } = normalizePaginationState());
|
||||
({ page, pageSize } = getNormalizedPagination());
|
||||
listState.showRows({
|
||||
rows,
|
||||
total,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue