Debugging

This commit is contained in:
Eric gullickson
2025-09-22 20:58:02 -05:00
parent d4befe31d1
commit d4ca0ba8ae
4 changed files with 21 additions and 14 deletions

View File

@@ -16,9 +16,9 @@ const VehicleSelectorComponent: React.FC<Props> = ({ value, onChange, error, req
const { data: vehicles, isLoading } = useVehicles(); const { data: vehicles, isLoading } = useVehicles();
// DEBUG: Log vehicle selector renders and data changes // DEBUG: Log vehicle selector renders and data changes
console.log('[VehicleSelector] Render - value:', value, 'vehicles count:', vehicles?.length, 'isLoading:', isLoading); console.log('[VehicleSelector] Render - value:', value, 'vehicles count:', Array.isArray(vehicles) ? vehicles.length : 0, 'isLoading:', isLoading);
if (!isLoading && (vehicles?.length || 0) === 0) { if (!isLoading && (!vehicles || vehicles.length === 0)) {
return ( return (
<Box p={2} borderRadius={1} bgcolor={'background.default'}> <Box p={2} borderRadius={1} bgcolor={'background.default'}>
<Typography variant="body2" color="text.secondary"> <Typography variant="body2" color="text.secondary">
@@ -32,14 +32,14 @@ const VehicleSelectorComponent: React.FC<Props> = ({ value, onChange, error, req
<FormControl fullWidth error={!!error} required={required}> <FormControl fullWidth error={!!error} required={required}>
<InputLabel>Select Vehicle</InputLabel> <InputLabel>Select Vehicle</InputLabel>
<Select value={value || ''} onChange={(e) => onChange(e.target.value as string)} label="Select Vehicle" disabled={disabled}> <Select value={value || ''} onChange={(e) => onChange(e.target.value as string)} label="Select Vehicle" disabled={disabled}>
{vehicles?.map((v: Vehicle) => ( {vehicles && Array.isArray(vehicles) ? vehicles.map((v: Vehicle) => (
<MenuItem key={v.id} value={v.id}> <MenuItem key={v.id} value={v.id}>
<Box display="flex" alignItems="center" gap={1}> <Box display="flex" alignItems="center" gap={1}>
<DirectionsCarIcon fontSize="small" /> <DirectionsCarIcon fontSize="small" />
<Typography variant="body2">{`${v.year || ''} ${v.make || ''} ${v.model || ''}`.trim()}</Typography> <Typography variant="body2">{`${v.year || ''} ${v.make || ''} ${v.model || ''}`.trim()}</Typography>
</Box> </Box>
</MenuItem> </MenuItem>
))} )) : null}
</Select> </Select>
{error && <FormHelperText>{error}</FormHelperText>} {error && <FormHelperText>{error}</FormHelperText>}
</FormControl> </FormControl>

View File

@@ -2,6 +2,7 @@
* @ai-summary React hooks for vehicles feature * @ai-summary React hooks for vehicles feature
*/ */
import React from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { useAuth0 } from '@auth0/auth0-react'; import { useAuth0 } from '@auth0/auth0-react';
import { vehiclesApi } from '../api/vehicles.api'; import { vehiclesApi } from '../api/vehicles.api';
@@ -22,7 +23,7 @@ export const useVehicles = () => {
console.log('[useVehicles] Hook called - isAuthenticated:', isAuthenticated, 'isLoading:', isLoading); console.log('[useVehicles] Hook called - isAuthenticated:', isAuthenticated, 'isLoading:', isLoading);
return useQuery({ const query = useQuery({
queryKey: ['vehicles'], queryKey: ['vehicles'],
queryFn: () => { queryFn: () => {
console.log('[useVehicles] Query function called - fetching vehicles'); console.log('[useVehicles] Query function called - fetching vehicles');
@@ -42,13 +43,19 @@ export const useVehicles = () => {
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000), retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000),
refetchOnWindowFocus: false, // Prevent refetch on window focus refetchOnWindowFocus: false, // Prevent refetch on window focus
refetchOnMount: false, // Only fetch on mount if data is stale refetchOnMount: false, // Only fetch on mount if data is stale
onSuccess: (data) => {
console.log('[useVehicles] Query success - vehicles loaded:', data?.length);
},
onError: (error) => {
console.log('[useVehicles] Query error:', error);
},
}); });
// Handle success/error with useEffect instead of deprecated callbacks
React.useEffect(() => {
if (query.data) {
console.log('[useVehicles] Query success - vehicles loaded:', Array.isArray(query.data) ? query.data.length : 0);
}
if (query.error) {
console.log('[useVehicles] Query error:', query.error);
}
}, [query.data, query.error]);
return query;
}; };
export const useVehicle = (id: string) => { export const useVehicle = (id: string) => {

View File

@@ -45,7 +45,7 @@ export const VehiclesMobileScreen: React.FC<VehiclesMobileScreenProps> = ({
const { const {
optimisticVehicles, optimisticVehicles,
isPending: isOptimisticPending isPending: isOptimisticPending
} = useOptimisticVehicles(vehicles || []); } = useOptimisticVehicles(Array.isArray(vehicles) ? vehicles : []);
// Enhanced search with transitions // Enhanced search with transitions
const { const {

View File

@@ -29,7 +29,7 @@ export const VehiclesPage: React.FC = () => {
isPending: isOptimisticPending, isPending: isOptimisticPending,
optimisticCreateVehicle, optimisticCreateVehicle,
optimisticDeleteVehicle optimisticDeleteVehicle
} = useOptimisticVehicles(vehicles || []); } = useOptimisticVehicles(Array.isArray(vehicles) ? vehicles : []);
const { const {
searchQuery, searchQuery,
@@ -110,7 +110,7 @@ export const VehiclesPage: React.FC = () => {
</Box> </Box>
{/* Search functionality */} {/* Search functionality */}
{vehicles && vehicles.length > 0 && ( {vehicles && Array.isArray(vehicles) && vehicles.length > 0 && (
<Box sx={{ mb: 3 }}> <Box sx={{ mb: 3 }}>
<TextField <TextField
fullWidth fullWidth