Modernization Project Complete. Updated to latest versions of frameworks.
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
/**
|
||||
* @ai-summary Mobile-optimized vehicles screen with Material Design 3
|
||||
* @ai-summary Mobile vehicles screen with React 19 enhancements
|
||||
* @ai-context Enhanced with Suspense, optimistic updates, and transitions
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import React, { useTransition, useEffect } from 'react';
|
||||
import { Box, Typography, Grid } from '@mui/material';
|
||||
import { useVehicles } from '../hooks/useVehicles';
|
||||
import { useOptimisticVehicles } from '../hooks/useOptimisticVehicles';
|
||||
import { useVehicleSearch } from '../hooks/useVehicleTransitions';
|
||||
import { MobileVehiclesSuspense } from '../../../components/SuspenseWrappers';
|
||||
import { VehicleMobileCard } from './VehicleMobileCard';
|
||||
import { Vehicle } from '../types/vehicles.types';
|
||||
|
||||
@@ -32,6 +36,31 @@ export const VehiclesMobileScreen: React.FC<VehiclesMobileScreenProps> = ({
|
||||
onVehicleSelect
|
||||
}) => {
|
||||
const { data: vehicles, isLoading } = useVehicles();
|
||||
const [_isPending, startTransition] = useTransition();
|
||||
|
||||
// React 19 optimistic updates
|
||||
const {
|
||||
optimisticVehicles,
|
||||
isPending: isOptimisticPending
|
||||
} = useOptimisticVehicles(vehicles || []);
|
||||
|
||||
// Enhanced search with transitions
|
||||
const {
|
||||
filteredVehicles,
|
||||
updateVehicles
|
||||
} = useVehicleSearch(optimisticVehicles);
|
||||
|
||||
// Update search when optimistic vehicles change
|
||||
useEffect(() => {
|
||||
updateVehicles(optimisticVehicles);
|
||||
}, [optimisticVehicles, updateVehicles]);
|
||||
|
||||
const handleVehicleSelect = (vehicle: Vehicle) => {
|
||||
// Use transition to avoid blocking UI during navigation
|
||||
startTransition(() => {
|
||||
onVehicleSelect?.(vehicle);
|
||||
});
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
@@ -43,7 +72,7 @@ export const VehiclesMobileScreen: React.FC<VehiclesMobileScreenProps> = ({
|
||||
);
|
||||
}
|
||||
|
||||
if (!vehicles?.length) {
|
||||
if (!optimisticVehicles.length) {
|
||||
return (
|
||||
<Box sx={{ pb: 10 }}>
|
||||
<Section title="Vehicles">
|
||||
@@ -61,19 +90,21 @@ export const VehiclesMobileScreen: React.FC<VehiclesMobileScreenProps> = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<Box sx={{ pb: 10 }}>
|
||||
<Section title="Vehicles">
|
||||
<Grid container spacing={2}>
|
||||
{vehicles.map((vehicle) => (
|
||||
<Grid item xs={12} key={vehicle.id}>
|
||||
<VehicleMobileCard
|
||||
vehicle={vehicle}
|
||||
onClick={() => onVehicleSelect?.(vehicle)}
|
||||
/>
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
</Section>
|
||||
</Box>
|
||||
<MobileVehiclesSuspense>
|
||||
<Box sx={{ pb: 10 }}>
|
||||
<Section title={`Vehicles ${isOptimisticPending ? '(Updating...)' : ''}`}>
|
||||
<Grid container spacing={2}>
|
||||
{filteredVehicles.map((vehicle) => (
|
||||
<Grid item xs={12} key={vehicle.id}>
|
||||
<VehicleMobileCard
|
||||
vehicle={vehicle}
|
||||
onClick={() => handleVehicleSelect(vehicle)}
|
||||
/>
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
</Section>
|
||||
</Box>
|
||||
</MobileVehiclesSuspense>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user