parent
b1db99f2a0
commit
6d28930359
@ -0,0 +1,54 @@ |
||||
// |
||||
// DateUpdateManagerView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 17/04/2024. |
||||
// |
||||
|
||||
import SwiftUI |
||||
|
||||
enum DateUpdate { |
||||
case nextRotation |
||||
case previousRotation |
||||
case tomorrowAtNine |
||||
case inMinutes(Int) |
||||
case afterRound(Round) |
||||
case afterGroupStage(GroupStage) |
||||
} |
||||
|
||||
struct DateUpdateManagerView: View { |
||||
@Binding var startDate: Date |
||||
@State private var dateUpdated: Bool = false |
||||
|
||||
var validateAction: () -> Void |
||||
|
||||
var body: some View { |
||||
HStack { |
||||
Menu { |
||||
Text("à demain 9h") |
||||
Text("à la prochaine rotation") |
||||
Text("à la précédente rotation") |
||||
} label: { |
||||
Text("décaler") |
||||
.underline() |
||||
} |
||||
Spacer() |
||||
|
||||
if dateUpdated { |
||||
Button { |
||||
validateAction() |
||||
dateUpdated = false |
||||
} label: { |
||||
Text("valider la modification") |
||||
.underline() |
||||
} |
||||
} |
||||
} |
||||
.font(.subheadline) |
||||
.buttonStyle(.borderless) |
||||
.onChange(of: startDate) { |
||||
dateUpdated = true |
||||
} |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,79 @@ |
||||
// |
||||
// LoserRoundStepScheduleEditorView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 17/04/2024. |
||||
// |
||||
|
||||
import SwiftUI |
||||
|
||||
struct LoserRoundStepScheduleEditorView: View { |
||||
@EnvironmentObject var dataStore: DataStore |
||||
@Environment(Tournament.self) var tournament: Tournament |
||||
|
||||
var round: Round |
||||
var upperRound: Round |
||||
var matches: [Match] |
||||
@State private var startDate: Date |
||||
@State private var matchFormat: MatchFormat |
||||
|
||||
init(round: Round, upperRound: Round) { |
||||
self.upperRound = upperRound |
||||
self.round = round |
||||
let _matches = upperRound.loserRounds(forRoundIndex: round.index).flatMap({ $0.playedMatches() }) |
||||
self.matches = _matches |
||||
self._startDate = State(wrappedValue: round.startDate ?? _matches.first?.startDate ?? Date()) |
||||
self._matchFormat = State(wrappedValue: round.matchFormat) |
||||
} |
||||
|
||||
var body: some View { |
||||
@Bindable var round = round |
||||
Section { |
||||
MatchFormatPickerView(headerLabel: "Format", matchFormat: $round.matchFormat) |
||||
DatePicker(selection: $startDate) { |
||||
Text(startDate.formatted(.dateTime.weekday(.wide))).font(.headline) |
||||
} |
||||
NavigationLink { |
||||
List { |
||||
ForEach(matches) { match in |
||||
if match.disabled == false { |
||||
MatchScheduleEditorView(match: match) |
||||
} |
||||
} |
||||
} |
||||
.headerProminence(.increased) |
||||
.navigationTitle(round.selectionLabel()) |
||||
.environment(tournament) |
||||
} label: { |
||||
Text("Voir tous les matchs") |
||||
} |
||||
|
||||
} header: { |
||||
Text(round.selectionLabel()) |
||||
} footer: { |
||||
DateUpdateManagerView(startDate: $startDate) { |
||||
_updateSchedule() |
||||
} |
||||
} |
||||
.headerProminence(.increased) |
||||
} |
||||
|
||||
private func _updateSchedule() { |
||||
upperRound.loserRounds(forRoundIndex: round.index).forEach({ round in |
||||
round.resetRound(updateMatchFormat: round.matchFormat) |
||||
}) |
||||
|
||||
try? dataStore.matches.addOrUpdate(contentOfs: matches) |
||||
_save() |
||||
|
||||
MatchScheduler.shared.updateSchedule(tournament: tournament, fromRoundId: round.id, fromMatchId: nil, startDate: startDate) |
||||
upperRound.loserRounds(forRoundIndex: round.index).forEach({ round in |
||||
round.startDate = startDate |
||||
}) |
||||
_save() |
||||
} |
||||
|
||||
private func _save() { |
||||
try? dataStore.rounds.addOrUpdate(contentOfs: upperRound.loserRounds(forRoundIndex: round.index)) |
||||
} |
||||
} |
||||
Loading…
Reference in new issue