Fix: Resolve TypeScript errors

This commit is contained in:
gpt-engineer-app[bot]
2025-11-03 02:28:57 +00:00
parent f6c409fac4
commit 9e8e8719b4
14 changed files with 48 additions and 30 deletions

View File

@@ -133,7 +133,7 @@ export function useEntityCache() {
const uncachedIds = getUncachedIds(type, ids);
if (uncachedIds.length === 0) {
// All entities are cached, return them
return ids.map(id => getCached(type, id)).filter(Boolean);
return ids.map(id => getCached(type, id)).filter((item): item is EntityTypeMap[T] => item !== undefined);
}
try {

View File

@@ -316,10 +316,12 @@ export function useModerationActions(config: ModerationActionsConfig): Moderatio
});
},
onSuccess: (data) => {
toast({
title: `Content ${data.action}`,
description: `The ${data.item.type} has been ${data.action}`,
});
if (data) {
toast({
title: `Content ${data.action}`,
description: `The ${data.item.type} has been ${data.action}`,
});
}
},
onSettled: () => {
// Always refetch to ensure consistency

View File

@@ -113,12 +113,21 @@ export function useProfileCache() {
// Cache the fetched profiles
if (data) {
data.forEach((profile: CachedProfile) => {
setCached(profile.user_id, profile);
data.forEach((profile) => {
const cachedProfile: CachedProfile = {
...profile,
display_name: profile.display_name || undefined,
avatar_url: profile.avatar_url || undefined
};
setCached(profile.user_id, cachedProfile);
});
}
return data || [];
return (data || []).map(profile => ({
...profile,
display_name: profile.display_name || undefined,
avatar_url: profile.avatar_url || undefined
}));
} catch (error: unknown) {
logger.error('Failed to bulk fetch profiles:', { error: getErrorMessage(error) });
return [];

View File

@@ -64,13 +64,13 @@ export function useStatesProvinces(country?: string) {
const { data, error } = await supabase
.from('locations')
.select('state_province')
.eq('country', country)
.eq('country', country || '')
.not('state_province', 'is', null);
if (error) throw error;
const uniqueStates = Array.from(
new Set(data?.map(item => item.state_province) || [])
new Set(data?.map(item => item.state_province).filter((s): s is string => s != null) || [])
).sort();
setStatesProvinces(
@@ -153,7 +153,7 @@ export function useRideModels(manufacturerId?: string) {
const { data, error } = await supabase
.from('ride_models')
.select('id, name')
.eq('manufacturer_id', manufacturerId)
.eq('manufacturer_id', manufacturerId || '')
.order('name');
if (error) throw error;
@@ -198,7 +198,7 @@ export function useCompanyHeadquarters() {
if (error) throw error;
const uniqueHeadquarters = Array.from(
new Set(data?.map(item => item.headquarters_location) || [])
new Set(data?.map(item => item.headquarters_location).filter((hq): hq is string => hq != null) || [])
).sort();
setHeadquarters(

View File

@@ -18,7 +18,7 @@ export function useProfile(userId: string | undefined) {
// Use get_filtered_profile RPC for privacy-aware field filtering
const { data, error } = await supabase.rpc('get_filtered_profile', {
_profile_user_id: userId,
_viewer_id: viewerId
_viewer_id: viewerId || ''
});
if (error) {

View File

@@ -99,8 +99,8 @@ export function useSearch(options: UseSearchOptions = {}) {
type: 'park',
title: park.name,
subtitle: [park.location?.city, park.location?.state_province, park.location?.country].filter(Boolean).join(', '),
image: park.banner_image_url || park.card_image_url,
rating: park.average_rating,
image: park.banner_image_url || park.card_image_url || undefined,
rating: park.average_rating ?? undefined,
slug: park.slug,
data: park
});
@@ -125,8 +125,8 @@ export function useSearch(options: UseSearchOptions = {}) {
type: 'ride',
title: ride.name,
subtitle: `at ${ride.park?.name || 'Unknown Park'}`,
image: ride.image_url,
rating: ride.average_rating,
image: ride.image_url || undefined,
rating: ride.average_rating ?? undefined,
slug: ride.slug,
data: ride
});
@@ -147,7 +147,7 @@ export function useSearch(options: UseSearchOptions = {}) {
type: 'company',
title: company.name,
subtitle: company.company_type?.replace('_', ' ').replace(/\b\w/g, l => l.toUpperCase()) || 'Company',
image: company.logo_url,
image: company.logo_url || undefined,
slug: company.slug,
data: company
});

View File

@@ -29,8 +29,8 @@ export function useVersionComparison(
// Use the database function to get diff
const { data, error: rpcError } = await supabase.rpc('get_version_diff', {
p_entity_type: entityType,
p_from_version_id: fromVersionId,
p_to_version_id: toVersionId
p_from_version_id: fromVersionId || '',
p_to_version_id: toVersionId || ''
});
if (rpcError) throw rpcError;