mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
feat(frontend): style recent listens page
This commit is contained in:
parent
75d3e2edbd
commit
1d5cefb447
3 changed files with 165 additions and 54 deletions
29
frontend/src/util/getPaginationItems.ts
Normal file
29
frontend/src/util/getPaginationItems.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
export const getPaginationItems = (
|
||||
currentPage: number,
|
||||
totalPages: number,
|
||||
delta: number = 1
|
||||
): (number | null)[] => {
|
||||
const left = currentPage - delta;
|
||||
const right = currentPage + delta;
|
||||
|
||||
const range = Array.from(Array(totalPages))
|
||||
.map((e, i) => i + 1)
|
||||
.filter((i) => i === 1 || i === totalPages || (i >= left && i <= right))
|
||||
.reduce((pages: (number | null)[], page, i) => {
|
||||
if (pages.length !== 0) {
|
||||
const prevPage = pages[pages.length - 1];
|
||||
if (prevPage !== null) {
|
||||
const diff = page - prevPage;
|
||||
if (diff > 1) {
|
||||
pages.push(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pages.push(page);
|
||||
|
||||
return pages;
|
||||
}, []);
|
||||
|
||||
return range;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue