fix summon stuff

multistore
Razmig Sarkissian 1 year ago
parent dc3815829d
commit 66468d2a56
  1. 13
      PadelClub/Data/Match.swift
  2. 42
      PadelClub/Views/Calling/CallMessageCustomizationView.swift
  3. 27
      PadelClub/Views/Calling/CallSettingsView.swift
  4. 10
      PadelClub/Views/Calling/SendToAllView.swift
  5. 134
      PadelClub/Views/Match/MatchDetailView.swift

@ -168,6 +168,19 @@ class Match: ModelObject, Storable {
servingTeamId = nil 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) { func teamWillBeWalkOut(_ team: TeamRegistration) {
resetMatch() resetMatch()
let previousScores = teamScores.filter({ $0.luckyLoser != nil }) let previousScores = teamScores.filter({ $0.luckyLoser != nil })

@ -24,6 +24,8 @@ struct CallMessageCustomizationView: View {
@State private var customCallMessageSignature: String = "" @State private var customCallMessageSignature: String = ""
@State private var summonsAvailablePaymentMethods: String = "" @State private var summonsAvailablePaymentMethods: String = ""
var columns: [GridItem] = Array(repeating: .init(.flexible()), count: 3)
init(tournament: Tournament) { init(tournament: Tournament) {
self.tournament = tournament self.tournament = tournament
_customCallMessageBody = State(wrappedValue: DataStore.shared.user.summonsMessageBody ?? (DataStore.shared.user.summonsUseFullCustomMessage ? "" : ContactType.defaultCustomMessage)) _customCallMessageBody = State(wrappedValue: DataStore.shared.user.summonsMessageBody ?? (DataStore.shared.user.summonsUseFullCustomMessage ? "" : ContactType.defaultCustomMessage))
@ -73,6 +75,16 @@ struct CallMessageCustomizationView: View {
} footer: { } footer: {
HStack { HStack {
Spacer() Spacer()
FooterButtonView("effacer") {
customCallMessageSignature = ""
_save()
}
Divider()
FooterButtonView("défaut") {
customCallMessageSignature = DataStore.shared.user.defaultSignature()
_save()
}
Divider()
FooterButtonView("éditer") { FooterButtonView("éditer") {
focusedField = .signature focusedField = .signature
} }
@ -142,16 +154,22 @@ struct CallMessageCustomizationView: View {
if user.summonsUseFullCustomMessage == false { if user.summonsUseFullCustomMessage == false {
HStack { HStack {
Spacer() Spacer()
FooterButtonView("éditer") { FooterButtonView("effacer") {
focusedField = .body customCallMessageBody = ""
_save()
} }
Divider()
FooterButtonView("défaut") {
customCallMessageBody = ContactType.defaultCustomMessage
_save()
} }
Divider()
FooterButtonView("éditer") {
focusedField = .body
} }
} }
} else {
if user.summonsUseFullCustomMessage { LazyVGrid(columns: columns, spacing: 0) {
Section {
LazyHStack {
FooterButtonView("#titre") { FooterButtonView("#titre") {
customCallMessageBody.append("#titre") customCallMessageBody.append("#titre")
focusedField = .body focusedField = .body
@ -181,8 +199,6 @@ struct CallMessageCustomizationView: View {
focusedField = .body focusedField = .body
} }
} }
} header: {
Text("Utilisez ces balises")
} }
} }
} }
@ -275,6 +291,16 @@ struct CallMessageCustomizationView: View {
} footer: { } footer: {
HStack { HStack {
Spacer() Spacer()
FooterButtonView("effacer") {
summonsAvailablePaymentMethods = ""
_save()
}
Divider()
FooterButtonView("défaut") {
summonsAvailablePaymentMethods = ContactType.defaultAvailablePaymentMethods
_save()
}
Divider()
FooterButtonView("éditer") { FooterButtonView("éditer") {
focusedField = .paymentMethods focusedField = .paymentMethods
} }

@ -6,11 +6,13 @@
// //
import SwiftUI import SwiftUI
import LeStorage
struct CallSettingsView: View { struct CallSettingsView: View {
@EnvironmentObject var dataStore: DataStore @EnvironmentObject var dataStore: DataStore
@Environment(Tournament.self) var tournament: Tournament @Environment(Tournament.self) var tournament: Tournament
@State private var showSendToAllView: Bool = false @State private var showSendToAllView: Bool = false
@State private var addLink: Bool = false
var body: some View { var body: some View {
List { 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 { Section {
RowButtonView("Annuler toutes les convocations", role: .destructive) { RowButtonView("Annuler toutes les convocations", role: .destructive) {
let teams = tournament.unsortedTeams() let teams = tournament.unsortedTeams()
@ -48,9 +72,10 @@ struct CallSettingsView: View {
try? dataStore.teamRegistrations.addOrUpdate(contentOfs: teams) try? dataStore.teamRegistrations.addOrUpdate(contentOfs: teams)
} }
} }
#endif
} }
.sheet(isPresented: $showSendToAllView) { .sheet(isPresented: $showSendToAllView) {
SendToAllView() SendToAllView(addLink: addLink)
.tint(.master) .tint(.master)
} }
} }

@ -16,7 +16,7 @@ struct SendToAllView: View {
@State private var contactMethod: Int = 1 @State private var contactMethod: Int = 1
@State private var contactRecipients: Set<String> = Set() @State private var contactRecipients: Set<String> = Set()
@State private var sentError: ContactManagerError? = nil @State private var sentError: ContactManagerError? = nil
let addLink: Bool
@State var cannotPayForTournament: Bool = false @State var cannotPayForTournament: Bool = false
var messageSentFailed: Binding<Bool> { var messageSentFailed: Binding<Bool> {
@ -72,16 +72,16 @@ struct SendToAllView: View {
Section { Section {
RowButtonView("Contacter \(_totalString())") { RowButtonView("Contacter \(_totalString())") {
if contactMethod == 0 { 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 { } 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)) .environment(\.editMode, Binding.constant(EditMode.active))
.headerProminence(.increased) .headerProminence(.increased)
.navigationTitle("Réglages") .navigationTitle("Préparation")
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.toolbarBackground(.visible, for: .navigationBar) .toolbarBackground(.visible, for: .navigationBar)
.alert("Un problème est survenu", isPresented: messageSentFailed) { .alert("Un problème est survenu", isPresented: messageSentFailed) {
@ -169,5 +169,5 @@ struct SendToAllView: View {
} }
#Preview { #Preview {
SendToAllView() SendToAllView(addLink: true)
} }

@ -281,70 +281,37 @@ struct MatchDetailView: View {
} }
.tint(.master) .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 { Button(role: .destructive) {
// if match.isBroadcasted() { match.resetScores()
// match.refreshBroadcast() save()
// } } label: {
// } Text("Supprimer les scores")
// .toolbar { }
// ToolbarItem(placement: .topBarTrailing) {
// Menu { } label: {
// Button { LabelOptions()
// 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")
// }
// }
// }
.navigationTitle(match.matchTitle()) .navigationTitle(match.matchTitle())
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.toolbarBackground(.visible, for: .navigationBar) .toolbarBackground(.visible, for: .navigationBar)
@ -365,8 +332,6 @@ struct MatchDetailView: View {
@ViewBuilder @ViewBuilder
var menuView: some View { var menuView: some View {
broadcastView
if match.hasStarted() { if match.hasStarted() {
Section { Section {
editionView editionView
@ -455,23 +420,10 @@ struct MatchDetailView: View {
} }
} }
// if match.canBroadcast() == true {
// Picker(selection: $broadcasted) {
// Text("Oui").tag(true)
// Text("Non").tag(false)
// } label: {
// Text("Diffuser automatiquement")
// }
// }
RowButtonView("Valider") { RowButtonView("Valider") {
match.validateMatch(fromStartDate: startDateSetup == .now ? Date() : startDate, toEndDate: endDate, fieldSetup: fieldSetup) match.validateMatch(fromStartDate: startDateSetup == .now ? Date() : startDate, toEndDate: endDate, fieldSetup: fieldSetup)
if broadcasted {
broadcastAndSave()
} else {
save() save()
}
isEditing.toggle() 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 { var shareView: some View {
NavigationLink { NavigationLink {
//EditSharingView(match: match) //EditSharingView(match: match)
@ -509,16 +445,6 @@ struct MatchDetailView: View {
private func save() { private func save() {
try? dataStore.matches.addOrUpdate(instance: match) try? dataStore.matches.addOrUpdate(instance: match)
} }
private func broadcastAndSave() {
Task {
//try? await match.broadcast()
await MainActor.run {
}
}
}
} }
#Preview { #Preview {

Loading…
Cancel
Save