77 lines
2.2 KiB
TypeScript
77 lines
2.2 KiB
TypeScript
import { ViewModel } from "../contracts/view-models/ViewModel";
|
|
import { DashboardConsistencyFormatter } from "../formatters/DashboardConsistencyFormatter";
|
|
import { NumberFormatter } from "../formatters/NumberFormatter";
|
|
import { RatingFormatter } from "../formatters/RatingFormatter";
|
|
import { ProfileViewData } from "../view-data/ProfileViewData";
|
|
|
|
/**
|
|
* Driver Profile Driver Summary View Model
|
|
*
|
|
* Represents a fully prepared UI state for driver summary display.
|
|
* Transforms ViewData into UI-ready data structures.
|
|
*/
|
|
export class DriverProfileDriverSummaryViewModel extends ViewModel {
|
|
constructor(private readonly viewData: ProfileViewData) {
|
|
super();
|
|
}
|
|
|
|
get id(): string {
|
|
return this.viewData.driver.id;
|
|
}
|
|
|
|
get name(): string {
|
|
return this.viewData.driver.name;
|
|
}
|
|
|
|
get country(): string {
|
|
return this.viewData.driver.countryCode;
|
|
}
|
|
|
|
get avatarUrl(): string {
|
|
return this.viewData.driver.avatarUrl;
|
|
}
|
|
|
|
get iracingId(): string | null {
|
|
return this.viewData.driver.iracingId;
|
|
}
|
|
|
|
get joinedAt(): string {
|
|
return this.viewData.driver.joinedAtLabel;
|
|
}
|
|
|
|
get rating(): number | null {
|
|
return this.viewData.stats?.ratingLabel ? Number(this.viewData.stats.ratingLabel) : null;
|
|
}
|
|
|
|
get ratingLabel(): string {
|
|
return RatingFormatter.format(this.rating);
|
|
}
|
|
|
|
get globalRank(): number | null {
|
|
return this.viewData.stats?.globalRankLabel ? Number(this.viewData.stats.globalRankLabel) : null;
|
|
}
|
|
|
|
get globalRankLabel(): string {
|
|
return this.globalRank ? NumberFormatter.format(this.globalRank) : '—';
|
|
}
|
|
|
|
get consistency(): number | null {
|
|
return this.viewData.stats?.consistencyLabel ? Number(this.viewData.stats.consistencyLabel) : null;
|
|
}
|
|
|
|
get consistencyLabel(): string {
|
|
return this.consistency ? DashboardConsistencyFormatter.format(this.consistency) : '—';
|
|
}
|
|
|
|
get bio(): string | null {
|
|
return this.viewData.driver.bio;
|
|
}
|
|
|
|
get totalDrivers(): number | null {
|
|
return this.viewData.stats?.totalRacesLabel ? Number(this.viewData.stats.totalRacesLabel) : null;
|
|
}
|
|
|
|
get totalDriversLabel(): string {
|
|
return this.totalDrivers ? NumberFormatter.format(this.totalDrivers) : '—';
|
|
}
|
|
} |