view data fixes
This commit is contained in:
@@ -1,28 +1,24 @@
|
||||
import { RaceDetailUserResultDTO } from '@/lib/types/generated/RaceDetailUserResultDTO';
|
||||
|
||||
import { ViewModel } from "../contracts/view-models/ViewModel";
|
||||
import { DurationDisplay } from "../display-objects/DurationDisplay";
|
||||
import type { RaceDetailUserResultViewData } from "../view-data/RaceDetailUserResultViewData";
|
||||
|
||||
export class RaceDetailUserResultViewModel extends ViewModel {
|
||||
position!: number;
|
||||
startPosition!: number;
|
||||
incidents!: number;
|
||||
fastestLap!: number;
|
||||
positionChange!: number;
|
||||
isPodium!: boolean;
|
||||
isClean!: boolean;
|
||||
ratingChange!: number;
|
||||
private readonly data: RaceDetailUserResultViewData;
|
||||
|
||||
constructor(dto: RaceDetailUserResultDTO) {
|
||||
this.position = dto.position;
|
||||
this.startPosition = dto.startPosition;
|
||||
this.incidents = dto.incidents;
|
||||
this.fastestLap = dto.fastestLap;
|
||||
this.positionChange = dto.positionChange;
|
||||
this.isPodium = dto.isPodium;
|
||||
this.isClean = dto.isClean;
|
||||
this.ratingChange = dto.ratingChange ?? 0;
|
||||
constructor(data: RaceDetailUserResultViewData) {
|
||||
super();
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
get position(): number { return this.data.position; }
|
||||
get startPosition(): number { return this.data.startPosition; }
|
||||
get incidents(): number { return this.data.incidents; }
|
||||
get fastestLap(): number { return this.data.fastestLap; }
|
||||
get positionChange(): number { return this.data.positionChange; }
|
||||
get isPodium(): boolean { return this.data.isPodium; }
|
||||
get isClean(): boolean { return this.data.isClean; }
|
||||
get ratingChange(): number { return this.data.ratingChange; }
|
||||
|
||||
/** UI-specific: Display for position change */
|
||||
get positionChangeDisplay(): string {
|
||||
if (this.positionChange > 0) return `+${this.positionChange}`;
|
||||
@@ -58,9 +54,6 @@ export class RaceDetailUserResultViewModel extends ViewModel {
|
||||
/** UI-specific: Formatted lap time */
|
||||
get lapTimeFormatted(): string {
|
||||
if (this.fastestLap <= 0) return '--:--.---';
|
||||
const minutes = Math.floor(this.fastestLap / 60);
|
||||
const seconds = Math.floor(this.fastestLap % 60);
|
||||
const milliseconds = Math.floor((this.fastestLap % 1) * 1000);
|
||||
return `${minutes}:${seconds.toString().padStart(2, '0')}.${milliseconds.toString().padStart(3, '0')}`;
|
||||
return DurationDisplay.formatSeconds(this.fastestLap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user