website refactor
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useCallback } from 'react';
|
||||
import { RaceResultsTemplate } from '@/templates/RaceResultsTemplate';
|
||||
import { RaceResultsViewData } from '@/lib/view-data/races/RaceResultsViewData';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
interface Props {
|
||||
data: RaceResultsViewData;
|
||||
}
|
||||
|
||||
export default function RaceResultsPageClient({ data: viewData }: Props) {
|
||||
const router = useRouter();
|
||||
const [importing, setImporting] = useState(false);
|
||||
const [importSuccess, setImportSuccess] = useState(false);
|
||||
const [importError, setImportError] = useState<string | null>(null);
|
||||
const [showImportForm, setShowImportForm] = useState(false);
|
||||
|
||||
const handleBack = useCallback(() => {
|
||||
router.back();
|
||||
}, [router]);
|
||||
|
||||
const handleImportResults = useCallback(async () => {
|
||||
setImporting(true);
|
||||
setImportError(null);
|
||||
try {
|
||||
// Mock import
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
setImportSuccess(true);
|
||||
} catch (err) {
|
||||
setImportError('Failed to import results');
|
||||
} finally {
|
||||
setImporting(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handlePenaltyClick = useCallback(() => {
|
||||
console.log('Penalty click');
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<RaceResultsTemplate
|
||||
viewData={viewData}
|
||||
isAdmin={false}
|
||||
isLoading={false}
|
||||
error={null}
|
||||
onBack={handleBack}
|
||||
onImportResults={handleImportResults}
|
||||
onPenaltyClick={handlePenaltyClick}
|
||||
importing={importing}
|
||||
importSuccess={importSuccess}
|
||||
importError={importError}
|
||||
showImportForm={showImportForm}
|
||||
setShowImportForm={setShowImportForm}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
import { notFound } from 'next/navigation';
|
||||
import { StatefulPageWrapper } from '@/components/shared/state/StatefulPageWrapper';
|
||||
import { RaceResultsTemplate } from '@/templates/RaceResultsTemplate';
|
||||
import { RaceResultsPageQuery } from '@/lib/page-queries/races/RaceResultsPageQuery';
|
||||
import { Trophy } from 'lucide-react';
|
||||
import RaceResultsPageClient from './RaceResultsPageClient';
|
||||
|
||||
interface RaceResultsPageProps {
|
||||
params: {
|
||||
params: Promise<{
|
||||
id: string;
|
||||
};
|
||||
}>;
|
||||
}
|
||||
|
||||
export default async function RaceResultsPage({ params }: RaceResultsPageProps) {
|
||||
const raceId = params.id;
|
||||
const { id: raceId } = await params;
|
||||
|
||||
if (!raceId) {
|
||||
notFound();
|
||||
@@ -23,56 +22,18 @@ export default async function RaceResultsPage({ params }: RaceResultsPageProps)
|
||||
if (result.isErr()) {
|
||||
const error = result.getError();
|
||||
|
||||
switch (error) {
|
||||
case 'notFound':
|
||||
notFound();
|
||||
case 'redirect':
|
||||
notFound();
|
||||
default:
|
||||
// Pass error to template via StatefulPageWrapper
|
||||
return (
|
||||
<StatefulPageWrapper
|
||||
data={null}
|
||||
isLoading={false}
|
||||
error={new globalThis.Error('Failed to load race results')}
|
||||
retry={() => Promise.resolve()}
|
||||
Template={() => (
|
||||
<RaceResultsTemplate
|
||||
viewData={{
|
||||
raceTrack: '',
|
||||
raceScheduledAt: '',
|
||||
totalDrivers: 0,
|
||||
leagueName: '',
|
||||
raceSOF: null,
|
||||
results: [],
|
||||
penalties: [],
|
||||
pointsSystem: {},
|
||||
fastestLapTime: 0,
|
||||
}}
|
||||
isAdmin={false}
|
||||
isLoading={false}
|
||||
error={null}
|
||||
onBack={() => {}}
|
||||
onImportResults={() => Promise.resolve()}
|
||||
onPenaltyClick={() => {}}
|
||||
importing={false}
|
||||
importSuccess={false}
|
||||
importError={null}
|
||||
showImportForm={false}
|
||||
setShowImportForm={() => {}}
|
||||
/>
|
||||
)}
|
||||
loading={{ variant: 'skeleton', message: 'Loading race results...' }}
|
||||
errorConfig={{ variant: 'full-screen' }}
|
||||
empty={{
|
||||
icon: Trophy,
|
||||
title: 'No results available',
|
||||
description: 'Race results will appear here once the race is completed',
|
||||
action: { label: 'Back to Race', onClick: () => {} }
|
||||
}}
|
||||
/>
|
||||
);
|
||||
if (error === 'notFound') {
|
||||
notFound();
|
||||
}
|
||||
// For other errors, let StatefulPageWrapper handle it
|
||||
return (
|
||||
<StatefulPageWrapper
|
||||
data={undefined}
|
||||
Template={RaceResultsPageClient as any}
|
||||
error={new Error('Failed to load race results')}
|
||||
retry={() => Promise.resolve()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const viewData = result.unwrap();
|
||||
@@ -80,33 +41,8 @@ export default async function RaceResultsPage({ params }: RaceResultsPageProps)
|
||||
return (
|
||||
<StatefulPageWrapper
|
||||
data={viewData}
|
||||
isLoading={false}
|
||||
error={null}
|
||||
Template={RaceResultsPageClient}
|
||||
retry={() => Promise.resolve()}
|
||||
Template={() => (
|
||||
<RaceResultsTemplate
|
||||
viewData={viewData}
|
||||
isAdmin={false}
|
||||
isLoading={false}
|
||||
error={null}
|
||||
onBack={() => {}}
|
||||
onImportResults={() => Promise.resolve()}
|
||||
onPenaltyClick={() => {}}
|
||||
importing={false}
|
||||
importSuccess={false}
|
||||
importError={null}
|
||||
showImportForm={false}
|
||||
setShowImportForm={() => {}}
|
||||
/>
|
||||
)}
|
||||
loading={{ variant: 'skeleton', message: 'Loading race results...' }}
|
||||
errorConfig={{ variant: 'full-screen' }}
|
||||
empty={{
|
||||
icon: Trophy,
|
||||
title: 'No results available',
|
||||
description: 'Race results will appear here once the race is completed',
|
||||
action: { label: 'Back to Race', onClick: () => {} }
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user