Files
gridpilot.gg/apps/website/lib/view-models/DriverProfileDriverSummaryViewModel.ts
Marc Mintel d97f50ed72
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 6m4s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-23 11:59:49 +01:00

77 lines
2.2 KiB
TypeScript

import { ViewModel } from "../contracts/view-models/ViewModel";
import { ProfileViewData } from "../view-data/ProfileViewData";
import { RatingDisplay } from "../display-objects/RatingDisplay";
import { DashboardConsistencyDisplay } from "../display-objects/DashboardConsistencyDisplay";
import { NumberDisplay } from "../display-objects/NumberDisplay";
/**
* 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 RatingDisplay.format(this.rating);
}
get globalRank(): number | null {
return this.viewData.stats?.globalRankLabel ? Number(this.viewData.stats.globalRankLabel) : null;
}
get globalRankLabel(): string {
return this.globalRank ? NumberDisplay.format(this.globalRank) : '—';
}
get consistency(): number | null {
return this.viewData.stats?.consistencyLabel ? Number(this.viewData.stats.consistencyLabel) : null;
}
get consistencyLabel(): string {
return this.consistency ? DashboardConsistencyDisplay.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 ? NumberDisplay.format(this.totalDrivers) : '—';
}
}