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.
88 lines
3.4 KiB
88 lines
3.4 KiB
//
|
|
// UpdateSourceRankDateView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 25/03/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
import LeStorage
|
|
|
|
struct UpdateSourceRankDateView: View {
|
|
@EnvironmentObject var dataStore: DataStore
|
|
|
|
@Binding var currentRankSourceDate: Date?
|
|
@Binding var confirmUpdateRank: Bool
|
|
@State private var forceRefreshLockWeight: Bool = false
|
|
@State private var updatingRank = false
|
|
var tournament: Tournament
|
|
|
|
var tournamentStore: TournamentStore {
|
|
return self.tournament.tournamentStore
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
List {
|
|
let suffix = (tournament.inscriptionClosed() ? "Les incriptions sont closes. Les équipes ne pourront pas être déplacé entre les poules et le tableau. Seule leur position au sein des poules et du tableau, respectivement, seront modifiée." : "Les inscriptions sont toujours ouvertes. Les équipes pourront être déplacé entre les poules et le tableau.")
|
|
|
|
Section {
|
|
Text("Vous êtes sur le point de mettre à jour les rangs des équipes." + "\n" + suffix)
|
|
}
|
|
|
|
if tournament.inscriptionClosed() {
|
|
Section {
|
|
Toggle(isOn: $forceRefreshLockWeight) {
|
|
Text("Ne pas en tenir compte")
|
|
}
|
|
}
|
|
}
|
|
|
|
RowButtonView("Valider") {
|
|
updatingRank = true
|
|
Task {
|
|
do {
|
|
try await tournament.updateRank(to: currentRankSourceDate, forceRefreshLockWeight: forceRefreshLockWeight, providedSources: nil)
|
|
try dataStore.tournaments.addOrUpdate(instance: tournament)
|
|
} catch {
|
|
Logger.error(error)
|
|
}
|
|
updatingRank = false
|
|
confirmUpdateRank = false
|
|
}
|
|
}.disabled(updatingRank)
|
|
|
|
if updatingRank {
|
|
Section {
|
|
let message = currentRankSourceDate == nil ? "Mise à jour des classements" : "Mise à jour des classements provenant de \(currentRankSourceDate!.monthYearFormatted) pour tous les joueurs."
|
|
ContentUnavailableView("Mise à jour", systemImage: "exclamationmark.triangle", description: Text(message))
|
|
}
|
|
|
|
Section {
|
|
HStack {
|
|
Spacer()
|
|
ProgressView()
|
|
Spacer()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle("Attention")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .topBarLeading) {
|
|
Button(role: .cancel) {
|
|
confirmUpdateRank = false
|
|
} label: {
|
|
Text("Annuler")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.interactiveDismissDisabled(updatingRank)
|
|
}
|
|
}
|
|
|
|
//#Preview {
|
|
// UpdateSourceRankDateView(currentRankSourceDate: .constant(Date()), confirmUpdateRank: .constant(true), tournament: Tournament.mock())
|
|
//}
|
|
|