mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 15:31:13 -05:00
Fix frontend JSONB references
This commit is contained in:
@@ -154,13 +154,18 @@ export function useRealtimeSubscriptions(
|
||||
const { data: submission, error } = await supabase
|
||||
.from('content_submissions')
|
||||
.select(`
|
||||
id, submission_type, status, content, created_at, user_id,
|
||||
id, submission_type, status, created_at, user_id,
|
||||
reviewed_at, reviewer_id, reviewer_notes, escalated, assigned_to, locked_until,
|
||||
submission_items (
|
||||
id,
|
||||
item_type,
|
||||
item_data,
|
||||
status
|
||||
),
|
||||
submission_metadata (
|
||||
entity_id,
|
||||
park_id,
|
||||
ride_id
|
||||
)
|
||||
`)
|
||||
.eq('id', submissionId)
|
||||
@@ -177,14 +182,18 @@ export function useRealtimeSubscriptions(
|
||||
/**
|
||||
* Resolve entity names for a submission
|
||||
*/
|
||||
const resolveEntityNames = useCallback(async (submission: { submission_type: string; content: Json }) => {
|
||||
const content = submission.content as SubmissionContent;
|
||||
let entityName = content?.name || 'Unknown';
|
||||
const resolveEntityNames = useCallback(async (submission: { submission_type: string; submission_metadata?: any[] }) => {
|
||||
// Get metadata
|
||||
const metadata = Array.isArray(submission.submission_metadata) && submission.submission_metadata.length > 0
|
||||
? submission.submission_metadata[0]
|
||||
: undefined;
|
||||
|
||||
let entityName = 'Unknown';
|
||||
let parkName: string | undefined;
|
||||
|
||||
if (submission.submission_type === 'ride' && content?.entity_id) {
|
||||
if (submission.submission_type === 'ride' && metadata?.entity_id) {
|
||||
// Try cache first
|
||||
const cachedRide = entityCache.getCached('rides', content.entity_id);
|
||||
const cachedRide = entityCache.getCached('rides', metadata.entity_id);
|
||||
if (cachedRide) {
|
||||
entityName = cachedRide.name;
|
||||
if (cachedRide.park_id) {
|
||||
@@ -195,12 +204,12 @@ export function useRealtimeSubscriptions(
|
||||
const { data: ride } = await supabase
|
||||
.from('rides')
|
||||
.select('id, name, park_id')
|
||||
.eq('id', content.entity_id)
|
||||
.eq('id', metadata.entity_id)
|
||||
.maybeSingle();
|
||||
|
||||
if (ride) {
|
||||
entityName = ride.name;
|
||||
entityCache.setCached('rides', content.entity_id, ride);
|
||||
entityCache.setCached('rides', metadata.entity_id, ride);
|
||||
|
||||
if (ride.park_id) {
|
||||
const { data: park } = await supabase
|
||||
@@ -216,36 +225,36 @@ export function useRealtimeSubscriptions(
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (submission.submission_type === 'park' && content?.entity_id) {
|
||||
const cachedPark = entityCache.getCached('parks', content.entity_id);
|
||||
} else if (submission.submission_type === 'park' && metadata?.entity_id) {
|
||||
const cachedPark = entityCache.getCached('parks', metadata.entity_id);
|
||||
if (cachedPark) {
|
||||
entityName = cachedPark.name;
|
||||
} else {
|
||||
const { data: park } = await supabase
|
||||
.from('parks')
|
||||
.select('id, name')
|
||||
.eq('id', content.entity_id)
|
||||
.eq('id', metadata.entity_id)
|
||||
.maybeSingle();
|
||||
|
||||
if (park) {
|
||||
entityName = park.name;
|
||||
entityCache.setCached('parks', content.entity_id, park);
|
||||
entityCache.setCached('parks', metadata.entity_id, park);
|
||||
}
|
||||
}
|
||||
} else if (['manufacturer', 'operator', 'designer', 'property_owner'].includes(submission.submission_type) && content?.entity_id) {
|
||||
const cachedCompany = entityCache.getCached('companies', content.entity_id);
|
||||
} else if (['manufacturer', 'operator', 'designer', 'property_owner'].includes(submission.submission_type) && metadata?.entity_id) {
|
||||
const cachedCompany = entityCache.getCached('companies', metadata.entity_id);
|
||||
if (cachedCompany) {
|
||||
entityName = cachedCompany.name;
|
||||
} else {
|
||||
const { data: company } = await supabase
|
||||
.from('companies')
|
||||
.select('id, name')
|
||||
.eq('id', content.entity_id)
|
||||
.eq('id', metadata.entity_id)
|
||||
.maybeSingle();
|
||||
|
||||
if (company) {
|
||||
entityName = company.name;
|
||||
entityCache.setCached('companies', content.entity_id, company);
|
||||
entityCache.setCached('companies', metadata.entity_id, company);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user