website refactor
This commit is contained in:
@@ -1,51 +1,27 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
import { notFound, redirect } from 'next/navigation';
|
||||
import { DriverRankingsPageQuery } from '@/lib/page-queries/page-queries/DriverRankingsPageQuery';
|
||||
import { DriverRankingsViewDataBuilder } from '@/lib/builders/view-data/DriverRankingsViewDataBuilder';
|
||||
import { DriverRankingsTemplate } from '@/templates/DriverRankingsTemplate';
|
||||
|
||||
// ============================================================================
|
||||
// MAIN PAGE COMPONENT
|
||||
// ============================================================================
|
||||
import { routes } from '@/lib/routing/RouteConfig';
|
||||
|
||||
export default async function DriverLeaderboardPage() {
|
||||
// Execute the page query
|
||||
const result = await DriverRankingsPageQuery.execute();
|
||||
|
||||
// Handle different result statuses
|
||||
switch (result.status) {
|
||||
case 'notFound':
|
||||
redirect('/404');
|
||||
case 'redirect':
|
||||
redirect(result.to);
|
||||
case 'error':
|
||||
// For now, show empty state. In a real app, you'd pass error to client
|
||||
return (
|
||||
<div className="max-w-7xl mx-auto px-4 py-12 text-center">
|
||||
<div className="text-red-400 mb-4">Error loading driver rankings</div>
|
||||
<p className="text-gray-400">Please try again later</p>
|
||||
</div>
|
||||
);
|
||||
case 'ok':
|
||||
const viewData = DriverRankingsViewDataBuilder.build(result.dto);
|
||||
const hasData = (viewData.drivers?.length ?? 0) > 0;
|
||||
|
||||
if (!hasData) {
|
||||
return (
|
||||
<DriverRankingsTemplate
|
||||
viewData={{
|
||||
drivers: [],
|
||||
podium: [],
|
||||
searchQuery: '',
|
||||
selectedSkill: 'all',
|
||||
sortBy: 'rank',
|
||||
showFilters: false,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<DriverRankingsTemplate viewData={viewData} />
|
||||
);
|
||||
|
||||
if (result.isErr()) {
|
||||
const error = result.getError();
|
||||
|
||||
// Handle different error types
|
||||
if (error === 'notFound') {
|
||||
notFound();
|
||||
} else if (error === 'redirect') {
|
||||
redirect(routes.public.home);
|
||||
} else {
|
||||
// serverError, networkError, unknown, validationError, unauthorized
|
||||
console.error('Driver rankings error:', error);
|
||||
notFound();
|
||||
}
|
||||
}
|
||||
|
||||
// Success
|
||||
const viewData = result.unwrap();
|
||||
return <DriverRankingsTemplate viewData={viewData} />;
|
||||
}
|
||||
Reference in New Issue
Block a user