You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
PadelClub/PadelClub/Views/Planning/MatchScheduleEditorView.swift

46 lines
1.3 KiB

//
// MatchScheduleEditorView.swift
// PadelClub
//
// Created by Razmig Sarkissian on 10/04/2024.
//
import SwiftUI
struct MatchScheduleEditorView: View {
@Environment(Tournament.self) var tournament: Tournament
var match: Match
@State private var startDate: Date
init(match: Match) {
self.match = match
self._startDate = State(wrappedValue: match.startDate ?? Date())
}
var body: some View {
Section {
DatePicker(selection: $startDate) {
Text(startDate.formatted(.dateTime.weekday(.wide))).font(.headline)
}
} header: {
if let round = match.roundObject {
Text(round.roundTitle() + " " + match.matchTitle())
} else {
Text(match.matchTitle())
}
} footer: {
DateUpdateManagerView(startDate: $startDate, duration: match.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
_updateSchedule()
}
}
.headerProminence(.increased)
}
private func _updateSchedule() {
MatchScheduler.shared.updateSchedule(tournament: tournament, fromRoundId: match.round, fromMatchId: match.id, startDate: startDate)
}
}
#Preview {
MatchScheduleEditorView(match: Match.mock())
}