From 78ae6071ec78513927f07949b6989952b021f4b7 Mon Sep 17 00:00:00 2001 From: Raz Date: Sun, 28 Apr 2024 13:18:07 +0200 Subject: [PATCH] contact all --- PadelClub/Views/Calling/SendToAllView.swift | 43 +++++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/PadelClub/Views/Calling/SendToAllView.swift b/PadelClub/Views/Calling/SendToAllView.swift index 6dc1b05..cc9f9b8 100644 --- a/PadelClub/Views/Calling/SendToAllView.swift +++ b/PadelClub/Views/Calling/SendToAllView.swift @@ -19,30 +19,43 @@ struct SendToAllView: View { List(selection: $contactRecipients) { Section { Picker(selection: $contactMethod) { - Text("par sms").tag(0) - Text("par mail").tag(1) + Text("Contacter par sms").tag(0) + Text("Contacter par mail").tag(1) } label: { Text("méthode") } .labelsHidden() .pickerStyle(.inline) - } Section { + ForEach(tournament.groupStages()) { groupStage in + let teams = groupStage.teams() + if teams.isEmpty == false { + LabeledContent { + Text(teams.count.formatted() + " équipe" + teams.count.pluralSuffix) + } label: { + Text(groupStage.groupStageTitle()) + } + .tag(groupStage.id) + } + + } ForEach(tournament.rounds()) { round in - LabeledContent { - let seeds = round.seeds() - Text(round.seeds().count + " tête" + seeds.count.pluralSuffix + " de série") - } label: { - Text(round.roundTitle()) + let teams = round.teams() + if teams.isEmpty == false { + LabeledContent { + Text(teams.count.formatted() + " équipe" + teams.count.pluralSuffix) + } label: { + Text(round.roundTitle()) + } + .tag(round.id) } - .tag(round.id) } } Section { - RowButtonView("Contacter \(totalString)") { + RowButtonView("Contacter \(_totalString())") { } } @@ -56,15 +69,21 @@ struct SendToAllView: View { } func _teams() -> [TeamRegistration] { - let rounds : [Round] = contactRecipients.map { Store.main.findById($0) } + let rounds : [Round] = contactRecipients.compactMap { Store.main.findById($0) } return rounds.flatMap({ $0.teams() }) } + + func _groupStagesTeams() -> [TeamRegistration] { + let groupStages : [GroupStage] = contactRecipients.compactMap { Store.main.findById($0) } + return groupStages.flatMap({ $0.teams() }) + } func _totalString() -> String { if contactRecipients.isEmpty { return "toutes les équipes" } else { - return + let teams = _teams() + _groupStagesTeams() + return teams.count.formatted() + " équipe" + teams.count.pluralSuffix } } }