website cleanup
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
import Card from '../ui/Card';
|
||||
import RankBadge from './RankBadge';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { getPrimaryLeagueIdForDriver } from '@/lib/leagueMembership';
|
||||
import { useMemo } from 'react';
|
||||
import { useDriverProfile } from '@/hooks/useDriverService';
|
||||
|
||||
interface ProfileStatsProps {
|
||||
driverId?: string;
|
||||
@@ -17,43 +17,36 @@ interface ProfileStatsProps {
|
||||
};
|
||||
}
|
||||
|
||||
type DriverProfileOverviewViewModel = ProfileOverviewOutputPort | null;
|
||||
|
||||
export default function ProfileStats({ driverId, stats }: ProfileStatsProps) {
|
||||
const [profileData, setProfileData] = useState<DriverProfileOverviewViewModel>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (driverId) {
|
||||
const load = async () => {
|
||||
const profileUseCase = getGetProfileOverviewUseCase();
|
||||
const vm = await profileUseCase.execute({ driverId });
|
||||
setProfileData(vm);
|
||||
};
|
||||
void load();
|
||||
const { data: profileData } = useDriverProfile(driverId ?? '');
|
||||
|
||||
const driverStats = profileData?.stats ?? null;
|
||||
const totalDrivers = profileData?.currentDriver?.totalDrivers ?? 0;
|
||||
|
||||
// League rank widget needs a dedicated API contract; keep it disabled until provided.
|
||||
// (Leaving UI block out avoids `never` typing issues.)
|
||||
|
||||
const defaultStats = useMemo(() => {
|
||||
if (stats) {
|
||||
return stats;
|
||||
}
|
||||
}, [driverId]);
|
||||
|
||||
const driverStats = profileData?.stats || null;
|
||||
const totalDrivers = profileData?.driver?.totalDrivers ?? 0;
|
||||
const primaryLeagueId = driverId ? getPrimaryLeagueIdForDriver(driverId) : null;
|
||||
const leagueRank =
|
||||
driverId && primaryLeagueId ? getLeagueRankings(driverId, primaryLeagueId) : null;
|
||||
if (!driverStats) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const defaultStats =
|
||||
stats ||
|
||||
(driverStats
|
||||
? {
|
||||
totalRaces: driverStats.totalRaces,
|
||||
wins: driverStats.wins,
|
||||
podiums: driverStats.podiums,
|
||||
dnfs: driverStats.dnfs,
|
||||
avgFinish: driverStats.avgFinish ?? 0,
|
||||
completionRate:
|
||||
driverStats.totalRaces > 0
|
||||
? ((driverStats.totalRaces - driverStats.dnfs) / driverStats.totalRaces) * 100
|
||||
: 0,
|
||||
}
|
||||
: null);
|
||||
return {
|
||||
totalRaces: driverStats.totalRaces,
|
||||
wins: driverStats.wins,
|
||||
podiums: driverStats.podiums,
|
||||
dnfs: driverStats.dnfs,
|
||||
avgFinish: driverStats.avgFinish ?? 0,
|
||||
completionRate:
|
||||
driverStats.totalRaces > 0
|
||||
? ((driverStats.totalRaces - driverStats.dnfs) / driverStats.totalRaces) * 100
|
||||
: 0,
|
||||
};
|
||||
}, [stats, driverStats]);
|
||||
|
||||
const winRate =
|
||||
defaultStats && defaultStats.totalRaces > 0
|
||||
@@ -134,27 +127,7 @@ export default function ProfileStats({ driverId, stats }: ProfileStatsProps) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{leagueRank && leagueRank.totalDrivers > 0 && (
|
||||
<div className="p-4 rounded-lg bg-deep-graphite border border-charcoal-outline">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<RankBadge rank={leagueRank.rank} size="md" />
|
||||
<div>
|
||||
<div className="text-white font-medium">Primary League</div>
|
||||
<div className="text-sm text-gray-400">
|
||||
{leagueRank.rank} of {leagueRank.totalDrivers} drivers
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className={`text-sm font-medium ${getPercentileColor(leagueRank.percentile)}`}>
|
||||
{getPercentileLabel(leagueRank.percentile)}
|
||||
</div>
|
||||
<div className="text-xs text-gray-500">League Percentile</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{/* Primary-league ranking removed until we have a dedicated API + view model for league ranks. */}
|
||||
</div>
|
||||
</Card>
|
||||
)}
|
||||
@@ -264,4 +237,4 @@ function PerformanceRow({ label, races, wins, podiums, avgFinish }: {
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user