website cleanup
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import type { DriverDTO } from '@core/racing/application/dto/DriverDTO';
|
||||
import type { DriverDTO } from '@/lib/types/generated/DriverDTO';
|
||||
import Card from '../ui/Card';
|
||||
import ProfileHeader from '../profile/ProfileHeader';
|
||||
import ProfileStats from './ProfileStats';
|
||||
@@ -8,17 +8,14 @@ import CareerHighlights from './CareerHighlights';
|
||||
import DriverRankings from './DriverRankings';
|
||||
import PerformanceMetrics from './PerformanceMetrics';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { DriverTeamPresenter } from '@/lib/presenters/DriverTeamPresenter';
|
||||
import { getPrimaryLeagueIdForDriver } from '@/lib/leagueMembership';
|
||||
import type { ProfileOverviewOutputPort } from '@core/racing/application/ports/output/ProfileOverviewOutputPort';
|
||||
import type { DriverTeamViewModel } from '@core/racing/application/presenters/IDriverTeamPresenter';
|
||||
import { useServices } from '@/lib/services/ServiceProvider';
|
||||
|
||||
interface DriverProfileProps {
|
||||
driver: DriverDTO;
|
||||
isOwnProfile?: boolean;
|
||||
onEditClick?: () => void;
|
||||
}
|
||||
|
||||
|
||||
interface DriverProfileStatsViewModel {
|
||||
rating: number;
|
||||
wins: number;
|
||||
@@ -33,36 +30,49 @@ interface DriverProfileStatsViewModel {
|
||||
overallRank?: number;
|
||||
}
|
||||
|
||||
type DriverProfileOverviewViewModel = ProfileOverviewOutputPort | null;
|
||||
interface DriverTeamViewModel {
|
||||
team: {
|
||||
name: string;
|
||||
tag: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default function DriverProfile({ driver, isOwnProfile = false, onEditClick }: DriverProfileProps) {
|
||||
const [profileData, setProfileData] = useState<DriverProfileOverviewViewModel>(null);
|
||||
const { driverService } = useServices();
|
||||
const [profileData, setProfileData] = useState<DriverProfileStatsViewModel | null>(null);
|
||||
const [teamData, setTeamData] = useState<DriverTeamViewModel | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const load = async () => {
|
||||
// Load profile data using GetProfileOverviewUseCase
|
||||
const profileUseCase = getGetProfileOverviewUseCase();
|
||||
const profileViewModel = await profileUseCase.execute({ driverId: driver.id });
|
||||
setProfileData(profileViewModel);
|
||||
|
||||
// Load team data using caller-owned presenter
|
||||
const teamUseCase = getGetDriverTeamUseCase();
|
||||
const driverTeamPresenter = new DriverTeamPresenter();
|
||||
await teamUseCase.execute({ driverId: driver.id }, driverTeamPresenter);
|
||||
const teamResult = driverTeamPresenter.getViewModel();
|
||||
setTeamData(teamResult ?? null);
|
||||
try {
|
||||
// Load driver profile
|
||||
const profile = await driverService.getDriverProfile(driver.id);
|
||||
|
||||
// Extract stats from profile
|
||||
if (profile.stats) {
|
||||
setProfileData(profile.stats);
|
||||
}
|
||||
|
||||
// Load team data if available
|
||||
if (profile.teamMemberships && profile.teamMemberships.length > 0) {
|
||||
const currentTeam = profile.teamMemberships.find(m => m.isCurrent) || profile.teamMemberships[0];
|
||||
setTeamData({
|
||||
team: {
|
||||
name: currentTeam.teamName,
|
||||
tag: currentTeam.teamTag ?? ''
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load driver profile data:', error);
|
||||
}
|
||||
};
|
||||
void load();
|
||||
}, [driver.id]);
|
||||
}, [driver.id, driverService]);
|
||||
|
||||
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?.driver?.globalRank ?? null;
|
||||
const totalDrivers = profileData?.driver?.totalDrivers ?? 0;
|
||||
const driverStats = profileData;
|
||||
const globalRank = profileData?.overallRank ?? null;
|
||||
const totalDrivers = 1000; // Placeholder
|
||||
|
||||
const performanceStats = driverStats ? {
|
||||
winRate: driverStats.totalRaces > 0 ? (driverStats.wins / driverStats.totalRaces) * 100 : 0,
|
||||
@@ -83,14 +93,6 @@ export default function DriverProfile({ driver, isOwnProfile = false, onEditClic
|
||||
percentile: driverStats.percentile ?? 0,
|
||||
rating: driverStats.rating ?? 0,
|
||||
},
|
||||
{
|
||||
type: 'league' as const,
|
||||
name: 'Primary League',
|
||||
rank: leagueRank.rank,
|
||||
totalDrivers: leagueRank.totalDrivers,
|
||||
percentile: leagueRank.percentile,
|
||||
rating: driverStats.rating ?? 0,
|
||||
},
|
||||
] : [];
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user