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