mirror of
https://github.com/BlossomiShymae/clean-cuts.git
synced 2025-12-06 18:20:47 +01:00
Init commit
This commit is contained in:
50
utils/paginated-array.ts
Normal file
50
utils/paginated-array.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
export class PaginatedArray<T> extends Array<T> {
|
||||
pageSize: number;
|
||||
items: Array<T>;
|
||||
pageIndex: number;
|
||||
totalPages: number;
|
||||
|
||||
constructor(items: Array<T>, pageIndex: number, pageSize: number) {
|
||||
super();
|
||||
|
||||
this.pageSize = pageSize;
|
||||
this.items = items;
|
||||
|
||||
this.pageIndex = pageIndex;
|
||||
this.totalPages = Math.ceil(items.length / pageSize);
|
||||
|
||||
this.push(...items.slice((pageIndex - 1) * pageSize).slice(0, pageSize));
|
||||
}
|
||||
|
||||
public get hasFurtherPreviousPage() {
|
||||
return this.pageIndex > 2;
|
||||
}
|
||||
|
||||
public get hasPreviousPage() {
|
||||
return this.pageIndex > 1;
|
||||
}
|
||||
|
||||
public get hasNextPage() {
|
||||
return this.pageIndex < this.totalPages;
|
||||
}
|
||||
|
||||
public get hasFurtherNextPage() {
|
||||
return this.pageIndex < this.totalPages - 1;
|
||||
}
|
||||
|
||||
public get furtherPreviousPage() {
|
||||
return this.pageIndex - 2;
|
||||
}
|
||||
|
||||
public get previousPage() {
|
||||
return this.pageIndex - 1;
|
||||
}
|
||||
|
||||
public get nextPage() {
|
||||
return this.pageIndex + 1;
|
||||
}
|
||||
|
||||
public get furtherNextPage() {
|
||||
return this.pageIndex + 2;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user