新增得獎更新、刪除的功能
This commit is contained in:
@@ -65,6 +65,8 @@ interface CompetitionContextType {
|
||||
loadingAwards: boolean
|
||||
loadAwards: () => Promise<void>
|
||||
addAward: (award: Omit<Award, "id">) => void
|
||||
updateAward: (award: Award) => void
|
||||
deleteAward: (awardId: string) => void
|
||||
getAwardsByYear: (year: number) => Award[]
|
||||
getAwardsByMonth: (year: number, month: number) => Award[]
|
||||
getAvailableYears: () => number[]
|
||||
@@ -571,6 +573,34 @@ export function CompetitionProvider({ children }: { children: ReactNode }) {
|
||||
})
|
||||
}
|
||||
|
||||
const updateAward = (award: Award) => {
|
||||
setAwards((prev) => {
|
||||
const index = prev.findIndex((existingAward) => existingAward.id === award.id)
|
||||
if (index === -1) {
|
||||
console.log('⚠️ 找不到要更新的獎項:', award.id)
|
||||
return prev
|
||||
}
|
||||
|
||||
console.log('✅ 更新獎項:', award)
|
||||
const updated = [...prev]
|
||||
updated[index] = award
|
||||
return updated
|
||||
})
|
||||
}
|
||||
|
||||
const deleteAward = (awardId: string) => {
|
||||
setAwards((prev) => {
|
||||
const filtered = prev.filter((award) => award.id !== awardId)
|
||||
if (filtered.length === prev.length) {
|
||||
console.log('⚠️ 找不到要刪除的獎項:', awardId)
|
||||
return prev
|
||||
}
|
||||
|
||||
console.log('✅ 刪除獎項:', awardId)
|
||||
return filtered
|
||||
})
|
||||
}
|
||||
|
||||
const getAwardsByYear = (year: number): Award[] => {
|
||||
return awards.filter((award) => award.year === year)
|
||||
}
|
||||
@@ -843,6 +873,8 @@ export function CompetitionProvider({ children }: { children: ReactNode }) {
|
||||
loadingAwards,
|
||||
loadAwards,
|
||||
addAward,
|
||||
updateAward,
|
||||
deleteAward,
|
||||
getAwardsByYear,
|
||||
getAwardsByMonth,
|
||||
getAvailableYears,
|
||||
|
Reference in New Issue
Block a user