diff --git a/PadelClub/ViewModel/MatchScheduler.swift b/PadelClub/ViewModel/MatchScheduler.swift index b8f7f0a..7a06ecf 100644 --- a/PadelClub/ViewModel/MatchScheduler.swift +++ b/PadelClub/ViewModel/MatchScheduler.swift @@ -494,22 +494,41 @@ class MatchScheduler { } }) - if let roundId { - if let round : Round = Store.main.findById(roundId) { - let matches = round._matches() - round.resetFromRoundAllMatchesStartDate() - flattenedMatches = matches + flattenedMatches +// if let roundId { +// if let round : Round = Store.main.findById(roundId) { +// let matches = round._matches().filter({ $0.disabled == false }).sorted(by: \.index) +// round.resetFromRoundAllMatchesStartDate() +// flattenedMatches = matches + flattenedMatches +// } +// +// } else if let matchId { +// if let match : Match = Store.main.findById(matchId) { +// if let round = match.roundObject { +// round.resetFromRoundAllMatchesStartDate(from: match) +// } +// flattenedMatches = [match] + flattenedMatches +// } +// } + + if let roundId, let matchId { + //todo + if let index = flattenedMatches.firstIndex(where: { $0.round == roundId && $0.id == matchId }) { + flattenedMatches[index...].forEach { + $0.startDate = nil + $0.removeCourt() + } } - - } else if let matchId { - if let match : Match = Store.main.findById(matchId) { - if let round = match.roundObject { - round.resetFromRoundAllMatchesStartDate(from: match) + } else if let roundId { + //todo + if let index = flattenedMatches.firstIndex(where: { $0.round == roundId }) { + flattenedMatches[index...].forEach { + $0.startDate = nil + $0.removeCourt() } - flattenedMatches = [match] + flattenedMatches } } + let usedCourts = getAvailableCourts(from: allMatches.filter({ $0.startDate?.isEarlierThan(startDate) == true && $0.startDate?.dayInt == startDate.dayInt })) let initialCourts = usedCourts.filter { (court, availableDate) in availableDate <= startDate diff --git a/PadelClub/Views/Calling/CallView.swift b/PadelClub/Views/Calling/CallView.swift index 440adfc..fb1e6c9 100644 --- a/PadelClub/Views/Calling/CallView.swift +++ b/PadelClub/Views/Calling/CallView.swift @@ -84,7 +84,7 @@ struct CallView: View { var body: some View { let callWord = teams.allSatisfy({ $0.called() }) ? "Reconvoquer" : "Convoquer" - HStack(spacing: 0.0) { + HStack { if teams.count == 1 { if let previousCallDate = teams.first?.callDate, Calendar.current.compare(previousCallDate, to: callDate, toGranularity: .minute) != .orderedSame { Text("Reconvoquer " + callDate.localizedDate() + " par") diff --git a/PadelClub/Views/Planning/Components/DateUpdateManagerView.swift b/PadelClub/Views/Planning/Components/DateUpdateManagerView.swift index debc31c..8c8d96c 100644 --- a/PadelClub/Views/Planning/Components/DateUpdateManagerView.swift +++ b/PadelClub/Views/Planning/Components/DateUpdateManagerView.swift @@ -47,12 +47,12 @@ struct DateUpdateManagerView: View { Spacer() if dateUpdated { - FooterButtonView("valider la modification") { + FooterButtonView("valider l'horaire") { validateAction() dateUpdated = false } } else if currentDate != nil { - FooterButtonView("horaire automatique") { + FooterButtonView("retirer l'horaire") { currentDate = nil } } diff --git a/PadelClub/Views/Planning/GroupStageScheduleEditorView.swift b/PadelClub/Views/Planning/GroupStageScheduleEditorView.swift index 3a3d878..3c2994a 100644 --- a/PadelClub/Views/Planning/GroupStageScheduleEditorView.swift +++ b/PadelClub/Views/Planning/GroupStageScheduleEditorView.swift @@ -12,7 +12,8 @@ struct GroupStageScheduleEditorView: View { @Bindable var groupStage: GroupStage var tournament: Tournament @State private var startDate: Date - + @State private var uuid: UUID = UUID() + init(groupStage: GroupStage, tournament: Tournament) { self.groupStage = groupStage self.tournament = tournament @@ -31,8 +32,10 @@ struct GroupStageScheduleEditorView: View { DateUpdateManagerView(startDate: $startDate, currentDate: $groupStage.startDate, duration: groupStage.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) { groupStage.startDate = startDate _save() + uuid = UUID() } } + .id(uuid) } diff --git a/PadelClub/Views/Planning/LoserRoundScheduleEditorView.swift b/PadelClub/Views/Planning/LoserRoundScheduleEditorView.swift index c34fb32..bd6e485 100644 --- a/PadelClub/Views/Planning/LoserRoundScheduleEditorView.swift +++ b/PadelClub/Views/Planning/LoserRoundScheduleEditorView.swift @@ -43,11 +43,13 @@ struct LoserRoundScheduleEditorView: View { ForEach(enabledLoserRounds.indices, id: \.self) { index in let loserRound = enabledLoserRounds[index] LoserRoundStepScheduleEditorView(stepIndex: index, round: loserRound, upperRound: upperRound) + .id(UUID()) } } .onChange(of: matchFormat) { loserRounds.forEach { round in - round.updateIfRequiredMatchFormat(matchFormat, andLoserBracket: true) + round.updateMatchFormatAndAllMatches(matchFormat) + //round.updateIfRequiredMatchFormat(matchFormat, andLoserBracket: true) } _save() } diff --git a/PadelClub/Views/Planning/LoserRoundStepScheduleEditorView.swift b/PadelClub/Views/Planning/LoserRoundStepScheduleEditorView.swift index 200504f..f775b32 100644 --- a/PadelClub/Views/Planning/LoserRoundStepScheduleEditorView.swift +++ b/PadelClub/Views/Planning/LoserRoundStepScheduleEditorView.swift @@ -61,7 +61,7 @@ struct LoserRoundStepScheduleEditorView: View { } .headerProminence(.increased) .onChange(of: matchFormat) { - round.updateIfRequiredMatchFormat(matchFormat, andLoserBracket: true) + round.updateMatchFormatAndAllMatches(matchFormat) _save() } .onChange(of: round.startDate) { diff --git a/PadelClub/Views/Planning/RoundScheduleEditorView.swift b/PadelClub/Views/Planning/RoundScheduleEditorView.swift index e827e56..bece59e 100644 --- a/PadelClub/Views/Planning/RoundScheduleEditorView.swift +++ b/PadelClub/Views/Planning/RoundScheduleEditorView.swift @@ -35,6 +35,7 @@ struct RoundScheduleEditorView: View { ForEach(round.playedMatches()) { match in MatchScheduleEditorView(match: match) + .id(UUID()) } } .navigationBarTitleDisplayMode(.inline) diff --git a/PadelClub/Views/Planning/SchedulerView.swift b/PadelClub/Views/Planning/SchedulerView.swift index 7285481..51fafb3 100644 --- a/PadelClub/Views/Planning/SchedulerView.swift +++ b/PadelClub/Views/Planning/SchedulerView.swift @@ -48,6 +48,7 @@ struct SchedulerView: View { } ForEach(tournament.groupStages()) { GroupStageScheduleEditorView(groupStage: $0, tournament: tournament) + .id(UUID()) } case .scheduleBracket: ForEach(tournament.rounds()) { round in