docs
This commit is contained in:
88
apps/website/app/dashboard/DashboardViewDataBuilder.ts
Normal file
88
apps/website/app/dashboard/DashboardViewDataBuilder.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import type { DashboardOverviewViewModelData } from '@/lib/view-models/DashboardOverviewViewModelData';
|
||||
import type { DashboardViewData } from './DashboardViewData';
|
||||
import {
|
||||
formatDashboardDate,
|
||||
formatRating,
|
||||
formatRank,
|
||||
formatConsistency,
|
||||
formatRaceCount,
|
||||
formatFriendCount,
|
||||
formatLeaguePosition,
|
||||
formatPoints,
|
||||
formatTotalDrivers,
|
||||
} from '@/lib/display-objects/DashboardDisplay';
|
||||
|
||||
/**
|
||||
* Build DashboardViewData directly from ViewModelData
|
||||
* Used for SSR phase - no ViewModel instantiation
|
||||
*/
|
||||
export function buildDashboardViewData(viewModelData: DashboardOverviewViewModelData): DashboardViewData {
|
||||
return {
|
||||
currentDriver: {
|
||||
name: viewModelData.currentDriver?.name || '',
|
||||
avatarUrl: viewModelData.currentDriver?.avatarUrl || '',
|
||||
country: viewModelData.currentDriver?.country || '',
|
||||
rating: viewModelData.currentDriver ? formatRating(viewModelData.currentDriver.rating) : '0.0',
|
||||
rank: viewModelData.currentDriver ? formatRank(viewModelData.currentDriver.globalRank) : '0',
|
||||
totalRaces: viewModelData.currentDriver ? formatRaceCount(viewModelData.currentDriver.totalRaces) : '0',
|
||||
wins: viewModelData.currentDriver ? formatRaceCount(viewModelData.currentDriver.wins) : '0',
|
||||
podiums: viewModelData.currentDriver ? formatRaceCount(viewModelData.currentDriver.podiums) : '0',
|
||||
consistency: viewModelData.currentDriver ? formatConsistency(viewModelData.currentDriver.consistency) : '0%',
|
||||
},
|
||||
nextRace: viewModelData.nextRace ? (() => {
|
||||
const dateInfo = formatDashboardDate(new Date(viewModelData.nextRace.scheduledAt));
|
||||
return {
|
||||
id: viewModelData.nextRace.id,
|
||||
track: viewModelData.nextRace.track,
|
||||
car: viewModelData.nextRace.car,
|
||||
scheduledAt: viewModelData.nextRace.scheduledAt,
|
||||
formattedDate: dateInfo.date,
|
||||
formattedTime: dateInfo.time,
|
||||
timeUntil: dateInfo.relative,
|
||||
isMyLeague: viewModelData.nextRace.isMyLeague,
|
||||
};
|
||||
})() : null,
|
||||
upcomingRaces: viewModelData.upcomingRaces.map((race) => {
|
||||
const dateInfo = formatDashboardDate(new Date(race.scheduledAt));
|
||||
return {
|
||||
id: race.id,
|
||||
track: race.track,
|
||||
car: race.car,
|
||||
scheduledAt: race.scheduledAt,
|
||||
formattedDate: dateInfo.date,
|
||||
formattedTime: dateInfo.time,
|
||||
timeUntil: dateInfo.relative,
|
||||
isMyLeague: race.isMyLeague,
|
||||
};
|
||||
}),
|
||||
leagueStandings: viewModelData.leagueStandingsSummaries.map((standing) => ({
|
||||
leagueId: standing.leagueId,
|
||||
leagueName: standing.leagueName,
|
||||
position: formatLeaguePosition(standing.position),
|
||||
points: formatPoints(standing.points),
|
||||
totalDrivers: formatTotalDrivers(standing.totalDrivers),
|
||||
})),
|
||||
feedItems: viewModelData.feedSummary.items.map((item) => ({
|
||||
id: item.id,
|
||||
type: item.type,
|
||||
headline: item.headline,
|
||||
body: item.body,
|
||||
timestamp: item.timestamp,
|
||||
formattedTime: formatDashboardDate(new Date(item.timestamp)).relative,
|
||||
ctaHref: item.ctaHref,
|
||||
ctaLabel: item.ctaLabel,
|
||||
})),
|
||||
friends: viewModelData.friends.map((friend) => ({
|
||||
id: friend.id,
|
||||
name: friend.name,
|
||||
avatarUrl: friend.avatarUrl,
|
||||
country: friend.country,
|
||||
})),
|
||||
activeLeaguesCount: formatRaceCount(viewModelData.activeLeaguesCount),
|
||||
friendCount: formatFriendCount(viewModelData.friends.length),
|
||||
hasUpcomingRaces: viewModelData.upcomingRaces.length > 0,
|
||||
hasLeagueStandings: viewModelData.leagueStandingsSummaries.length > 0,
|
||||
hasFeedItems: viewModelData.feedSummary.items.length > 0,
|
||||
hasFriends: viewModelData.friends.length > 0,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user