1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-10 17:12:48 +00:00

client - forum page - pagination / threads per page

This commit is contained in:
2018-01-18 22:41:43 -06:00
parent 857df18cbf
commit 0d3a92c28d
11 changed files with 228 additions and 27 deletions

View File

@@ -1 +1,2 @@
export * from './oauth/oauth';
export * from './pagination/pagination';

View File

@@ -0,0 +1,30 @@
export const pagination = (page: number, numPages: number): (number | string)[] => {
const current = page;
const last = numPages;
const delta = 2;
const left = current - delta;
const right = current + delta + 1;
const range = [];
const rangeWithDots = [];
let l;
for (let i = 1; i <= last; i++) {
if (i === 1 || i === last || (i >= left && i < right)) {
range.push(i);
}
}
for (const i of range) {
if (l) {
if (i - l === 2) {
rangeWithDots.push(l + 1);
} else if (i - l !== 1) {
rangeWithDots.push('...');
}
}
rangeWithDots.push(i);
l = i;
}
return rangeWithDots;
};