website refactor
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { LeaderboardsTemplate } from '@/templates/LeaderboardsTemplate';
|
||||
import type { LeaderboardsViewData } from '@/lib/view-data/LeaderboardsViewData';
|
||||
import { routes } from '@/lib/routing/RouteConfig';
|
||||
|
||||
export function LeaderboardsPageWrapper({ data }: { data: LeaderboardsViewData | null }) {
|
||||
const router = useRouter();
|
||||
|
||||
if (!data || (!data.drivers && !data.teams)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleDriverClick = (driverId: string) => {
|
||||
router.push(routes.driver.detail(driverId));
|
||||
};
|
||||
|
||||
const handleTeamClick = (teamId: string) => {
|
||||
router.push(routes.team.detail(teamId));
|
||||
};
|
||||
|
||||
const handleNavigateToDrivers = () => {
|
||||
router.push(routes.leaderboards.drivers);
|
||||
};
|
||||
|
||||
const handleNavigateToTeams = () => {
|
||||
router.push(routes.team.leaderboard);
|
||||
};
|
||||
|
||||
// Transform ViewData to template props (simple field mapping only)
|
||||
const templateData = {
|
||||
drivers: data.drivers.map(d => ({
|
||||
id: d.id,
|
||||
name: d.name,
|
||||
rating: d.rating,
|
||||
skillLevel: d.skillLevel,
|
||||
nationality: d.nationality,
|
||||
wins: d.wins,
|
||||
rank: d.rank,
|
||||
avatarUrl: d.avatarUrl,
|
||||
position: d.position,
|
||||
})),
|
||||
teams: data.teams.map(t => ({
|
||||
id: t.id,
|
||||
name: t.name,
|
||||
tag: t.tag,
|
||||
memberCount: t.memberCount,
|
||||
category: t.category,
|
||||
totalWins: t.totalWins,
|
||||
logoUrl: t.logoUrl,
|
||||
position: t.position,
|
||||
})),
|
||||
onDriverClick: handleDriverClick,
|
||||
onTeamClick: handleTeamClick,
|
||||
onNavigateToDrivers: handleNavigateToDrivers,
|
||||
onNavigateToTeams: handleNavigateToTeams,
|
||||
};
|
||||
|
||||
return <LeaderboardsTemplate {...templateData} />;
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
import { notFound, redirect } from 'next/navigation';
|
||||
import { LeaderboardsPageQuery } from '@/lib/page-queries/page-queries/LeaderboardsPageQuery';
|
||||
import { LeaderboardsPageWrapper } from './LeaderboardsPageWrapper';
|
||||
import { LeaderboardsTemplate } from '@/templates/LeaderboardsTemplate';
|
||||
import { routes } from '@/lib/routing/RouteConfig';
|
||||
|
||||
export default async function LeaderboardsPage() {
|
||||
const result = await LeaderboardsPageQuery.execute();
|
||||
|
||||
|
||||
if (result.isErr()) {
|
||||
const error = result.getError();
|
||||
|
||||
|
||||
// Handle different error types
|
||||
if (error === 'notFound') {
|
||||
notFound();
|
||||
@@ -20,8 +20,8 @@ export default async function LeaderboardsPage() {
|
||||
notFound();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Success
|
||||
const viewData = result.unwrap();
|
||||
return <LeaderboardsPageWrapper data={viewData} />;
|
||||
return <LeaderboardsTemplate viewData={viewData} />;
|
||||
}
|
||||
Reference in New Issue
Block a user