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.
93 lines
3.3 KiB
93 lines
3.3 KiB
//
|
|
// DatePickingView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 17/04/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct DatePickingView: 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("Modifier la suite du programme") {
|
|
updatingInProgress = true
|
|
await validateAction()
|
|
updatingInProgress = false
|
|
confirmFollowingScheduleUpdate = false
|
|
}
|
|
}
|
|
} header: {
|
|
Text(title)
|
|
} footer: {
|
|
if confirmFollowingScheduleUpdate && updatingInProgress == false {
|
|
FooterButtonView("non, ne pas modifier la suite") {
|
|
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)
|
|
}
|
|
}
|
|
|