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:
@@ -1 +1,2 @@
|
||||
export * from './oauth/oauth';
|
||||
export * from './pagination/pagination';
|
||||
|
||||
30
client/app/util/pagination/pagination.ts
Normal file
30
client/app/util/pagination/pagination.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user