gp stage fix

sync2
Raz 1 year ago
parent e7f2ae8ee1
commit da0ec5b231
  1. 7
      PadelClub/Data/MatchScheduler.swift
  2. 86
      PadelClub/Views/Planning/Components/DateUpdateManagerView.swift
  3. 3
      PadelClub/Views/Planning/GroupStageScheduleEditorView.swift

@ -93,9 +93,12 @@ final class MatchScheduler : ModelObject, Storable {
} }
@discardableResult @discardableResult
func updateGroupStageSchedule(tournament: Tournament) -> Date { func updateGroupStageSchedule(tournament: Tournament, specificGroupStage: GroupStage? = nil) -> Date {
let computedGroupStageChunkCount = groupStageChunkCount ?? tournament.getGroupStageChunkValue() let computedGroupStageChunkCount = groupStageChunkCount ?? tournament.getGroupStageChunkValue()
let groupStages: [GroupStage] = tournament.groupStages() var groupStages: [GroupStage] = tournament.groupStages()
if let specificGroupStage {
groupStages = [specificGroupStage]
}
let numberOfCourtsAvailablePerRotation: Int = tournament.courtCount let numberOfCourtsAvailablePerRotation: Int = tournament.courtCount
let matches = groupStages.flatMap { $0._matches() } let matches = groupStages.flatMap { $0._matches() }

@ -123,3 +123,89 @@ struct MatchFormatPickingView: View {
} }
} }
} }
struct GroupStageDatePickingView: View {
let title: String
@Binding var startDate: Date
@Binding var currentDate: Date?
var duration: Int?
var validateAction: (() async -> ())
@State private var confirmFollowingScheduleUpdate: Bool = false
@State private var updatingInProgress: Bool = false
var body: some View {
Section {
DatePicker(selection: $startDate) {
Text(startDate.formatted(.dateTime.weekday(.wide))).font(.headline)
}
if confirmFollowingScheduleUpdate {
RowButtonView("Confirmer et modifier les matchs") {
updatingInProgress = true
await validateAction()
updatingInProgress = false
confirmFollowingScheduleUpdate = false
}
}
} header: {
Text(title)
} footer: {
if confirmFollowingScheduleUpdate && updatingInProgress == false {
FooterButtonView("Modifier juste l'horaire de la poule") {
currentDate = startDate
confirmFollowingScheduleUpdate = false
}
} else {
HStack {
Menu {
Button("de 30 minutes") {
startDate = startDate.addingTimeInterval(1800)
}
Button("d'une heure") {
startDate = startDate.addingTimeInterval(3600)
}
Button("à 9h") {
startDate = startDate.atNine()
}
Button("à demain 9h") {
startDate = startDate.tomorrowAtNine
}
if let duration {
Button("à la prochaine rotation") {
startDate = startDate.addingTimeInterval(Double(duration) * 60)
}
Button("à la précédente rotation") {
startDate = startDate.addingTimeInterval(Double(duration) * -60)
}
}
} label: {
Text("décaler")
.underline()
}
.buttonStyle(.borderless)
Spacer()
if currentDate != nil {
FooterButtonView("retirer l'horaire bloqué") {
currentDate = nil
}
} else {
FooterButtonView("bloquer l'horaire") {
currentDate = startDate
}
}
}
.buttonStyle(.borderless)
}
}
.onChange(of: startDate) {
confirmFollowingScheduleUpdate = true
}
.headerProminence(.increased)
}
}

@ -27,8 +27,9 @@ struct GroupStageScheduleEditorView: View {
} }
var body: some View { var body: some View {
DatePickingView(title: groupStage.groupStageTitle(), startDate: $startDate, currentDate: $groupStage.startDate, duration: groupStage.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) { GroupStageDatePickingView(title: groupStage.groupStageTitle(), startDate: $startDate, currentDate: $groupStage.startDate, duration: groupStage.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
groupStage.startDate = startDate groupStage.startDate = startDate
tournament.matchScheduler()?.updateGroupStageSchedule(tournament: tournament, specificGroupStage: groupStage)
_save() _save()
} }
} }

Loading…
Cancel
Save