fix courtIndex not save

sync2
Raz 1 year ago
parent be4ee15485
commit c089e05c1a
  1. 11
      PadelClub/Data/Match.swift
  2. 12
      PadelClub/Views/Match/MatchDetailView.swift

@ -993,5 +993,16 @@ enum MatchFieldSetup: Hashable, Identifiable {
// case firstAvailable
case field(Int)
var courtIndex: Int? {
switch self {
case .random:
return nil
case .fullRandom:
return nil
case .field(let int):
return int
}
}
var id: Int { hashValue }
}

@ -478,6 +478,14 @@ struct MatchDetailView: View {
} label: {
Text("Terrain")
}
.onChange(of: fieldSetup) {
if let courtIndex = fieldSetup.courtIndex {
match.setCourt(courtIndex)
} else {
match.removeCourt()
}
_saveMatch()
}
RowButtonView("Valider") {
match.validateMatch(fromStartDate: startDateSetup == .now ? Date() : startDate, toEndDate: endDate, fieldSetup: fieldSetup)
@ -540,6 +548,10 @@ struct MatchDetailView: View {
}
}
_saveMatch()
}
private func _saveMatch() {
do {
try tournamentStore.matches.addOrUpdate(instance: match)
} catch {

Loading…
Cancel
Save