diff --git a/components/competition/award-detail-dialog.tsx b/components/competition/award-detail-dialog.tsx index daf1521..ba6c50d 100644 --- a/components/competition/award-detail-dialog.tsx +++ b/components/competition/award-detail-dialog.tsx @@ -207,11 +207,47 @@ export function AwardDetailDialog({ open, onOpenChange, award }: AwardDetailDial } const nextPhoto = () => { - setCurrentPhotoIndex((prev) => (prev + 1) % competitionPhotos.length) + setCurrentPhotoIndex((prev) => { + // 獲取當前照片數組 + let photos = []; + if (award.photos) { + photos = award.photos; + } else if (award.photos) { + try { + photos = typeof award.photos === 'string' + ? JSON.parse(award.photos) + : award.photos; + } catch (e) { + console.warn('解析 photos JSON 失敗:', e); + photos = []; + } + } + + if (photos.length === 0) return 0; + return (prev + 1) % photos.length; + }) } const prevPhoto = () => { - setCurrentPhotoIndex((prev) => (prev - 1 + competitionPhotos.length) % competitionPhotos.length) + setCurrentPhotoIndex((prev) => { + // 獲取當前照片數組 + let photos = []; + if (award.photos) { + photos = award.photos; + } else if (award.photos) { + try { + photos = typeof award.photos === 'string' + ? JSON.parse(award.photos) + : award.photos; + } catch (e) { + console.warn('解析 photos JSON 失敗:', e); + photos = []; + } + } + + if (photos.length === 0) return 0; + return (prev - 1 + photos.length) % photos.length; + }) } const handlePreview = (report: any) => { @@ -707,23 +743,91 @@ export function AwardDetailDialog({ open, onOpenChange, award }: AwardDetailDial ) } - const renderCompetitionPhotos = () => ( - - - - - 競賽照片 - - 競賽活動精彩瞬間 - - -
- -

暫無競賽照片

-
-
-
- ) + const renderCompetitionPhotos = () => { + // 解析 photos 資料 + let photos = []; + if (award.photos) { + photos = award.photos; + } else if (award.photos) { + try { + photos = typeof award.photos === 'string' + ? JSON.parse(award.photos) + : award.photos; + } catch (e) { + console.error('解析 photos 失敗:', e); + } + } + + console.log('🖼️ 競賽照片資料:', { + hasPhotos: !!photos, + photosType: typeof photos, + photosLength: photos?.length, + photosData: photos + }); + + return ( + + + + + 競賽照片 + + 競賽活動精彩瞬間 + + + {!photos || !Array.isArray(photos) || photos.length === 0 ? ( +
+ +

暫無競賽照片

+
+ ) : ( +
+ {photos.map((photo: any, index: number) => { + console.log('📸 處理照片:', { index, photo }); + return ( +
+
{ + setCurrentPhotoIndex(index); + setShowPhotoGallery(true); + }}> + {photo.url ? ( + {photo.caption { + console.log('❌ 圖片載入失敗:', photo.url); + e.currentTarget.style.display = 'none'; + e.currentTarget.nextElementSibling?.classList.remove('hidden'); + }} + onLoad={() => { + console.log('✅ 圖片載入成功:', photo.url); + }} + /> + ) : ( +
+ 🖼️ +
+ )} +
+ 🖼️ +
+
+ {(photo.caption || photo.name) && ( +

+ {photo.caption || photo.name} +

+ )} +
+ ); + })} +
+ )} +
+
+ ); + } return ( <> @@ -766,6 +870,132 @@ export function AwardDetailDialog({ open, onOpenChange, award }: AwardDetailDial + + {/* Photo Gallery Modal */} + {showPhotoGallery && (() => { + // 解析 photos 資料 + let photos = []; + if (award.photos) { + photos = award.photos; + } else if (award.photos) { + try { + photos = typeof award.photos === 'string' + ? JSON.parse(award.photos) + : award.photos; + } catch (e) { + console.error('解析 photos 失敗:', e); + } + } + + if (!photos || !Array.isArray(photos) || photos.length === 0) { + return null; + } + + const currentPhoto = photos[isNaN(currentPhotoIndex) ? 0 : currentPhotoIndex]; + + return ( + + + + 照片畫廊 + +
+ {/* Close Button */} + + + {/* Main Photo */} +
+ {currentPhoto?.url ? ( + {currentPhoto.caption + ) : ( +
+ 🖼️ +
+ )} + + {/* Navigation Arrows */} + {photos.length > 1 && ( + <> + + + + )} + + {/* Photo Counter */} +
+ {isNaN(currentPhotoIndex) ? 1 : currentPhotoIndex + 1} / {photos.length} +
+
+ + {/* Photo Caption */} + {(currentPhoto?.caption || currentPhoto?.name) && ( +
+

+ {currentPhoto.caption || currentPhoto.name} +

+
+ )} + + {/* Thumbnail Strip */} + {photos.length > 1 && ( +
+
+ {photos.map((photo: any, index: number) => ( + + ))} +
+
+ )} +
+
+
+ ); + })()} ) } \ No newline at end of file