view data fixes
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 6m4s
Contract Testing / contract-snapshot (pull_request) Has been skipped

This commit is contained in:
2026-01-23 11:59:49 +01:00
parent ae58839eb2
commit d97f50ed72
191 changed files with 2889 additions and 1019 deletions

View File

@@ -1,59 +1,49 @@
import type { DriverLeaderboardItemDTO } from '@/lib/types/generated/DriverLeaderboardItemDTO';
import type { LeaderboardDriverItem } from '@/lib/view-data/LeaderboardDriverItem';
export class DriverLeaderboardItemViewModel {
import { ViewModel } from "../contracts/view-models/ViewModel";
import { SkillLevelDisplay } from "../display-objects/SkillLevelDisplay";
import { SkillLevelIconDisplay } from "../display-objects/SkillLevelIconDisplay";
import { WinRateDisplay } from "../display-objects/WinRateDisplay";
import { RatingTrendDisplay } from "../display-objects/RatingTrendDisplay";
export class DriverLeaderboardItemViewModel extends ViewModel {
id: string;
name: string;
rating: number;
skillLevel: string;
category?: string;
nationality: string;
racesCompleted: number;
wins: number;
podiums: number;
isActive: boolean;
rank: number;
avatarUrl: string;
position: number;
private previousRating: number | undefined;
constructor(dto: DriverLeaderboardItemDTO, position: number, previousRating?: number) {
this.id = dto.id;
this.name = dto.name;
this.rating = dto.rating;
this.skillLevel = dto.skillLevel;
this.category = dto.category;
this.nationality = dto.nationality;
this.racesCompleted = dto.racesCompleted;
this.wins = dto.wins;
this.podiums = dto.podiums;
this.isActive = dto.isActive;
this.rank = dto.rank;
this.avatarUrl = dto.avatarUrl ?? '';
this.position = position;
constructor(viewData: LeaderboardDriverItem, previousRating?: number) {
super();
this.id = viewData.id;
this.name = viewData.name;
this.rating = viewData.rating;
this.skillLevel = viewData.skillLevel;
this.nationality = viewData.nationality;
this.racesCompleted = viewData.racesCompleted;
this.wins = viewData.wins;
this.podiums = viewData.podiums;
this.rank = viewData.rank;
this.avatarUrl = viewData.avatarUrl;
this.position = viewData.position;
this.previousRating = previousRating;
}
/** UI-specific: Skill level color */
get skillLevelColor(): string {
switch (this.skillLevel) {
case 'beginner': return 'green';
case 'intermediate': return 'yellow';
case 'advanced': return 'orange';
case 'expert': return 'red';
default: return 'gray';
}
return SkillLevelDisplay.getColor(this.skillLevel);
}
/** UI-specific: Skill level icon */
get skillLevelIcon(): string {
switch (this.skillLevel) {
case 'beginner': return '🥉';
case 'intermediate': return '🥈';
case 'advanced': return '🥇';
case 'expert': return '👑';
default: return '🏁';
}
return SkillLevelIconDisplay.getIcon(this.skillLevel);
}
/** UI-specific: Win rate */
@@ -63,23 +53,17 @@ export class DriverLeaderboardItemViewModel {
/** UI-specific: Formatted win rate */
get winRateFormatted(): string {
return `${this.winRate.toFixed(1)}%`;
return WinRateDisplay.format(this.winRate);
}
/** UI-specific: Rating trend */
get ratingTrend(): 'up' | 'down' | 'same' {
if (!this.previousRating) return 'same';
if (this.rating > this.previousRating) return 'up';
if (this.rating < this.previousRating) return 'down';
return 'same';
return RatingTrendDisplay.getTrend(this.rating, this.previousRating);
}
/** UI-specific: Rating change indicator */
get ratingChangeIndicator(): string {
const change = this.previousRating ? this.rating - this.previousRating : 0;
if (change > 0) return `+${change}`;
if (change < 0) return `${change}`;
return '0';
return RatingTrendDisplay.getChangeIndicator(this.rating, this.previousRating);
}
/** UI-specific: Position badge */