修正評審評分清單失敗問題
This commit is contained in:
@@ -126,12 +126,10 @@ export function CompetitionProvider({ children }: { children: ReactNode }) {
|
||||
useEffect(() => {
|
||||
const loadCompetitions = async () => {
|
||||
try {
|
||||
console.log('🔄 開始載入競賽數據...')
|
||||
|
||||
// 載入所有競賽
|
||||
const competitionsResponse = await fetch('/api/competitions')
|
||||
const competitionsData = await competitionsResponse.json()
|
||||
console.log('📋 競賽API回應:', competitionsData)
|
||||
|
||||
if (competitionsData.success) {
|
||||
if (competitionsData.data && competitionsData.data.length > 0) {
|
||||
@@ -141,22 +139,18 @@ export function CompetitionProvider({ children }: { children: ReactNode }) {
|
||||
judges: comp.judges || []
|
||||
}))
|
||||
setCompetitions(competitionsWithJudges)
|
||||
console.log('✅ 競賽數據載入成功:', competitionsWithJudges.length, '個競賽')
|
||||
} else {
|
||||
// 沒有競賽資料是正常情況,不報錯
|
||||
setCompetitions([])
|
||||
console.log('ℹ️ 暫無競賽數據')
|
||||
}
|
||||
} else {
|
||||
// 沒有競賽數據是正常情況,不報錯
|
||||
setCompetitions([])
|
||||
console.log('ℹ️ 暫無競賽數據')
|
||||
}
|
||||
|
||||
// 載入當前競賽
|
||||
const currentResponse = await fetch('/api/competitions/current')
|
||||
const currentData = await currentResponse.json()
|
||||
console.log('🏆 當前競賽API回應:', currentData)
|
||||
|
||||
if (currentData.success) {
|
||||
if (currentData.data) {
|
||||
@@ -166,36 +160,28 @@ export function CompetitionProvider({ children }: { children: ReactNode }) {
|
||||
judges: currentData.data.judges || []
|
||||
}
|
||||
setCurrentCompetition(currentCompetitionWithJudges)
|
||||
console.log('✅ 當前競賽載入成功:', currentCompetitionWithJudges.name)
|
||||
} else {
|
||||
// 沒有當前競賽是正常情況,不報錯
|
||||
setCurrentCompetition(null)
|
||||
console.log('ℹ️ 暫無當前競賽')
|
||||
}
|
||||
} else {
|
||||
// 沒有當前競賽是正常情況,不報錯
|
||||
setCurrentCompetition(null)
|
||||
console.log('ℹ️ 暫無當前競賽')
|
||||
}
|
||||
|
||||
// 載入評審數據
|
||||
console.log('👨⚖️ 開始載入評審數據...')
|
||||
const judgesResponse = await fetch('/api/admin/judges')
|
||||
const judgesData = await judgesResponse.json()
|
||||
console.log('評審API回應:', judgesData)
|
||||
|
||||
if (judgesData.success) {
|
||||
if (judgesData.data && judgesData.data.length > 0) {
|
||||
setJudges(judgesData.data)
|
||||
console.log('✅ 評審數據載入成功:', judgesData.data.length, '個評審')
|
||||
} else {
|
||||
setJudges([])
|
||||
console.log('ℹ️ 暫無評審數據')
|
||||
}
|
||||
} else {
|
||||
// 沒有評審數據是正常情況,不報錯
|
||||
setJudges([])
|
||||
console.log('ℹ️ 暫無評審數據')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ 載入競賽數據失敗:', error)
|
||||
@@ -283,12 +269,8 @@ export function CompetitionProvider({ children }: { children: ReactNode }) {
|
||||
}
|
||||
|
||||
const deleteJudge = (id: string) => {
|
||||
console.log('🗑️ Context deleteJudge 被調用,ID:', id)
|
||||
console.log('🗑️ 刪除前的 judges 狀態:', judges.map(j => ({ id: j.id, name: j.name, is_active: j.is_active })))
|
||||
|
||||
setJudges((prev) => {
|
||||
const filtered = prev.filter((judge) => judge.id !== id)
|
||||
console.log('🗑️ 刪除後的 judges 狀態:', filtered.map(j => ({ id: j.id, name: j.name, is_active: j.is_active })))
|
||||
return filtered
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user