wip
This commit is contained in:
@@ -8,7 +8,7 @@ import CareerHighlights from './CareerHighlights';
|
||||
import DriverRankings from './DriverRankings';
|
||||
import PerformanceMetrics from './PerformanceMetrics';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { getDriverStats, getLeagueRankings, getGetDriverTeamUseCase, getAllDriverRankings } from '@/lib/di-container';
|
||||
import { getLeagueRankings, getGetDriverTeamUseCase, getGetProfileOverviewUseCase } from '@/lib/di-container';
|
||||
import { getPrimaryLeagueIdForDriver } from '@/lib/leagueMembership';
|
||||
import type { GetDriverTeamQueryResultDTO } from '@gridpilot/racing/application/dto/TeamCommandAndQueryDTO';
|
||||
|
||||
@@ -19,24 +19,34 @@ interface DriverProfileProps {
|
||||
}
|
||||
|
||||
export default function DriverProfile({ driver, isOwnProfile = false, onEditClick }: DriverProfileProps) {
|
||||
const driverStats = getDriverStats(driver.id);
|
||||
const primaryLeagueId = getPrimaryLeagueIdForDriver(driver.id);
|
||||
const leagueRank = primaryLeagueId
|
||||
? getLeagueRankings(driver.id, primaryLeagueId)
|
||||
: { rank: 0, totalDrivers: 0, percentile: 0 };
|
||||
const allRankings = getAllDriverRankings();
|
||||
const [profileData, setProfileData] = useState<any>(null);
|
||||
const [teamData, setTeamData] = useState<GetDriverTeamQueryResultDTO | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const load = async () => {
|
||||
const useCase = getGetDriverTeamUseCase();
|
||||
await useCase.execute({ driverId: driver.id });
|
||||
const viewModel = useCase.presenter.getViewModel();
|
||||
setTeamData(viewModel.result);
|
||||
// Load profile data using GetProfileOverviewUseCase
|
||||
const profileUseCase = getGetProfileOverviewUseCase();
|
||||
await profileUseCase.execute({ driverId: driver.id });
|
||||
const profileViewModel = profileUseCase.presenter.getViewModel();
|
||||
setProfileData(profileViewModel);
|
||||
|
||||
// Load team data
|
||||
const teamUseCase = getGetDriverTeamUseCase();
|
||||
await teamUseCase.execute({ driverId: driver.id });
|
||||
const teamViewModel = teamUseCase.presenter.getViewModel();
|
||||
setTeamData(teamViewModel.result);
|
||||
};
|
||||
void load();
|
||||
}, [driver.id]);
|
||||
|
||||
const driverStats = profileData?.stats || null;
|
||||
const primaryLeagueId = getPrimaryLeagueIdForDriver(driver.id);
|
||||
const leagueRank = primaryLeagueId
|
||||
? getLeagueRankings(driver.id, primaryLeagueId)
|
||||
: { rank: 0, totalDrivers: 0, percentile: 0 };
|
||||
const globalRank = profileData?.currentDriver?.globalRank || null;
|
||||
const totalDrivers = profileData?.currentDriver?.totalDrivers || 0;
|
||||
|
||||
const performanceStats = driverStats ? {
|
||||
winRate: (driverStats.wins / driverStats.totalRaces) * 100,
|
||||
podiumRate: (driverStats.podiums / driverStats.totalRaces) * 100,
|
||||
@@ -51,8 +61,8 @@ export default function DriverProfile({ driver, isOwnProfile = false, onEditClic
|
||||
{
|
||||
type: 'overall' as const,
|
||||
name: 'Overall Ranking',
|
||||
rank: driverStats.overallRank,
|
||||
totalDrivers: allRankings.length,
|
||||
rank: globalRank || driverStats.overallRank || 0,
|
||||
totalDrivers: totalDrivers,
|
||||
percentile: driverStats.percentile,
|
||||
rating: driverStats.rating,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user