實現完整的後台得獎資訊
This commit is contained in:
@@ -60,33 +60,95 @@ export function AwardDetailDialog({ open, onOpenChange, award }: AwardDetailDial
|
||||
const [currentPhotoIndex, setCurrentPhotoIndex] = useState(0)
|
||||
const [competitionJudges, setCompetitionJudges] = useState<any[]>([])
|
||||
|
||||
// 添加調試資訊
|
||||
console.log('🏆 AwardDetailDialog 渲染:', {
|
||||
open,
|
||||
award: award ? {
|
||||
id: award.id,
|
||||
competitionId: award.competitionId,
|
||||
awardName: award.awardName,
|
||||
hasCompetitionId: !!award.competitionId
|
||||
} : null
|
||||
});
|
||||
|
||||
const competition = competitions.find((c) => c.id === award.competitionId)
|
||||
const judgeScores = getJudgeScores(award.id)
|
||||
const appData = getAppData(award.id)
|
||||
|
||||
// 載入競賽評審團資訊
|
||||
useEffect(() => {
|
||||
console.log('🔍 useEffect 觸發:', { open, competitionId: award.competitionId, awardId: award.id });
|
||||
|
||||
if (open && award.competitionId) {
|
||||
const loadCompetitionJudges = async () => {
|
||||
const loadCompetitionJudges = async (retryCount = 0) => {
|
||||
try {
|
||||
console.log('🔍 載入競賽評審團:', award.competitionId);
|
||||
const response = await fetch(`/api/competitions/${award.competitionId}/judges`);
|
||||
console.log('🔍 載入競賽評審團:', award.competitionId, '重試次數:', retryCount);
|
||||
console.log('🏆 獎項資料:', award);
|
||||
|
||||
// 添加時間戳防止快取,並設置快取控制標頭
|
||||
const timestamp = Date.now();
|
||||
const apiUrl = `/api/competitions/${award.competitionId}/judges?t=${timestamp}`;
|
||||
console.log('🌐 API URL:', apiUrl);
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
||||
'Pragma': 'no-cache',
|
||||
'Expires': '0'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('📡 API 回應狀態:', response.status);
|
||||
console.log('📡 API 回應標頭:', Object.fromEntries(response.headers.entries()));
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error('❌ API 錯誤回應:', errorText);
|
||||
throw new Error(`HTTP error! status: ${response.status}, message: ${errorText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log('📄 API 回應資料:', JSON.stringify(data, null, 2));
|
||||
|
||||
if (data.success && data.data && data.data.judges) {
|
||||
console.log('✅ 獲取到評審團:', data.data.judges.length, '位');
|
||||
console.log('👥 評審團詳細資料:', data.data.judges);
|
||||
setCompetitionJudges(data.data.judges);
|
||||
} else {
|
||||
console.error('❌ 獲取評審團失敗:', data.message);
|
||||
setCompetitionJudges([]);
|
||||
console.error('❌ 獲取評審團失敗:', data.message || '未知錯誤');
|
||||
console.error('❌ 完整錯誤資料:', data);
|
||||
|
||||
// 如果沒有評審資料且是第一次嘗試,重試一次
|
||||
if (retryCount === 0) {
|
||||
console.log('🔄 重試載入評審團...');
|
||||
setTimeout(() => loadCompetitionJudges(1), 1000);
|
||||
} else {
|
||||
setCompetitionJudges([]);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ 載入評審團失敗:', error);
|
||||
setCompetitionJudges([]);
|
||||
|
||||
// 如果是網路錯誤且是第一次嘗試,重試一次
|
||||
if (retryCount === 0) {
|
||||
console.log('🔄 網路錯誤,重試載入評審團...');
|
||||
setTimeout(() => loadCompetitionJudges(1), 2000);
|
||||
} else {
|
||||
setCompetitionJudges([]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 清空之前的評審資料,確保重新載入
|
||||
setCompetitionJudges([]);
|
||||
loadCompetitionJudges();
|
||||
} else {
|
||||
console.log('❌ useEffect 條件不滿足:', {
|
||||
open,
|
||||
competitionId: award.competitionId,
|
||||
hasCompetitionId: !!award.competitionId
|
||||
});
|
||||
}
|
||||
}, [open, award.competitionId]);
|
||||
|
||||
|
||||
@@ -287,7 +287,7 @@ export function PopularityRankings() {
|
||||
|
||||
return (
|
||||
<Card
|
||||
key={app.id}
|
||||
key={`app-${app.id}-${index}`}
|
||||
className="hover:shadow-lg transition-all duration-300 bg-gradient-to-br from-yellow-50 to-orange-50 border border-yellow-200 flex flex-col"
|
||||
>
|
||||
<CardContent className="p-4 flex flex-col flex-1">
|
||||
@@ -454,7 +454,7 @@ export function PopularityRankings() {
|
||||
|
||||
return (
|
||||
<Card
|
||||
key={team.id}
|
||||
key={`team-${team.id}-${index}`}
|
||||
className="hover:shadow-lg transition-all duration-300 bg-gradient-to-br from-green-50 to-blue-50 border border-green-200 flex flex-col"
|
||||
>
|
||||
<CardContent className="p-4 flex flex-col flex-1">
|
||||
@@ -487,8 +487,8 @@ export function PopularityRankings() {
|
||||
<div className="mb-4 flex-1">
|
||||
<h5 className="text-sm font-medium text-gray-700 mb-2">團隊成員 ({team.members.length}人)</h5>
|
||||
<div className="space-y-1">
|
||||
{team.members.slice(0, 3).map((member: any) => (
|
||||
<div key={member.id} className="flex items-center space-x-2 text-xs">
|
||||
{team.members.slice(0, 3).map((member: any, memberIndex: number) => (
|
||||
<div key={`member-${member.id}-${memberIndex}`} className="flex items-center space-x-2 text-xs">
|
||||
<div className="w-6 h-6 bg-green-100 rounded-full flex items-center justify-center text-green-700 font-medium">
|
||||
{member.name[0]}
|
||||
</div>
|
||||
@@ -687,8 +687,8 @@ export function PopularityRankings() {
|
||||
</div>
|
||||
) : competitionJudges.length > 0 ? (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{competitionJudges.map((judge) => (
|
||||
<div key={judge.id} className="flex items-center space-x-3 p-3 bg-gray-50 rounded-lg">
|
||||
{competitionJudges.map((judge, judgeIndex) => (
|
||||
<div key={`judge-${judge.id}-${judgeIndex}`} className="flex items-center space-x-3 p-3 bg-gray-50 rounded-lg">
|
||||
<Avatar>
|
||||
<AvatarImage src={judge.avatar} />
|
||||
<AvatarFallback className="bg-purple-100 text-purple-700">{judge.name[0]}</AvatarFallback>
|
||||
@@ -697,8 +697,8 @@ export function PopularityRankings() {
|
||||
<h4 className="font-medium">{judge.name}</h4>
|
||||
<p className="text-sm text-gray-600">{judge.title}</p>
|
||||
<div className="flex flex-wrap gap-1 mt-1">
|
||||
{judge.expertise.slice(0, 2).map((skill) => (
|
||||
<Badge key={skill} variant="secondary" className="text-xs">
|
||||
{judge.expertise.slice(0, 2).map((skill, skillIndex) => (
|
||||
<Badge key={`skill-${skill}-${skillIndex}`} variant="secondary" className="text-xs">
|
||||
{skill}
|
||||
</Badge>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user