From de39e469b7756e412961348d7863ad1309c9ecf2 Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Fri, 5 Apr 2024 03:09:22 +0000 Subject: [PATCH] fix library pagination --- .../pages/library/library.component.html | 4 +-- .../pages/library/library.component.ts | 28 +++---------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/frontend/src/app/features/pages/library/library.component.html b/frontend/src/app/features/pages/library/library.component.html index 90755c1..f50ed09 100644 --- a/frontend/src/app/features/pages/library/library.component.html +++ b/frontend/src/app/features/pages/library/library.component.html @@ -38,7 +38,7 @@ -
+
  • Previous @@ -57,7 +57,7 @@ -
    +
    • Previous diff --git a/frontend/src/app/features/pages/library/library.component.ts b/frontend/src/app/features/pages/library/library.component.ts index 1b5a2d7..fa6806f 100644 --- a/frontend/src/app/features/pages/library/library.component.ts +++ b/frontend/src/app/features/pages/library/library.component.ts @@ -21,8 +21,6 @@ export class LibraryComponent { constructor(private libraryService: LibraryService) {} ngOnInit() { - this.entriesCount = this.entries.length; - this.maxPage = this.entriesCount / this.pageSize; this.pageSize = this.getDefaultPageSize(); this.fetchEntries(); } @@ -52,23 +50,12 @@ export class LibraryComponent { } else { temp = this.entries; } - console.log(temp); - - // ? title search - // let len = temp.length; - // for (let i = 0; i < len; i++) { - // if (!temp[i].title.toLocaleLowerCase().includes('od')) { - // temp.splice(i); - // len--; - // } - // } const startIndex = (this.currentPage - 1) * this.pageSize; const endIndex = startIndex + this.pageSize; - this.entriesCount = this.entriesToShow.length; - this.maxPage = this.entriesCount / this.pageSize; - this.entriesToShow = []; + this.entriesCount = temp.length; + this.maxPage = Math.ceil(this.entriesCount / this.pageSize); this.entriesToShow = temp.slice(startIndex, endIndex); } @@ -79,21 +66,13 @@ export class LibraryComponent { } get pageNumbers(): number[] { - this.entriesCount = this.entries.length; - this.maxPage = this.entriesCount / this.pageSize; - - // Ensure currentPage is within the bounds. - this.currentPage = Math.max(1, Math.min(this.currentPage, this.maxPage)); - let pagesToShow = 5; // Total pages to show at any time let startPage: number, endPage: number; if (this.maxPage <= pagesToShow) { - // Case when the total number of pages is less or equal to pagesToShow. startPage = 1; endPage = this.maxPage; } else { - // Calculate the start page. startPage = Math.max(this.currentPage - Math.floor(pagesToShow / 2), 1); endPage = startPage + pagesToShow - 1; @@ -114,12 +93,13 @@ export class LibraryComponent { setEntryType(entryType: number) { this.entryType = entryType; this.currentPage = 1; + this.filterEntries(); } setPageSize(event: any) { this.pageSize = event.target.value; - this.filterEntries() + this.filterEntries(); } getDefaultPageSize() {