diff --git a/PadelClub/Data/Match.swift b/PadelClub/Data/Match.swift index 4c9bff4..62a2d40 100644 --- a/PadelClub/Data/Match.swift +++ b/PadelClub/Data/Match.swift @@ -168,6 +168,19 @@ class Match: ModelObject, Storable { servingTeamId = nil } + func resetScores() { + if hasEnded() == false { + teamScores.forEach({ $0.score = nil }) + do { + try DataStore.shared.teamScores.addOrUpdate(contentOfs: teamScores) + } catch { + Logger.error(error) + } + } else { + updateTeamScores() + } + } + func teamWillBeWalkOut(_ team: TeamRegistration) { resetMatch() let previousScores = teamScores.filter({ $0.luckyLoser != nil }) diff --git a/PadelClub/Views/Calling/CallMessageCustomizationView.swift b/PadelClub/Views/Calling/CallMessageCustomizationView.swift index d9bb26e..88386db 100644 --- a/PadelClub/Views/Calling/CallMessageCustomizationView.swift +++ b/PadelClub/Views/Calling/CallMessageCustomizationView.swift @@ -24,6 +24,8 @@ struct CallMessageCustomizationView: View { @State private var customCallMessageSignature: String = "" @State private var summonsAvailablePaymentMethods: String = "" + var columns: [GridItem] = Array(repeating: .init(.flexible()), count: 3) + init(tournament: Tournament) { self.tournament = tournament _customCallMessageBody = State(wrappedValue: DataStore.shared.user.summonsMessageBody ?? (DataStore.shared.user.summonsUseFullCustomMessage ? "" : ContactType.defaultCustomMessage)) @@ -73,6 +75,16 @@ struct CallMessageCustomizationView: View { } footer: { HStack { Spacer() + FooterButtonView("effacer") { + customCallMessageSignature = "" + _save() + } + Divider() + FooterButtonView("défaut") { + customCallMessageSignature = DataStore.shared.user.defaultSignature() + _save() + } + Divider() FooterButtonView("éditer") { focusedField = .signature } @@ -142,16 +154,22 @@ struct CallMessageCustomizationView: View { if user.summonsUseFullCustomMessage == false { HStack { Spacer() + FooterButtonView("effacer") { + customCallMessageBody = "" + _save() + } + Divider() + FooterButtonView("défaut") { + customCallMessageBody = ContactType.defaultCustomMessage + _save() + } + Divider() FooterButtonView("éditer") { focusedField = .body } } - } - } - - if user.summonsUseFullCustomMessage { - Section { - LazyHStack { + } else { + LazyVGrid(columns: columns, spacing: 0) { FooterButtonView("#titre") { customCallMessageBody.append("#titre") focusedField = .body @@ -181,8 +199,6 @@ struct CallMessageCustomizationView: View { focusedField = .body } } - } header: { - Text("Utilisez ces balises") } } } @@ -275,6 +291,16 @@ struct CallMessageCustomizationView: View { } footer: { HStack { Spacer() + FooterButtonView("effacer") { + summonsAvailablePaymentMethods = "" + _save() + } + Divider() + FooterButtonView("défaut") { + summonsAvailablePaymentMethods = ContactType.defaultAvailablePaymentMethods + _save() + } + Divider() FooterButtonView("éditer") { focusedField = .paymentMethods } diff --git a/PadelClub/Views/Calling/CallSettingsView.swift b/PadelClub/Views/Calling/CallSettingsView.swift index 64ed7f7..425bcb7 100644 --- a/PadelClub/Views/Calling/CallSettingsView.swift +++ b/PadelClub/Views/Calling/CallSettingsView.swift @@ -6,11 +6,13 @@ // import SwiftUI +import LeStorage struct CallSettingsView: View { @EnvironmentObject var dataStore: DataStore @Environment(Tournament.self) var tournament: Tournament @State private var showSendToAllView: Bool = false + @State private var addLink: Bool = false var body: some View { List { @@ -29,6 +31,28 @@ struct CallSettingsView: View { } } + Section { + RowButtonView("Envoyer le lien du tournoi") { + addLink = true + showSendToAllView = true + } + .disabled(tournament.isPrivate) + } footer: { + if tournament.isPrivate { + Button { + tournament.isPrivate = false + do { + try dataStore.tournaments.addOrUpdate(instance: tournament) + } catch { + Logger.error(error) + } + } label: { + Text(.init("Le tournoi n'est pas visible sur [Padel Club](\(URLs.main.rawValue)), ")).foregroundStyle(.logoRed) + Text("le rendre visible ?").underline().foregroundStyle(.master) + } + } + } + + #if DEBUG Section { RowButtonView("Annuler toutes les convocations", role: .destructive) { let teams = tournament.unsortedTeams() @@ -48,9 +72,10 @@ struct CallSettingsView: View { try? dataStore.teamRegistrations.addOrUpdate(contentOfs: teams) } } + #endif } .sheet(isPresented: $showSendToAllView) { - SendToAllView() + SendToAllView(addLink: addLink) .tint(.master) } } diff --git a/PadelClub/Views/Calling/SendToAllView.swift b/PadelClub/Views/Calling/SendToAllView.swift index 5ebdc71..454701a 100644 --- a/PadelClub/Views/Calling/SendToAllView.swift +++ b/PadelClub/Views/Calling/SendToAllView.swift @@ -16,7 +16,7 @@ struct SendToAllView: View { @State private var contactMethod: Int = 1 @State private var contactRecipients: Set = Set() @State private var sentError: ContactManagerError? = nil - + let addLink: Bool @State var cannotPayForTournament: Bool = false var messageSentFailed: Binding { @@ -72,16 +72,16 @@ struct SendToAllView: View { Section { RowButtonView("Contacter \(_totalString())") { if contactMethod == 0 { - contactType = .message(date: nil, recipients: _teams().flatMap { $0.unsortedPlayers() }.compactMap { $0.phoneNumber }, body: tournament.tournamentTitle(), tournamentBuild: nil) + contactType = .message(date: nil, recipients: _teams().flatMap { $0.unsortedPlayers() }.compactMap { $0.phoneNumber }, body: tournament.shareURL()?.absoluteString , tournamentBuild: nil) } else { - contactType = .mail(date: nil, recipients: tournament.umpireMail(), bccRecipients: _teams().flatMap { $0.unsortedPlayers() }.compactMap { $0.email }, body: nil, subject: tournament.tournamentTitle(), tournamentBuild: nil) + contactType = .mail(date: nil, recipients: tournament.umpireMail(), bccRecipients: _teams().flatMap { $0.unsortedPlayers() }.compactMap { $0.email }, body: tournament.shareURL()?.absoluteString, subject: tournament.tournamentTitle(), tournamentBuild: nil) } } } } .environment(\.editMode, Binding.constant(EditMode.active)) .headerProminence(.increased) - .navigationTitle("Réglages") + .navigationTitle("Préparation") .navigationBarTitleDisplayMode(.inline) .toolbarBackground(.visible, for: .navigationBar) .alert("Un problème est survenu", isPresented: messageSentFailed) { @@ -169,5 +169,5 @@ struct SendToAllView: View { } #Preview { - SendToAllView() + SendToAllView(addLink: true) } diff --git a/PadelClub/Views/Match/MatchDetailView.swift b/PadelClub/Views/Match/MatchDetailView.swift index 4e74f57..3ed5934 100644 --- a/PadelClub/Views/Match/MatchDetailView.swift +++ b/PadelClub/Views/Match/MatchDetailView.swift @@ -281,70 +281,37 @@ struct MatchDetailView: View { } .tint(.master) } + .toolbar { + ToolbarItem(placement: .topBarTrailing) { + Menu { + if match.courtIndex != nil { + Button(role: .destructive) { + match.removeCourt() + save() + } label: { + Text("Supprimer le terrain") + } + } + Button(role: .destructive) { + match.startDate = nil + match.endDate = nil + save() + } label: { + Text("Supprimer l'horaire") + } -// .refreshable { -// if match.isBroadcasted() { -// match.refreshBroadcast() -// } -// } -// .toolbar { -// ToolbarItem(placement: .topBarTrailing) { -// Menu { -// Button { -// scoreType = .live -// } label: { -// Label("Saisie Live", systemImage: "airplayaudio.circle") -// } -// -// Button { -// scoreType = .prepare -// } label: { -// Label("Préparer", systemImage: "calendar") -// } -// -// Divider() -// Menu { -// if match.fieldIndex > 0 { -// Button(role: .destructive) { -// match.currentTournament?.removeField(match.fieldIndex) -// match.fieldIndex = 0 -// match.refreshBroadcast() -// save() -// } label: { -// Label("Supprimer le terrain", systemImage: "figure.run") -// } -// } -// Button(role: .destructive) { -// match.restartMatch() -// save() -// } label: { -// Label("Supprimer l'horaire", systemImage: "xmark.circle.fill") -// } -// -// Button(role: .destructive) { -// match.resetScore() -// save() -// } label: { -// Label("Supprimer les scores", systemImage: "xmark.circle.fill") -// } -// -// if match.isFederalTournament == false && match.isFriendlyMatch == false { -// Button(role: .destructive) { -// match.resetMatch() -// save() -// } label: { -// Label("Supprimer les équipes et les scores", systemImage: "xmark.circle.fill") -// } -// } -// } label: { -// Text("Éditer") -// } -// -// } label: { -// Label("Options", systemImage: "ellipsis.circle") -// } -// } -// } + Button(role: .destructive) { + match.resetScores() + save() + } label: { + Text("Supprimer les scores") + } + + } label: { + LabelOptions() + } + } + } .navigationTitle(match.matchTitle()) .navigationBarTitleDisplayMode(.inline) .toolbarBackground(.visible, for: .navigationBar) @@ -365,8 +332,6 @@ struct MatchDetailView: View { @ViewBuilder var menuView: some View { - broadcastView - if match.hasStarted() { Section { editionView @@ -454,24 +419,11 @@ struct MatchDetailView: View { Text("Tirage au sort visuel") } } - -// if match.canBroadcast() == true { -// Picker(selection: $broadcasted) { -// Text("Oui").tag(true) -// Text("Non").tag(false) -// } label: { -// Text("Diffuser automatiquement") -// } -// } RowButtonView("Valider") { match.validateMatch(fromStartDate: startDateSetup == .now ? Date() : startDate, toEndDate: endDate, fieldSetup: fieldSetup) - if broadcasted { - broadcastAndSave() - } else { - save() - } + save() isEditing.toggle() @@ -481,22 +433,6 @@ struct MatchDetailView: View { } } - @ViewBuilder - var broadcastView: some View { - Section { -// if match.isBroadcasted() { -// RowButtonView("Arrêter de diffuser") { -// match.stopBroadcast() -// save() -// } -// } else if match.canBroadcast() == true { -// RowButtonView("Diffuser", systemImage: "airplayvideo") { -// broadcastAndSave() -// } -// } - } - } - var shareView: some View { NavigationLink { //EditSharingView(match: match) @@ -509,16 +445,6 @@ struct MatchDetailView: View { private func save() { try? dataStore.matches.addOrUpdate(instance: match) } - - private func broadcastAndSave() { - Task { - //try? await match.broadcast() - - await MainActor.run { - } - } - } - } #Preview {