From aacbf9f392049e6d066b5545df34e167de07a768 Mon Sep 17 00:00:00 2001 From: "nise.moe" Date: Thu, 22 Feb 2024 15:27:01 +0100 Subject: [PATCH] Added sorting to user suspicious scores --- .../app/view-user/view-user.component.html | 21 +++++++++- .../src/app/view-user/view-user.component.ts | 39 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/nise-frontend/src/app/view-user/view-user.component.html b/nise-frontend/src/app/view-user/view-user.component.html index d1833e4..5210cc8 100644 --- a/nise-frontend/src/app/view-user/view-user.component.html +++ b/nise-frontend/src/app/view-user/view-user.component.html @@ -80,9 +80,28 @@ + + + + + + + + + + + + + + + ▲️ + + + + - +
diff --git a/nise-frontend/src/app/view-user/view-user.component.ts b/nise-frontend/src/app/view-user/view-user.component.ts index ca5cd27..eebf169 100644 --- a/nise-frontend/src/app/view-user/view-user.component.ts +++ b/nise-frontend/src/app/view-user/view-user.component.ts @@ -12,6 +12,7 @@ import {RxStompService} from "../../corelib/stomp/stomp.service"; import {Message} from "@stomp/stompjs/esm6"; import {CuteLoadingComponent} from "../../corelib/components/cute-loading/cute-loading.component"; import {differenceInDays, differenceInHours} from "date-fns/fp"; +import {FilterManagerService} from "../filter-manager.service"; interface UserInfo { user_details: UserDetails; @@ -26,6 +27,10 @@ interface UserQueueWebsocketPacket { data?: UserQueueDetails; } +interface UserScoresFilter { + sorting?: string; +} + @Component({ selector: 'app-view-user', standalone: true, @@ -50,6 +55,9 @@ export class ViewUserComponent implements OnInit, OnChanges, OnDestroy { liveUserSub: Subscription | undefined; + filterManager = new FilterManagerService("userScoresFilter"); + filteredScores: SuspiciousScore[] = []; + constructor( private httpClient: HttpClient, private activatedRoute: ActivatedRoute, @@ -70,6 +78,8 @@ export class ViewUserComponent implements OnInit, OnChanges, OnDestroy { this.isLoading = true; this.userInfo = null; + this.filterManager.setFiltersFromLocal(); + this.activatedRoute.params.subscribe(params => { this.userId = params['userId']; if (this.userId) { @@ -94,6 +104,14 @@ export class ViewUserComponent implements OnInit, OnChanges, OnDestroy { (response: UserInfo) => { this.notFound = false; this.userInfo = response; + // Process the scores filter + this.filteredScores = response.suspicious_scores; + if(this.filterManager.filters.sorting) { + let field = this.filterManager.filters.sorting.split("-")[0]; + let order = this.filterManager.filters.sorting.split("-")[1]; + //@ts-ignore + this.sortScores(field, order); + } if(!isScoreUpdate) { this.title.setTitle(`${this.userInfo.user_details.username}`); this.subscribeToUser(); @@ -162,6 +180,27 @@ export class ViewUserComponent implements OnInit, OnChanges, OnDestroy { }); } + sortScores(field: 'pp' | 'ur' | 'beatmap_star_rating' | 'date', order: 'asc' | 'desc'): void { + if(!this.userInfo) { + return; + } + + this.filterManager.filters.sorting = `${field}-${order}` + this.filterManager.persistToLocalStorage(); + + this.filteredScores = this.userInfo.suspicious_scores.sort((a: SuspiciousScore, b: SuspiciousScore): number => { + let compareValue = 0; + + if (field === 'pp' || field === 'ur' || field === 'beatmap_star_rating') { + compareValue = a[field] - b[field]; + } else if (field === 'date') { + compareValue = a[field] < b[field] ? -1 : a[field] > b[field] ? 1 : 0; + } + + return order === 'asc' ? compareValue : -compareValue; + }); + } + protected readonly formatDuration = formatDuration; protected readonly countryCodeToFlag = countryCodeToFlag;