mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 05:51:15 -05:00
Refactor: Implement complete plan
This commit is contained in:
@@ -170,7 +170,7 @@ export function useEntityCache() {
|
||||
|
||||
// Collect all entity IDs from submissions
|
||||
submissions.forEach(submission => {
|
||||
const content = submission.content as any;
|
||||
const content = submission.content;
|
||||
if (content && typeof content === 'object') {
|
||||
if (content.ride_id) rideIds.add(content.ride_id);
|
||||
if (content.park_id) parkIds.add(content.park_id);
|
||||
|
||||
44
src/hooks/useCoasterStats.ts
Normal file
44
src/hooks/useCoasterStats.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
|
||||
export interface CoasterStat {
|
||||
id: string;
|
||||
ride_id: string;
|
||||
stat_name: string;
|
||||
stat_value: number;
|
||||
unit?: string | null;
|
||||
category?: string | null;
|
||||
description?: string | null;
|
||||
display_order: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export function useCoasterStats(rideId: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: ['coaster-stats', rideId],
|
||||
queryFn: async () => {
|
||||
if (!rideId) return [];
|
||||
|
||||
const { data, error } = await (supabase as any)
|
||||
.from('ride_coaster_stats')
|
||||
.select('*')
|
||||
.eq('ride_id', rideId)
|
||||
.order('display_order');
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
return (data || []).map((stat: any) => ({
|
||||
id: stat.id,
|
||||
ride_id: stat.ride_id,
|
||||
stat_name: stat.stat_name,
|
||||
stat_value: stat.stat_value,
|
||||
unit: stat.unit || null,
|
||||
category: stat.category || null,
|
||||
description: stat.description || null,
|
||||
display_order: stat.display_order,
|
||||
created_at: stat.created_at,
|
||||
})) as CoasterStat[];
|
||||
},
|
||||
enabled: !!rideId
|
||||
});
|
||||
}
|
||||
@@ -41,8 +41,8 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
||||
const versionTable = `${entityType}_versions`;
|
||||
const entityIdCol = `${entityType}_id`;
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from(versionTable as any)
|
||||
const { data, error } = await (supabase as any)
|
||||
.from(versionTable)
|
||||
.select(`
|
||||
*,
|
||||
profiles:created_by(username, display_name, avatar_url)
|
||||
@@ -63,7 +63,7 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
||||
return;
|
||||
}
|
||||
|
||||
const versionsWithProfiles = (data as any[]).map((v: any) => ({
|
||||
const versionsWithProfiles = (data || []).map((v: any) => ({
|
||||
...v,
|
||||
profiles: v.profiles || {
|
||||
username: 'Unknown',
|
||||
|
||||
52
src/hooks/useTechnicalSpecifications.ts
Normal file
52
src/hooks/useTechnicalSpecifications.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
|
||||
export interface TechnicalSpecification {
|
||||
id: string;
|
||||
entity_type: 'ride' | 'ride_model';
|
||||
entity_id: string;
|
||||
spec_name: string;
|
||||
spec_value: string;
|
||||
spec_unit?: string | null;
|
||||
category?: string | null;
|
||||
display_order: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export function useTechnicalSpecifications(
|
||||
entityType: 'ride' | 'ride_model',
|
||||
entityId: string | undefined
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ['technical-specifications', entityType, entityId],
|
||||
queryFn: async () => {
|
||||
if (!entityId) return [];
|
||||
|
||||
const tableName = entityType === 'ride'
|
||||
? 'ride_technical_specifications'
|
||||
: 'ride_model_technical_specifications';
|
||||
const idColumn = entityType === 'ride' ? 'ride_id' : 'ride_model_id';
|
||||
|
||||
const { data, error } = await (supabase as any)
|
||||
.from(tableName)
|
||||
.select('*')
|
||||
.eq(idColumn, entityId)
|
||||
.order('display_order');
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
return (data || []).map((spec: any) => ({
|
||||
id: spec.id,
|
||||
entity_type: entityType,
|
||||
entity_id: entityId,
|
||||
spec_name: spec.spec_name,
|
||||
spec_value: spec.spec_value,
|
||||
spec_unit: spec.spec_unit || null,
|
||||
category: spec.category || null,
|
||||
display_order: spec.display_order,
|
||||
created_at: spec.created_at,
|
||||
})) as TechnicalSpecification[];
|
||||
},
|
||||
enabled: !!entityId
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user