diff --git a/PadelClub/Views/Planning/PlanningView.swift b/PadelClub/Views/Planning/PlanningView.swift index 62babea..66138e8 100644 --- a/PadelClub/Views/Planning/PlanningView.swift +++ b/PadelClub/Views/Planning/PlanningView.swift @@ -33,7 +33,7 @@ struct PlanningView: View { } var timeSlots: [Date: [Match]] { - Dictionary(grouping: matches) { $0.startDate ?? .distantFuture } + Dictionary(grouping: matches) { $0.plannedStartDate ?? $0.startDate ?? .distantFuture } } func days(timeSlots: [Date: [Match]]) -> [Date] { @@ -279,7 +279,7 @@ struct PlanningView: View { self.selectedFormats = Array(Set(selectedMatches.map({ match in match.matchFormat }))) - _dateToUpdate = .init(wrappedValue: selectedMatches.first?.startDate ?? Date()) + _dateToUpdate = .init(wrappedValue: selectedMatches.first?.plannedStartDate ?? selectedMatches.first?.startDate ?? Date()) } var body: some View { @@ -328,7 +328,15 @@ struct PlanningView: View { private func _updateDate() { selectedMatches.forEach { match in - match.startDate = dateToUpdate + if match.hasStarted() || match.hasEnded() { + match.plannedStartDate = dateToUpdate + } else { + let hasStarted = match.currentTournament()?.hasStarted() == true + match.startDate = dateToUpdate + if hasStarted { + match.plannedStartDate = dateToUpdate + } + } } let groupByTournaments = selectedMatches.grouped { match in @@ -501,6 +509,8 @@ struct PlanningView: View { if matchViewStyle == .feedStyle, let tournament = match.currentTournament() { Text(tournament.tournamentTitle()) } + + Text(match.startDate?.formattedAsHourMinute() ?? "--") } } }