website refactor
This commit is contained in:
@@ -1,28 +1,25 @@
|
||||
import type { RacesPageDataDTO } from '@/lib/types/generated/RacesPageDataDTO';
|
||||
import type { RacesViewData, RaceViewData } from '@/lib/view-data/RacesViewData';
|
||||
import { DateDisplay } from '@/lib/display-objects/DateDisplay';
|
||||
import { RaceStatusDisplay } from '@/lib/display-objects/RaceStatusDisplay';
|
||||
import { RelativeTimeDisplay } from '@/lib/display-objects/RelativeTimeDisplay';
|
||||
|
||||
export class RacesViewDataBuilder {
|
||||
static build(apiDto: RacesPageDataDTO): RacesViewData {
|
||||
const now = new Date();
|
||||
const races = apiDto.races.map((race): RaceViewData => {
|
||||
const scheduledAt = new Date(race.scheduledAt);
|
||||
|
||||
return {
|
||||
id: race.id,
|
||||
track: race.track,
|
||||
car: race.car,
|
||||
scheduledAt: race.scheduledAt,
|
||||
scheduledAtLabel: scheduledAt.toLocaleDateString('en-US', {
|
||||
weekday: 'short',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
}),
|
||||
timeLabel: scheduledAt.toLocaleTimeString('en-US', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}),
|
||||
relativeTimeLabel: this.getRelativeTime(scheduledAt),
|
||||
scheduledAtLabel: DateDisplay.formatShort(race.scheduledAt),
|
||||
timeLabel: DateDisplay.formatTime(race.scheduledAt),
|
||||
relativeTimeLabel: RelativeTimeDisplay.format(race.scheduledAt, now),
|
||||
status: race.status as RaceViewData['status'],
|
||||
statusLabel: this.getStatusLabel(race.status),
|
||||
statusLabel: RaceStatusDisplay.getLabel(race.status),
|
||||
statusVariant: RaceStatusDisplay.getVariant(race.status),
|
||||
statusIconName: RaceStatusDisplay.getIconName(race.status),
|
||||
sessionType: 'Race',
|
||||
leagueId: race.leagueId,
|
||||
leagueName: race.leagueName,
|
||||
@@ -69,32 +66,4 @@ export class RacesViewDataBuilder {
|
||||
racesByDate,
|
||||
};
|
||||
}
|
||||
|
||||
private static getStatusLabel(status: string): string {
|
||||
switch (status) {
|
||||
case 'scheduled': return 'Scheduled';
|
||||
case 'running': return 'LIVE';
|
||||
case 'completed': return 'Completed';
|
||||
case 'cancelled': return 'Cancelled';
|
||||
default: return status;
|
||||
}
|
||||
}
|
||||
|
||||
private static getRelativeTime(date: Date): string {
|
||||
const now = new Date();
|
||||
const diffMs = date.getTime() - now.getTime();
|
||||
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
|
||||
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
||||
|
||||
if (diffMs < 0) return 'Past';
|
||||
if (diffHours < 1) return 'Starting soon';
|
||||
if (diffHours < 24) return `In ${diffHours}h`;
|
||||
if (diffDays === 1) return 'Tomorrow';
|
||||
if (diffDays < 7) return `In ${diffDays} days`;
|
||||
return date.toLocaleDateString('en-US', {
|
||||
weekday: 'short',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import type { TeamDetailPageDto } from '@/lib/page-queries/TeamDetailPageQuery';
|
||||
import type { TeamDetailViewData, TeamDetailData, TeamMemberData, SponsorMetric, TeamTab } from '@/lib/view-data/TeamDetailViewData';
|
||||
import { DateDisplay } from '@/lib/display-objects/DateDisplay';
|
||||
import { MemberDisplay } from '@/lib/display-objects/MemberDisplay';
|
||||
import { LeagueDisplay } from '@/lib/display-objects/LeagueDisplay';
|
||||
|
||||
/**
|
||||
* TeamDetailViewDataBuilder - Transforms TeamDetailPageDto into ViewData
|
||||
@@ -15,6 +18,7 @@ export class TeamDetailViewDataBuilder {
|
||||
ownerId: apiDto.team.ownerId,
|
||||
leagues: apiDto.team.leagues,
|
||||
createdAt: apiDto.team.createdAt,
|
||||
foundedDateLabel: apiDto.team.createdAt ? DateDisplay.formatMonthYear(apiDto.team.createdAt) : 'Unknown',
|
||||
specialization: apiDto.team.specialization,
|
||||
region: apiDto.team.region,
|
||||
languages: apiDto.team.languages,
|
||||
@@ -28,6 +32,7 @@ export class TeamDetailViewDataBuilder {
|
||||
driverName: membership.driverName,
|
||||
role: membership.role,
|
||||
joinedAt: membership.joinedAt,
|
||||
joinedAtLabel: DateDisplay.formatShort(membership.joinedAt),
|
||||
isActive: membership.isActive,
|
||||
avatarUrl: membership.avatarUrl,
|
||||
}));
|
||||
@@ -80,6 +85,8 @@ export class TeamDetailViewDataBuilder {
|
||||
isAdmin,
|
||||
teamMetrics,
|
||||
tabs,
|
||||
memberCountLabel: MemberDisplay.formatCount(memberships.length),
|
||||
leagueCountLabel: LeagueDisplay.formatCount(leagueCount),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user