mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 07:31:12 -05:00
Fix photo submission query
This commit is contained in:
@@ -18,23 +18,34 @@ export function PhotoSubmissionDisplay({ submissionId }: PhotoSubmissionDisplayP
|
||||
|
||||
const fetchPhotos = async () => {
|
||||
try {
|
||||
// Step 1: Get photo_submission_id from submission_id
|
||||
const { data: photoSubmission, error: photoSubmissionError } = await supabase
|
||||
.from('photo_submissions')
|
||||
.select('id')
|
||||
.eq('submission_id', submissionId)
|
||||
.maybeSingle();
|
||||
|
||||
if (photoSubmissionError) throw photoSubmissionError;
|
||||
|
||||
if (!photoSubmission) {
|
||||
setPhotos([]);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 2: Get photo items using photo_submission_id
|
||||
const { data, error } = await supabase
|
||||
.from('photo_submission_items')
|
||||
.select(`
|
||||
*,
|
||||
photo_submission:photo_submissions(submission_id)
|
||||
`)
|
||||
.eq('photo_submission.submission_id', submissionId)
|
||||
.select('*')
|
||||
.eq('photo_submission_id', photoSubmission.id)
|
||||
.order('order_index');
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
// Filter out any items where photo_submission is null (shouldn't happen but be safe)
|
||||
const validPhotos = (data || []).filter(item => item.photo_submission);
|
||||
setPhotos(validPhotos);
|
||||
setPhotos(data || []);
|
||||
} catch (error) {
|
||||
console.error('Error fetching photo submission items:', error);
|
||||
setPhotos([]); // Ensure photos is empty on error
|
||||
setPhotos([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user