From 2b27fb6955599b1f96c924b99205a2744172b712 Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Sat, 12 Apr 2025 01:45:59 +0200 Subject: [PATCH] Add dynamic pagination and state management for history Introduced dynamic pagination based on punishment types and counts, retrieved via a new API call. Refactored state management with a centralized `pushState` method and updated button logic in the template to reflect the changes. This improves navigation consistency and user experience. --- frontend/src/app/bans/bans.component.html | 8 +-- frontend/src/app/bans/bans.component.ts | 75 +++++++++++++++++++---- 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/frontend/src/app/bans/bans.component.html b/frontend/src/app/bans/bans.component.html index 7e39d72..240784c 100644 --- a/frontend/src/app/bans/bans.component.html +++ b/frontend/src/app/bans/bans.component.html @@ -11,10 +11,10 @@
- - - - + + + +
{ this.names = names; }); - const state = { - searchTerm: this.searchTerm, - page: this.page, - userType: this.userType, - punishmentType: this.punishmentType - }; - const title = 'Altitude Bans'; - const url = window.location.href; - window.history.pushState(state, title, url) + this.historyApi.getTotalPunishments().subscribe(totalPunishments => { + this.historyCount = totalPunishments; + }) + + this.pushState(); window.addEventListener('popstate', (event) => { if (event.state && event.state.searchTerm !== undefined) { @@ -73,6 +75,40 @@ export class BansComponent implements OnInit { } public search() { + this.pushState() + this.finalSearchTerm = this.searchTerm; + } + + public changeHistoryType(type: 'player' | 'staff') { + this.pushState(); + this.userType = type; + } + + public changeHistoryPunishment(type: 'all' | 'ban' | 'mute' | 'kick' | 'warn') { + this.pushState(); + this.punishmentType = type; + } + + public nextPage() { + if (this.page === this.getMaxPage() - 1) { + return; + } + this.setPage(this.page++) + } + + public previousPage() { + if (this.page === 0) { + return; + } + this.setPage(this.page--) + } + + public setPage(page: number) { + this.pushState(); + this.page = page + } + + private pushState() { const state = { searchTerm: this.searchTerm, page: this.page, @@ -82,6 +118,23 @@ export class BansComponent implements OnInit { const title = 'Altitude Bans'; const url = window.location.href; window.history.pushState(state, title, url); - this.finalSearchTerm = this.searchTerm; + } + + public getMaxPage() { + const all = this.historyCount.bans + this.historyCount.mutes + this.historyCount.warnings; + switch (this.punishmentType) { + case 'all': + return Math.ceil(all / 10); + case 'ban': + return Math.ceil(this.historyCount.bans / 10); + case 'mute': + return Math.ceil(this.historyCount.mutes / 10); + case 'kick': + return Math.ceil(this.historyCount.kicks / 10); + case 'warn': + return Math.ceil(this.historyCount.warnings / 10); + default: + return 0; + } } }