website refactor
This commit is contained in:
@@ -2,6 +2,11 @@ import type { GetDriverProfileOutputDTO } from '@/lib/types/generated/GetDriverP
|
||||
import type { ProfileViewData } from '@/lib/view-data/ProfileViewData';
|
||||
import { mediaConfig } from '@/lib/config/mediaConfig';
|
||||
import { CountryFlagDisplay } from '@/lib/display-objects/CountryFlagDisplay';
|
||||
import { DateDisplay } from '@/lib/display-objects/DateDisplay';
|
||||
import { FinishDisplay } from '@/lib/display-objects/FinishDisplay';
|
||||
import { PercentDisplay } from '@/lib/display-objects/PercentDisplay';
|
||||
import { RatingDisplay } from '@/lib/display-objects/RatingDisplay';
|
||||
import { NumberDisplay } from '@/lib/display-objects/NumberDisplay';
|
||||
|
||||
export class ProfileViewDataBuilder {
|
||||
static build(apiDto: GetDriverProfileOutputDTO): ProfileViewData {
|
||||
@@ -29,11 +34,6 @@ export class ProfileViewDataBuilder {
|
||||
const socialSummary = apiDto.socialSummary;
|
||||
const extended = apiDto.extendedProfile ?? null;
|
||||
|
||||
const joinedAtLabel = new Date(driver.joinedAt).toLocaleDateString('en-US', {
|
||||
month: 'short',
|
||||
year: 'numeric',
|
||||
});
|
||||
|
||||
return {
|
||||
driver: {
|
||||
id: driver.id,
|
||||
@@ -42,22 +42,22 @@ export class ProfileViewDataBuilder {
|
||||
countryFlag: CountryFlagDisplay.fromCountryCode(driver.country).toString(),
|
||||
avatarUrl: driver.avatarUrl || mediaConfig.avatars.defaultFallback,
|
||||
bio: driver.bio || null,
|
||||
iracingId: driver.iracingId || null,
|
||||
joinedAtLabel,
|
||||
iracingId: driver.iracingId ? String(driver.iracingId) : null,
|
||||
joinedAtLabel: DateDisplay.formatMonthYear(driver.joinedAt),
|
||||
},
|
||||
stats: stats
|
||||
? {
|
||||
ratingLabel: stats.rating != null ? String(stats.rating) : '0',
|
||||
ratingLabel: RatingDisplay.format(stats.rating),
|
||||
globalRankLabel: driver.globalRank != null ? `#${driver.globalRank}` : '—',
|
||||
totalRacesLabel: String(stats.totalRaces),
|
||||
winsLabel: String(stats.wins),
|
||||
podiumsLabel: String(stats.podiums),
|
||||
dnfsLabel: String(stats.dnfs),
|
||||
bestFinishLabel: stats.bestFinish != null ? `P${stats.bestFinish}` : '—',
|
||||
worstFinishLabel: stats.worstFinish != null ? `P${stats.worstFinish}` : '—',
|
||||
avgFinishLabel: stats.avgFinish != null ? `P${stats.avgFinish.toFixed(1)}` : '—',
|
||||
consistencyLabel: stats.consistency != null ? `${stats.consistency}%` : '0%',
|
||||
percentileLabel: stats.percentile != null ? `${stats.percentile}%` : '—',
|
||||
totalRacesLabel: NumberDisplay.format(stats.totalRaces),
|
||||
winsLabel: NumberDisplay.format(stats.wins),
|
||||
podiumsLabel: NumberDisplay.format(stats.podiums),
|
||||
dnfsLabel: NumberDisplay.format(stats.dnfs),
|
||||
bestFinishLabel: FinishDisplay.format(stats.bestFinish),
|
||||
worstFinishLabel: FinishDisplay.format(stats.worstFinish),
|
||||
avgFinishLabel: FinishDisplay.formatAverage(stats.avgFinish),
|
||||
consistencyLabel: PercentDisplay.formatWhole(stats.consistency),
|
||||
percentileLabel: PercentDisplay.format(stats.percentile),
|
||||
}
|
||||
: null,
|
||||
teamMemberships: apiDto.teamMemberships.map((m) => ({
|
||||
@@ -65,10 +65,7 @@ export class ProfileViewDataBuilder {
|
||||
teamName: m.teamName,
|
||||
teamTag: m.teamTag || null,
|
||||
roleLabel: m.role,
|
||||
joinedAtLabel: new Date(m.joinedAt).toLocaleDateString('en-US', {
|
||||
month: 'short',
|
||||
year: 'numeric',
|
||||
}),
|
||||
joinedAtLabel: DateDisplay.formatMonthYear(m.joinedAt),
|
||||
href: `/teams/${m.teamId}`,
|
||||
})),
|
||||
extendedProfile: extended
|
||||
@@ -89,12 +86,8 @@ export class ProfileViewDataBuilder {
|
||||
id: a.id,
|
||||
title: a.title,
|
||||
description: a.description,
|
||||
earnedAtLabel: new Date(a.earnedAt).toLocaleDateString('en-US', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
}),
|
||||
icon: a.icon as NonNullable<ProfileViewData['extendedProfile']>['achievements'][number]['icon'],
|
||||
earnedAtLabel: DateDisplay.formatShort(a.earnedAt),
|
||||
icon: a.icon as any,
|
||||
rarityLabel: a.rarity,
|
||||
})),
|
||||
friends: socialSummary.friends.slice(0, 8).map((f) => ({
|
||||
@@ -104,7 +97,7 @@ export class ProfileViewDataBuilder {
|
||||
avatarUrl: f.avatarUrl || mediaConfig.avatars.defaultFallback,
|
||||
href: `/drivers/${f.id}`,
|
||||
})),
|
||||
friendsCountLabel: String(socialSummary.friendsCount),
|
||||
friendsCountLabel: NumberDisplay.format(socialSummary.friendsCount),
|
||||
}
|
||||
: null,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user