Add search state persistence and pagination for bans history
Enhanced the bans component to retain search state using the History API. Updated the history component to support paginated and filtered data loading based on user input and search terms.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {Component, Input, OnChanges, OnInit} from '@angular/core';
|
||||
import {BASE_PATH, HistoryService, PunishmentHistoryInner} from '../../../api';
|
||||
import {map, shareReplay} from 'rxjs';
|
||||
import {map, Observable, shareReplay} from 'rxjs';
|
||||
import {NgForOf, NgIf} from '@angular/common';
|
||||
import {CookieService} from 'ngx-cookie-service';
|
||||
|
||||
@@ -21,6 +21,10 @@ export class HistoryComponent implements OnInit, OnChanges {
|
||||
|
||||
@Input() userType: 'player' | 'staff' = "player";
|
||||
@Input() punishmentType: 'all' | 'ban' | 'mute' | 'kick' | 'warn' = "all";
|
||||
@Input() page: number = 0;
|
||||
@Input() searchTerm: string = '';
|
||||
|
||||
private uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
||||
|
||||
public history: PunishmentHistoryInner[] = []
|
||||
|
||||
@@ -36,16 +40,19 @@ export class HistoryComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
private reloadHistory(): void {
|
||||
console.log('userType', this.userType);
|
||||
console.log('punishmentType', this.punishmentType);
|
||||
this.historyApi.getHistoryForAll(this.userType, this.punishmentType, 0).pipe(
|
||||
let historyObservable: Observable<PunishmentHistoryInner[]>;
|
||||
if (this.searchTerm.length === 0) {
|
||||
historyObservable = this.historyApi.getHistoryForAll(this.userType, this.punishmentType, this.page);
|
||||
} else {
|
||||
if (this.uuidRegex.test(this.searchTerm)) {
|
||||
historyObservable = this.historyApi.getHistoryForUuid(this.userType, this.punishmentType, this.searchTerm, this.page);
|
||||
} else {
|
||||
historyObservable = this.historyApi.getHistoryForUsers(this.userType, this.punishmentType, this.searchTerm, this.page)
|
||||
}
|
||||
}
|
||||
historyObservable.pipe(
|
||||
map(history => {
|
||||
this.history = history;
|
||||
console.log("HI");
|
||||
console.log(history);
|
||||
history.forEach(history => {
|
||||
console.log(history);
|
||||
});
|
||||
}),
|
||||
shareReplay(1)
|
||||
).subscribe();
|
||||
@@ -67,7 +74,7 @@ export class HistoryComponent implements OnInit, OnChanges {
|
||||
if (entry.expiryTime === 0) {
|
||||
return "Permanent " + entry.type.charAt(0).toUpperCase() + entry.type.slice(1);
|
||||
}
|
||||
const date = new Date(entry.punishmentTime + entry.expiryTime);
|
||||
const date = new Date(entry.expiryTime);
|
||||
return date.toLocaleString(navigator.language, {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
|
||||
Reference in New Issue
Block a user