前台競賽功能修復
This commit is contained in:
@@ -231,3 +231,7 @@ import { DatabaseMonitor } from '@/components/admin/database-monitor';
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1997,12 +1997,13 @@ export function CompetitionManagement() {
|
|||||||
if (!competition) return { completed: 0, total: 0, percentage: 0 }
|
if (!competition) return { completed: 0, total: 0, percentage: 0 }
|
||||||
|
|
||||||
const participantCount = getParticipantCount(competition)
|
const participantCount = getParticipantCount(competition)
|
||||||
const totalExpected = competition.judges.length * participantCount
|
const judgesCount = competition.judges?.length || 0
|
||||||
|
const totalExpected = judgesCount * participantCount
|
||||||
const completed = judgeScores.filter((score) => {
|
const completed = judgeScores.filter((score) => {
|
||||||
const individualParticipants = competition.participatingApps || []
|
const individualParticipants = competition.participatingApps || []
|
||||||
const teamParticipants = competition.participatingTeams || []
|
const teamParticipants = competition.participatingTeams || []
|
||||||
const allParticipants = [...individualParticipants, ...teamParticipants]
|
const allParticipants = [...individualParticipants, ...teamParticipants]
|
||||||
return allParticipants.includes(score.appId) && competition.judges.includes(score.judgeId)
|
return allParticipants.includes(score.appId) && (competition.judges || []).includes(score.judgeId)
|
||||||
}).length
|
}).length
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@@ -122,21 +122,29 @@ export function CompetitionProvider({ children }: { children: ReactNode }) {
|
|||||||
const [teams, setTeams] = useState<Team[]>(mockTeams)
|
const [teams, setTeams] = useState<Team[]>(mockTeams)
|
||||||
const [proposals, setProposals] = useState<Proposal[]>(mockProposals)
|
const [proposals, setProposals] = useState<Proposal[]>(mockProposals)
|
||||||
|
|
||||||
// 載入當前競賽
|
// 載入所有競賽和當前競賽
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadCurrentCompetition = async () => {
|
const loadCompetitions = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/competitions/current')
|
// 載入所有競賽
|
||||||
const data = await response.json()
|
const competitionsResponse = await fetch('/api/competitions')
|
||||||
if (data.success && data.data) {
|
const competitionsData = await competitionsResponse.json()
|
||||||
setCurrentCompetition(data.data)
|
if (competitionsData.success && competitionsData.data) {
|
||||||
|
setCompetitions(competitionsData.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 載入當前競賽
|
||||||
|
const currentResponse = await fetch('/api/competitions/current')
|
||||||
|
const currentData = await currentResponse.json()
|
||||||
|
if (currentData.success && currentData.data) {
|
||||||
|
setCurrentCompetition(currentData.data)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('載入當前競賽失敗:', error)
|
console.error('載入競賽數據失敗:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadCurrentCompetition()
|
loadCompetitions()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Load judge scores from localStorage
|
// Load judge scores from localStorage
|
||||||
|
@@ -1275,7 +1275,26 @@ export class CompetitionService {
|
|||||||
// 獲取所有競賽
|
// 獲取所有競賽
|
||||||
static async getAllCompetitions(): Promise<Competition[]> {
|
static async getAllCompetitions(): Promise<Competition[]> {
|
||||||
const sql = 'SELECT * FROM competitions WHERE is_active = TRUE ORDER BY year DESC, month DESC';
|
const sql = 'SELECT * FROM competitions WHERE is_active = TRUE ORDER BY year DESC, month DESC';
|
||||||
return await db.query<Competition>(sql);
|
const competitions = await db.query<any>(sql);
|
||||||
|
|
||||||
|
// 轉換字段名稱以匹配前端期望的格式
|
||||||
|
return competitions.map(competition => ({
|
||||||
|
...competition,
|
||||||
|
startDate: competition.start_date,
|
||||||
|
endDate: competition.end_date,
|
||||||
|
evaluationFocus: competition.evaluation_focus,
|
||||||
|
maxTeamSize: competition.max_team_size,
|
||||||
|
isActive: competition.is_active,
|
||||||
|
createdAt: competition.created_at,
|
||||||
|
updatedAt: competition.updated_at,
|
||||||
|
// 添加默認的空數組,因為這些字段在競賽列表中不需要詳細數據
|
||||||
|
judges: [],
|
||||||
|
participatingApps: [],
|
||||||
|
participatingTeams: [],
|
||||||
|
participatingProposals: [],
|
||||||
|
rules: [],
|
||||||
|
awardTypes: []
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 獲取競賽統計
|
// 獲取競賽統計
|
||||||
|
Reference in New Issue
Block a user