mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 16:51:13 -05:00
Fix data structure and add backward compatibility
This commit is contained in:
@@ -169,11 +169,25 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
|||||||
for (const submission of submissionsWithEntities) {
|
for (const submission of submissionsWithEntities) {
|
||||||
if (submission.submission_type === 'photo' && submission.content && typeof submission.content === 'object') {
|
if (submission.submission_type === 'photo' && submission.content && typeof submission.content === 'object') {
|
||||||
const contentObj = submission.content as any;
|
const contentObj = submission.content as any;
|
||||||
const context = contentObj.context;
|
|
||||||
const rideId = contentObj.ride_id;
|
|
||||||
const parkId = contentObj.park_id;
|
|
||||||
|
|
||||||
if (context === 'ride' && rideId) {
|
// Handle both old format (context as object) and new format (context as string)
|
||||||
|
let contextType = null;
|
||||||
|
let rideId = null;
|
||||||
|
let parkId = null;
|
||||||
|
|
||||||
|
if (typeof contentObj.context === 'object' && contentObj.context !== null) {
|
||||||
|
// OLD FORMAT: context is an object like {ride_id: "...", park_id: "..."}
|
||||||
|
rideId = contentObj.context.ride_id;
|
||||||
|
parkId = contentObj.context.park_id;
|
||||||
|
contextType = rideId ? 'ride' : parkId ? 'park' : null;
|
||||||
|
} else if (typeof contentObj.context === 'string') {
|
||||||
|
// NEW FORMAT: context is a string, IDs are at top level
|
||||||
|
contextType = contentObj.context;
|
||||||
|
rideId = contentObj.ride_id;
|
||||||
|
parkId = contentObj.park_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contextType === 'ride' && rideId) {
|
||||||
const { data: rideData } = await supabase
|
const { data: rideData } = await supabase
|
||||||
.from('rides')
|
.from('rides')
|
||||||
.select(`
|
.select(`
|
||||||
@@ -189,7 +203,7 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
|||||||
(submission as any).entity_name = rideData.name;
|
(submission as any).entity_name = rideData.name;
|
||||||
(submission as any).park_name = rideData.parks?.name;
|
(submission as any).park_name = rideData.parks?.name;
|
||||||
}
|
}
|
||||||
} else if (context === 'park' && parkId) {
|
} else if (contextType === 'park' && parkId) {
|
||||||
const { data: parkData } = await supabase
|
const { data: parkData } = await supabase
|
||||||
.from('parks')
|
.from('parks')
|
||||||
.select('name')
|
.select('name')
|
||||||
@@ -852,15 +866,27 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
|||||||
<div className="mt-3 pt-3 border-t text-xs text-muted-foreground">
|
<div className="mt-3 pt-3 border-t text-xs text-muted-foreground">
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<span className="font-medium">Context:</span>
|
<span className="font-medium">Context:</span>
|
||||||
<span className="capitalize">{item.content.content.context}</span>
|
<span className="capitalize">
|
||||||
|
{typeof item.content.content.context === 'object'
|
||||||
|
? (item.content.content.context.ride_id ? 'ride' :
|
||||||
|
item.content.content.context.park_id ? 'park' : 'unknown')
|
||||||
|
: item.content.content.context}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{item.entity_name && (
|
{item.entity_name && (
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<span className="font-medium text-xs">{item.content.content.context === 'ride' ? 'Ride:' : 'Park:'}</span>
|
<span className="font-medium text-xs">
|
||||||
|
{(typeof item.content.content.context === 'object'
|
||||||
|
? (item.content.content.context.ride_id ? 'ride' : 'park')
|
||||||
|
: item.content.content.context) === 'ride' ? 'Ride:' : 'Park:'}
|
||||||
|
</span>
|
||||||
<span className="font-medium text-foreground text-base">{item.entity_name}</span>
|
<span className="font-medium text-foreground text-base">{item.entity_name}</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{item.park_name && item.content.content.context === 'ride' && (
|
{item.park_name &&
|
||||||
|
(typeof item.content.content.context === 'object'
|
||||||
|
? !!item.content.content.context.ride_id
|
||||||
|
: item.content.content.context === 'ride') && (
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<span className="font-medium text-xs">Park:</span>
|
<span className="font-medium text-xs">Park:</span>
|
||||||
<span className="font-medium text-foreground text-base">{item.park_name}</span>
|
<span className="font-medium text-foreground text-base">{item.park_name}</span>
|
||||||
|
|||||||
@@ -202,10 +202,10 @@ export function UppyPhotoSubmissionUpload({
|
|||||||
title: photo.title?.trim(),
|
title: photo.title?.trim(),
|
||||||
order: index,
|
order: index,
|
||||||
})),
|
})),
|
||||||
context: {
|
// NEW STRUCTURE: context as string, IDs at top level
|
||||||
park_id: parkId,
|
context: rideId ? 'ride' : parkId ? 'park' : undefined,
|
||||||
ride_id: rideId,
|
ride_id: rideId,
|
||||||
},
|
park_id: parkId,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user