Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
90 lines
2.4 KiB
TypeScript
90 lines
2.4 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) : '—';
|
|
}
|
|
|
|
// Legacy compatibility
|
|
get driver() {
|
|
return {
|
|
id: this.id,
|
|
name: this.name,
|
|
countryCode: this.country,
|
|
avatarUrl: this.avatarUrl,
|
|
iracingId: this.iracingId,
|
|
joinedAtLabel: this.joinedAt,
|
|
bio: this.bio,
|
|
};
|
|
}
|
|
} |