do to formatters
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
'use client';
|
||||
|
||||
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
|
||||
import { DashboardConsistencyFormatter } from '@/lib/formatters/DashboardConsistencyFormatter';
|
||||
import { DashboardCountFormatter } from '@/lib/formatters/DashboardCountFormatter';
|
||||
import { DashboardDateFormatter } from '@/lib/formatters/DashboardDateFormatter';
|
||||
import { DashboardLeaguePositionFormatter } from '@/lib/formatters/DashboardLeaguePositionFormatter';
|
||||
import { DashboardRankFormatter } from '@/lib/formatters/DashboardRankFormatter';
|
||||
import { RatingFormatter } from '@/lib/formatters/RatingFormatter';
|
||||
import type { DashboardOverviewDTO } from '@/lib/types/generated/DashboardOverviewDTO';
|
||||
import type { DashboardViewData } from '@/lib/view-data/DashboardViewData';
|
||||
import { DashboardDateDisplay } from '@/lib/display-objects/DashboardDateDisplay';
|
||||
import { RatingDisplay } from '@/lib/display-objects/RatingDisplay';
|
||||
import { DashboardRankDisplay } from '@/lib/display-objects/DashboardRankDisplay';
|
||||
import { DashboardConsistencyDisplay } from '@/lib/display-objects/DashboardConsistencyDisplay';
|
||||
import { DashboardCountDisplay } from '@/lib/display-objects/DashboardCountDisplay';
|
||||
import { DashboardLeaguePositionDisplay } from '@/lib/display-objects/DashboardLeaguePositionDisplay';
|
||||
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
|
||||
|
||||
export class DashboardViewDataBuilder {
|
||||
public static build(apiDto: DashboardOverviewDTO): DashboardViewData {
|
||||
@@ -17,21 +17,21 @@ export class DashboardViewDataBuilder {
|
||||
name: apiDto.currentDriver?.name || '',
|
||||
avatarUrl: apiDto.currentDriver?.avatarUrl || '',
|
||||
country: apiDto.currentDriver?.country || '',
|
||||
rating: apiDto.currentDriver ? RatingDisplay.format(apiDto.currentDriver.rating ?? 0) : '0.0',
|
||||
rank: apiDto.currentDriver ? DashboardRankDisplay.format(apiDto.currentDriver.globalRank ?? 0) : '0',
|
||||
totalRaces: apiDto.currentDriver ? DashboardCountDisplay.format(apiDto.currentDriver.totalRaces ?? 0) : '0',
|
||||
wins: apiDto.currentDriver ? DashboardCountDisplay.format(apiDto.currentDriver.wins ?? 0) : '0',
|
||||
podiums: apiDto.currentDriver ? DashboardCountDisplay.format(apiDto.currentDriver.podiums ?? 0) : '0',
|
||||
consistency: apiDto.currentDriver ? DashboardConsistencyDisplay.format(apiDto.currentDriver.consistency ?? 0) : '0%',
|
||||
rating: apiDto.currentDriver ? RatingFormatter.format(apiDto.currentDriver.rating ?? 0) : '0.0',
|
||||
rank: apiDto.currentDriver ? DashboardRankFormatter.format(apiDto.currentDriver.globalRank ?? 0) : '0',
|
||||
totalRaces: apiDto.currentDriver ? DashboardCountFormatter.format(apiDto.currentDriver.totalRaces ?? 0) : '0',
|
||||
wins: apiDto.currentDriver ? DashboardCountFormatter.format(apiDto.currentDriver.wins ?? 0) : '0',
|
||||
podiums: apiDto.currentDriver ? DashboardCountFormatter.format(apiDto.currentDriver.podiums ?? 0) : '0',
|
||||
consistency: apiDto.currentDriver ? DashboardConsistencyFormatter.format(apiDto.currentDriver.consistency ?? 0) : '0%',
|
||||
},
|
||||
nextRace: apiDto.nextRace ? DashboardViewDataBuilder.buildNextRace(apiDto.nextRace) : null,
|
||||
upcomingRaces: apiDto.upcomingRaces.map((race) => DashboardViewDataBuilder.buildRace(race)),
|
||||
leagueStandings: apiDto.leagueStandingsSummaries.map((standing) => ({
|
||||
leagueId: standing.leagueId,
|
||||
leagueName: standing.leagueName,
|
||||
position: DashboardLeaguePositionDisplay.format(standing.position),
|
||||
points: DashboardCountDisplay.format(standing.points),
|
||||
totalDrivers: DashboardCountDisplay.format(standing.totalDrivers),
|
||||
position: DashboardLeaguePositionFormatter.format(standing.position),
|
||||
points: DashboardCountFormatter.format(standing.points),
|
||||
totalDrivers: DashboardCountFormatter.format(standing.totalDrivers),
|
||||
})),
|
||||
feedItems: apiDto.feedSummary.items.map((item) => ({
|
||||
id: item.id,
|
||||
@@ -39,7 +39,7 @@ export class DashboardViewDataBuilder {
|
||||
headline: item.headline,
|
||||
body: item.body ?? undefined,
|
||||
timestamp: item.timestamp,
|
||||
formattedTime: DashboardDateDisplay.format(new Date(item.timestamp)).relative,
|
||||
formattedTime: DashboardDateFormatter.format(new Date(item.timestamp)).relative,
|
||||
ctaHref: item.ctaHref ?? undefined,
|
||||
ctaLabel: item.ctaLabel ?? undefined,
|
||||
})),
|
||||
@@ -49,8 +49,8 @@ export class DashboardViewDataBuilder {
|
||||
avatarUrl: friend.avatarUrl || '',
|
||||
country: friend.country,
|
||||
})),
|
||||
activeLeaguesCount: DashboardCountDisplay.format(apiDto.activeLeaguesCount),
|
||||
friendCount: DashboardCountDisplay.format(apiDto.friends.length),
|
||||
activeLeaguesCount: DashboardCountFormatter.format(apiDto.activeLeaguesCount),
|
||||
friendCount: DashboardCountFormatter.format(apiDto.friends.length),
|
||||
hasUpcomingRaces: apiDto.upcomingRaces.length > 0,
|
||||
hasLeagueStandings: apiDto.leagueStandingsSummaries.length > 0,
|
||||
hasFeedItems: apiDto.feedSummary.items.length > 0,
|
||||
@@ -59,7 +59,7 @@ export class DashboardViewDataBuilder {
|
||||
}
|
||||
|
||||
private static buildNextRace(race: NonNullable<DashboardOverviewDTO['nextRace']>) {
|
||||
const dateInfo = DashboardDateDisplay.format(new Date(race.scheduledAt));
|
||||
const dateInfo = DashboardDateFormatter.format(new Date(race.scheduledAt));
|
||||
return {
|
||||
id: race.id,
|
||||
track: race.track,
|
||||
@@ -73,7 +73,7 @@ export class DashboardViewDataBuilder {
|
||||
}
|
||||
|
||||
private static buildRace(race: DashboardOverviewDTO['upcomingRaces'][number]) {
|
||||
const dateInfo = DashboardDateDisplay.format(new Date(race.scheduledAt));
|
||||
const dateInfo = DashboardDateFormatter.format(new Date(race.scheduledAt));
|
||||
return {
|
||||
id: race.id,
|
||||
track: race.track,
|
||||
|
||||
Reference in New Issue
Block a user