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/Tournament/Screen/Components/UpdateSourceRankDateView.swift

94 lines
4.0 KiB

//
// UpdateSourceRankDateView.swift
// PadelClub
//
// Created by Razmig Sarkissian on 25/03/2024.
//
import SwiftUI
struct UpdateSourceRankDateView: View {
@EnvironmentObject var dataStore: DataStore
@Binding var currentRankSourceDate: Date?
@Binding var confirmUpdateRank: Bool
@State private var updatingRank = false
var tournament: Tournament
var body: some View {
NavigationStack {
List {
let suffix = (false ? "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, cela affectera leur position." + "\n" + suffix)
}
RowButtonView(title: "Valider") {
updatingRank = true
//buildMoveArray()
Task {
do {
try await tournament.updateRank(to: currentRankSourceDate)
await MainActor.run {
if tournament.state() == .build {
//manageEntriesMovement()
} else {
//save()
tournament.unsortedPlayers().forEach { player in
player.setWeight(in: tournament)
}
try? dataStore.playerRegistrations.addOrUpdate(contentOfs: tournament.unsortedPlayers())
tournament.unsortedTeams().forEach { team in
team.setWeight(from: team.players())
}
try? dataStore.teamRegistrations.addOrUpdate(contentOfs: tournament.unsortedTeams())
try? dataStore.tournaments.addOrUpdate(instance: tournament)
}
updatingRank = false
confirmUpdateRank = false
}
} catch {
}
}
}.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())
}