Added sorting to user suspicious scores
This commit is contained in:
parent
ee619161d2
commit
aacbf9f392
@ -80,9 +80,28 @@
|
|||||||
</th>
|
</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr class="filters">
|
||||||
|
<th>
|
||||||
|
<span title="Sort by beatmap star rating (asc)" class="pointer sorter" [class.active]="this.filterManager.filters.sorting == 'beatmap_star_rating-asc'" (click)="sortScores('beatmap_star_rating', 'asc')">▲</span>
|
||||||
|
<span title="Sort by beatmap star rating (desc)" class="pointer sorter" [class.active]="this.filterManager.filters.sorting == 'beatmap_star_rating-desc'" (click)="sortScores('beatmap_star_rating', 'desc')">▼</span>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<span title="Sort by date (asc)" class="pointer sorter" [class.active]="this.filterManager.filters.sorting == 'date-asc'" (click)="sortScores('date', 'asc')">▲</span>
|
||||||
|
<span title="Sort by date (desc)" class="pointer sorter" [class.active]="this.filterManager.filters.sorting == 'date-desc'" (click)="sortScores('date', 'desc')">▼</span>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<span title="Sort by cvUR (asc)" class="pointer sorter" [class.active]="this.filterManager.filters.sorting == 'ur-asc'" (click)="sortScores('ur', 'asc')">▲</span>
|
||||||
|
<span title="Sort by cvUR (desc)" class="pointer sorter" [class.active]="this.filterManager.filters.sorting == 'ur-desc'" (click)="sortScores('ur', 'desc')">▼</span>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<span title="Sort by PP (asc)" class="pointer sorter" [class.active]="this.filterManager.filters.sorting == 'pp-asc'" (click)="sortScores('pp', 'asc')">▲️</span>
|
||||||
|
<span title="Sort by PP (desc)" class="pointer sorter" [class.active]="this.filterManager.filters.sorting == 'pp-desc'" (click)="sortScores('pp', 'desc')">▼</span>
|
||||||
|
</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr *ngFor="let score of this.userInfo.suspicious_scores">
|
<tr *ngFor="let score of this.filteredScores">
|
||||||
<td>
|
<td>
|
||||||
<div class="image-container">
|
<div class="image-container">
|
||||||
<a href="https://osu.ppy.sh/beatmaps/{{ score.beatmap_id }}?mode=osu" target="_blank">
|
<a href="https://osu.ppy.sh/beatmaps/{{ score.beatmap_id }}?mode=osu" target="_blank">
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import {RxStompService} from "../../corelib/stomp/stomp.service";
|
|||||||
import {Message} from "@stomp/stompjs/esm6";
|
import {Message} from "@stomp/stompjs/esm6";
|
||||||
import {CuteLoadingComponent} from "../../corelib/components/cute-loading/cute-loading.component";
|
import {CuteLoadingComponent} from "../../corelib/components/cute-loading/cute-loading.component";
|
||||||
import {differenceInDays, differenceInHours} from "date-fns/fp";
|
import {differenceInDays, differenceInHours} from "date-fns/fp";
|
||||||
|
import {FilterManagerService} from "../filter-manager.service";
|
||||||
|
|
||||||
interface UserInfo {
|
interface UserInfo {
|
||||||
user_details: UserDetails;
|
user_details: UserDetails;
|
||||||
@ -26,6 +27,10 @@ interface UserQueueWebsocketPacket {
|
|||||||
data?: UserQueueDetails;
|
data?: UserQueueDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface UserScoresFilter {
|
||||||
|
sorting?: string;
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-view-user',
|
selector: 'app-view-user',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
@ -50,6 +55,9 @@ export class ViewUserComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
|
|
||||||
liveUserSub: Subscription | undefined;
|
liveUserSub: Subscription | undefined;
|
||||||
|
|
||||||
|
filterManager = new FilterManagerService<UserScoresFilter>("userScoresFilter");
|
||||||
|
filteredScores: SuspiciousScore[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private httpClient: HttpClient,
|
private httpClient: HttpClient,
|
||||||
private activatedRoute: ActivatedRoute,
|
private activatedRoute: ActivatedRoute,
|
||||||
@ -70,6 +78,8 @@ export class ViewUserComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
this.userInfo = null;
|
this.userInfo = null;
|
||||||
|
|
||||||
|
this.filterManager.setFiltersFromLocal();
|
||||||
|
|
||||||
this.activatedRoute.params.subscribe(params => {
|
this.activatedRoute.params.subscribe(params => {
|
||||||
this.userId = params['userId'];
|
this.userId = params['userId'];
|
||||||
if (this.userId) {
|
if (this.userId) {
|
||||||
@ -94,6 +104,14 @@ export class ViewUserComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
(response: UserInfo) => {
|
(response: UserInfo) => {
|
||||||
this.notFound = false;
|
this.notFound = false;
|
||||||
this.userInfo = response;
|
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) {
|
if(!isScoreUpdate) {
|
||||||
this.title.setTitle(`${this.userInfo.user_details.username}`);
|
this.title.setTitle(`${this.userInfo.user_details.username}`);
|
||||||
this.subscribeToUser();
|
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 formatDuration = formatDuration;
|
||||||
protected readonly countryCodeToFlag = countryCodeToFlag;
|
protected readonly countryCodeToFlag = countryCodeToFlag;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user