From ff0b483369e90b972c87082dbb10bfb7ac844352 Mon Sep 17 00:00:00 2001 From: Raz Date: Thu, 5 Sep 2024 12:54:03 +0200 Subject: [PATCH 1/7] fix regression --- PadelClub.xcodeproj/project.pbxproj | 8 ++++---- PadelClub/Data/Tournament.swift | 2 +- PadelClub/ViewModel/SeedInterval.swift | 8 ++++++++ PadelClub/Views/Match/MatchSetupView.swift | 2 +- PadelClub/Views/Round/RoundView.swift | 4 ++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index b938fc5..2f8d0c0 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -1960,7 +1960,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -1985,7 +1985,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.4; + MARKETING_VERSION = 1.0.5; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20"; OTHER_SWIFT_FLAGS = "-Onone"; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; @@ -2010,7 +2010,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; @@ -2033,7 +2033,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.4; + MARKETING_VERSION = 1.0.5; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20"; OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-function-bodies=5 -Xfrontend -warn-long-expression-type-checking=20 -Xfrontend -warn-long-function-bodies=50"; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 5ab4fd8..3fe8d03 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -1211,7 +1211,7 @@ defer { others.forEach { round in print("round", round.roundTitle()) if let interval = round.seedInterval() { - print("interval", interval.localizedLabel()) + print("interval", interval.localizedInterval()) let playedMatches = round.playedMatches().filter { $0.disabled == false || $0.isReady() } print("playedMatches", playedMatches.count) let winners = playedMatches.compactMap({ $0.winningTeamId }).filter({ ids.contains($0) == false }) diff --git a/PadelClub/ViewModel/SeedInterval.swift b/PadelClub/ViewModel/SeedInterval.swift index e34f620..01e7519 100644 --- a/PadelClub/ViewModel/SeedInterval.swift +++ b/PadelClub/ViewModel/SeedInterval.swift @@ -57,4 +57,12 @@ struct SeedInterval: Hashable, Comparable { return "Place \(first) à \(last)" } } + + func localizedInterval(_ displayStyle: DisplayStyle = .wide) -> String { + if dimension < 3 { + return "#\(first) / #\(last)" + } else { + return "#\(first) à #\(last)" + } + } } diff --git a/PadelClub/Views/Match/MatchSetupView.swift b/PadelClub/Views/Match/MatchSetupView.swift index 296c4b4..65a98f7 100644 --- a/PadelClub/Views/Match/MatchSetupView.swift +++ b/PadelClub/Views/Match/MatchSetupView.swift @@ -138,7 +138,7 @@ struct MatchSetupView: View { } } } label: { - Label(seedGroup.localizedLabel(), systemImage: "dice") + Label(seedGroup.localizedInterval(), systemImage: "dice") } } } label: { diff --git a/PadelClub/Views/Round/RoundView.swift b/PadelClub/Views/Round/RoundView.swift index 3891599..3e52112 100644 --- a/PadelClub/Views/Round/RoundView.swift +++ b/PadelClub/Views/Round/RoundView.swift @@ -123,7 +123,7 @@ struct RoundView: View { if availableSeeds.isEmpty == false, let availableSeedGroup { Section { - RowButtonView("Placer \(availableSeedGroup.localizedLabel())" + ((availableSeedGroup.isFixed() == false) ? " au hasard" : "")) { + RowButtonView("Placer \(availableSeedGroup.localizedInterval())" + ((availableSeedGroup.isFixed() == false) ? " au hasard" : "")) { Task { tournament.setSeeds(inRoundIndex: upperRound.round.index, inSeedGroup: availableSeedGroup) _save() @@ -137,7 +137,7 @@ struct RoundView: View { if (availableSeedGroup.isFixed() == false) { Section { - RowButtonView("Tirage au sort \(availableSeedGroup.localizedLabel()) visuel") { + RowButtonView("Tirage au sort \(availableSeedGroup.localizedInterval()) visuel") { self.selectedSeedGroup = availableSeedGroup } } footer: { From 48a5dd4cc3efcc9f544531f5df51b25fff294a76 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 6 Sep 2024 11:41:33 +0200 Subject: [PATCH 2/7] Adds patch for missing matches --- PadelClub/Utils/Patcher.swift | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/PadelClub/Utils/Patcher.swift b/PadelClub/Utils/Patcher.swift index 0b6368c..66a71ee 100644 --- a/PadelClub/Utils/Patcher.swift +++ b/PadelClub/Utils/Patcher.swift @@ -15,6 +15,7 @@ enum PatchError: Error { enum Patch: String, CaseIterable { case alexisLeDu case importDataFromDevToProd + case fixMissingMatches var id: String { return "padelclub.app.patch.\(self.rawValue)" @@ -45,6 +46,7 @@ class Patcher { switch patch { case .alexisLeDu: self._patchAlexisLeDu() case .importDataFromDevToProd: try self._importDataFromDev() + case .fixMissingMatches: self._patchMissingMatches() } } @@ -115,5 +117,48 @@ class Patcher { } } + + fileprivate static func _patchMissingMatches() { + + guard let url = StoreCenter.main.synchronizationApiURL else { + return + } + guard url == "https://padelclub.app/roads/" else { + return + } + let services = Services(url: url) + + for tournament in DataStore.shared.tournaments { + + let store = tournament.tournamentStore + let identifier = StoreIdentifier(value: tournament.id, parameterName: "tournament") + + Task { + + do { + // if nothing is online we upload the data + let matches: [Match] = try await services.get(identifier: identifier) + if matches.isEmpty { + store.matches.insertAllIntoCurrentService() + } + + let playerRegistrations: [PlayerRegistration] = try await services.get(identifier: identifier) + if playerRegistrations.isEmpty { + store.playerRegistrations.insertAllIntoCurrentService() + } + + let teamScores: [TeamScore] = try await services.get(identifier: identifier) + if teamScores.isEmpty { + store.teamScores.insertAllIntoCurrentService() + } + + } catch { + Logger.error(error) + } + + } + } + + } } From 888672cc9b85152b42fbee692b6408f5fb54c824 Mon Sep 17 00:00:00 2001 From: Raz Date: Fri, 6 Sep 2024 11:34:42 +0200 Subject: [PATCH 3/7] v1.0.6 (cherry picked from commit 0860fb5bcace0cf042f25f26caf14cf3d9bac648) --- PadelClub/Data/TeamRegistration.swift | 8 +++ PadelClub/Data/Tournament.swift | 2 +- .../Views/Calling/TeamsCallingView.swift | 49 ++++++++++++++++++- .../Views/Navigation/Umpire/UmpireView.swift | 2 +- .../Views/Shared/ImportedPlayerView.swift | 5 +- .../Shared/SelectablePlayerListView.swift | 12 ++--- PadelClub/Views/Team/EditingTeamView.swift | 16 ++++++ .../Tournament/Screen/BroadcastView.swift | 8 ++- 8 files changed, 90 insertions(+), 12 deletions(-) diff --git a/PadelClub/Data/TeamRegistration.swift b/PadelClub/Data/TeamRegistration.swift index c5db5d1..1c90fef 100644 --- a/PadelClub/Data/TeamRegistration.swift +++ b/PadelClub/Data/TeamRegistration.swift @@ -498,6 +498,14 @@ final class TeamRegistration: ModelObject, Storable { return self.tournamentStore.matches.first(where: { $0.round == initialRoundObject.id && $0.index == bracketPosition / 2 }) } + func toggleSummonConfirmation() { + if confirmationDate == nil { confirmationDate = Date() } + else { confirmationDate = nil } + } + + func didConfirmSummon() -> Bool { + confirmationDate != nil + } func tournamentObject() -> Tournament? { return Store.main.findById(tournament) diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 3fe8d03..7ad53ff 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -113,7 +113,7 @@ final class Tournament : ModelObject, Storable { self.startDate = startDate self.endDate = endDate self.creationDate = creationDate - self.isPrivate = isPrivate + self.isPrivate = Guard.main.purchasedTransactions.isEmpty self.groupStageFormat = groupStageFormat self.roundFormat = roundFormat self.loserRoundFormat = loserRoundFormat diff --git a/PadelClub/Views/Calling/TeamsCallingView.swift b/PadelClub/Views/Calling/TeamsCallingView.swift index 656351a..4575acb 100644 --- a/PadelClub/Views/Calling/TeamsCallingView.swift +++ b/PadelClub/Views/Calling/TeamsCallingView.swift @@ -6,6 +6,7 @@ // import SwiftUI +import LeStorage struct TeamsCallingView: View { @Environment(Tournament.self) var tournament: Tournament @@ -15,7 +16,23 @@ struct TeamsCallingView: View { let teams = tournament.selectedSortedTeams() Section { ForEach(teams) { team in - TeamRowView(team: team, displayCallDate: true) + Menu { + _menuOptions(team: team) + } label: { + HStack { + TeamRowView(team: team, displayCallDate: true) + if team.called() { + Spacer() + Menu { + _menuOptions(team: team) + } label: { + LabelOptions().labelStyle(.iconOnly) + } + } + } + } + .buttonStyle(.plain) + .listRowView(isActive: team.didConfirmSummon(), color: .green, hideColorVariation: true) } } } @@ -25,4 +42,34 @@ struct TeamsCallingView: View { .toolbarBackground(.visible, for: .navigationBar) } + @ViewBuilder + func _menuOptions(team: TeamRegistration) -> some View { + Button { + team.toggleSummonConfirmation() + do { + try self.tournament.tournamentStore.teamRegistrations.addOrUpdate(instance: team) + } catch { + Logger.error(error) + } + } label: { + if team.didConfirmSummon() { + Label("Confirmation reçue", systemImage: "checkmark.circle.fill").foregroundStyle(.green) + } else { + Label("Confirmation reçue", systemImage: "circle").foregroundStyle(.logoRed) + } + } + Divider() + + Button(role: .destructive) { + team.callDate = nil + do { + try self.tournament.tournamentStore.teamRegistrations.addOrUpdate(instance: team) + } catch { + Logger.error(error) + } + } label: { + Text("Effacer la date de convocation") + } + + } } diff --git a/PadelClub/Views/Navigation/Umpire/UmpireView.swift b/PadelClub/Views/Navigation/Umpire/UmpireView.swift index 945d2d7..ac79547 100644 --- a/PadelClub/Views/Navigation/Umpire/UmpireView.swift +++ b/PadelClub/Views/Navigation/Umpire/UmpireView.swift @@ -56,7 +56,7 @@ struct UmpireView: View { Section { if let currentPlayerData { //todo palmares - ImportedPlayerView(player: currentPlayerData) + ImportedPlayerView(player: currentPlayerData, showProgression: true) // NavigationLink { // // } label: { diff --git a/PadelClub/Views/Shared/ImportedPlayerView.swift b/PadelClub/Views/Shared/ImportedPlayerView.swift index 70b41e6..fd99bf8 100644 --- a/PadelClub/Views/Shared/ImportedPlayerView.swift +++ b/PadelClub/Views/Shared/ImportedPlayerView.swift @@ -11,7 +11,7 @@ struct ImportedPlayerView: View { let player: PlayerHolder var index: Int? = nil var showFemaleInMaleAssimilation: Bool = false - @State var showProgression: Bool = false + var showProgression: Bool = false var body: some View { VStack(alignment: .leading) { @@ -54,7 +54,7 @@ struct ImportedPlayerView: View { } } - if player.getProgression() != 0 { + if showProgression, player.getProgression() != 0 { HStack(alignment: .top, spacing: 2) { Text("(") Text(player.getProgression().formatted(.number.sign(strategy: .always()))) @@ -77,6 +77,7 @@ struct ImportedPlayerView: View { } } } + .lineLimit(1) if showFemaleInMaleAssimilation, let assimilatedAsMaleRank = player.getAssimilatedAsMaleRank() { HStack(alignment: .top, spacing: 2) { diff --git a/PadelClub/Views/Shared/SelectablePlayerListView.swift b/PadelClub/Views/Shared/SelectablePlayerListView.swift index b0f195d..b5d9a2d 100644 --- a/PadelClub/Views/Shared/SelectablePlayerListView.swift +++ b/PadelClub/Views/Shared/SelectablePlayerListView.swift @@ -364,7 +364,7 @@ struct MySearchView: View { let array = Array(searchViewModel.selectedPlayers) Section { ForEach(array) { player in - ImportedPlayerView(player: player, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation) + ImportedPlayerView(player: player, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation, showProgression: true) } .onDelete { indexSet in for index in indexSet { @@ -379,7 +379,7 @@ struct MySearchView: View { } else { Section { ForEach(players, id: \.self) { player in - ImportedPlayerView(player: player, index: nil, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation) + ImportedPlayerView(player: player, index: nil, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation, showProgression: true) } } header: { if players.isEmpty == false { @@ -398,7 +398,7 @@ struct MySearchView: View { Button { searchViewModel.selectedPlayers.insert(player) } label: { - ImportedPlayerView(player: player, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation) + ImportedPlayerView(player: player, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation, showProgression: true) } .buttonStyle(.plain) } @@ -412,7 +412,7 @@ struct MySearchView: View { Section { ForEach(players.indices, id: \.self) { index in let player = players[index] - ImportedPlayerView(player: player, index: searchViewModel.showIndex() ? (index + 1) : nil, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation) + ImportedPlayerView(player: player, index: searchViewModel.showIndex() ? (index + 1) : nil, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation, showProgression: true) } } header: { if players.isEmpty == false { @@ -429,13 +429,13 @@ struct MySearchView: View { Button { searchViewModel.selectedPlayers.insert(player) } label: { - ImportedPlayerView(player: player, index: searchViewModel.showIndex() ? (index + 1) : nil, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation) + ImportedPlayerView(player: player, index: searchViewModel.showIndex() ? (index + 1) : nil, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation, showProgression: true) .contentShape(Rectangle()) } .frame(maxWidth: .infinity) .buttonStyle(.plain) } else { - ImportedPlayerView(player: player, index: searchViewModel.showIndex() ? (index + 1) : nil, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation) + ImportedPlayerView(player: player, index: searchViewModel.showIndex() ? (index + 1) : nil, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation, showProgression: true) } } } header: { diff --git a/PadelClub/Views/Team/EditingTeamView.swift b/PadelClub/Views/Team/EditingTeamView.swift index 492822e..d3ac838 100644 --- a/PadelClub/Views/Team/EditingTeamView.swift +++ b/PadelClub/Views/Team/EditingTeamView.swift @@ -76,6 +76,22 @@ struct EditingTeamView: View { } label: { Text("Convocation") } + + Button { + team.toggleSummonConfirmation() + do { + try self.tournament.tournamentStore.teamRegistrations.addOrUpdate(instance: team) + } catch { + Logger.error(error) + } + } label: { + if team.didConfirmSummon() { + Label("Confirmation reçue", systemImage: "checkmark.circle.fill").foregroundStyle(.green) + } else { + Label("Confirmation reçue", systemImage: "circle").foregroundStyle(.logoRed) + } + } + } else { Text("Cette équipe n'a pas été convoquée") } diff --git a/PadelClub/Views/Tournament/Screen/BroadcastView.swift b/PadelClub/Views/Tournament/Screen/BroadcastView.swift index 54648cc..573f093 100644 --- a/PadelClub/Views/Tournament/Screen/BroadcastView.swift +++ b/PadelClub/Views/Tournament/Screen/BroadcastView.swift @@ -108,9 +108,15 @@ struct BroadcastView: View { Section { Toggle(isOn: $tournament.isPrivate) { Text("Tournoi privé") + if (tournament.isPrivate && Guard.main.purchasedTransactions.isEmpty) { + Text("Vous devez disposer d'une offre pour rendre publique ce tournoi.") + .foregroundStyle(.logoRed) + } } + .disabled((tournament.isPrivate && Guard.main.purchasedTransactions.isEmpty)) } footer: { - let footerString = "Le tournoi sera masqué sur le site [Padel Club](\(URLs.main.rawValue))" + let verb : String = tournament.isPrivate ? "est" : "sera" + let footerString = " Le tournoi \(verb) masqué sur le site [Padel Club](\(URLs.main.rawValue))" Text(.init(footerString)) } From eec308bb8bd73e6ccbec87086f8a04329c662e30 Mon Sep 17 00:00:00 2001 From: Raz Date: Fri, 6 Sep 2024 11:41:19 +0200 Subject: [PATCH 4/7] fix debug (cherry picked from commit 143a17f5b4997b196935bda633dc12ed5f0f25b8) --- PadelClub/Views/Tournament/Screen/BroadcastView.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PadelClub/Views/Tournament/Screen/BroadcastView.swift b/PadelClub/Views/Tournament/Screen/BroadcastView.swift index 573f093..836197d 100644 --- a/PadelClub/Views/Tournament/Screen/BroadcastView.swift +++ b/PadelClub/Views/Tournament/Screen/BroadcastView.swift @@ -113,7 +113,10 @@ struct BroadcastView: View { .foregroundStyle(.logoRed) } } + #if DEBUG + #else .disabled((tournament.isPrivate && Guard.main.purchasedTransactions.isEmpty)) + #endif } footer: { let verb : String = tournament.isPrivate ? "est" : "sera" let footerString = " Le tournoi \(verb) masqué sur le site [Padel Club](\(URLs.main.rawValue))" From 29dc0bf8bf778be73445ec1bf49a4c6eec9a3880 Mon Sep 17 00:00:00 2001 From: Raz Date: Fri, 6 Sep 2024 11:45:56 +0200 Subject: [PATCH 5/7] v1.0.6 --- PadelClub.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 2f8d0c0..1ab3708 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -1985,7 +1985,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.5; + MARKETING_VERSION = 1.0.6; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20"; OTHER_SWIFT_FLAGS = "-Onone"; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; @@ -2033,7 +2033,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.5; + MARKETING_VERSION = 1.0.6; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20"; OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-function-bodies=5 -Xfrontend -warn-long-expression-type-checking=20 -Xfrontend -warn-long-function-bodies=50"; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; From ac641cfca04ce8510ce1113a9a734f0e27b67123 Mon Sep 17 00:00:00 2001 From: Raz Date: Fri, 6 Sep 2024 11:57:14 +0200 Subject: [PATCH 6/7] fix debug _disablePrivateToggle --- .../Views/Tournament/Screen/BroadcastView.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/PadelClub/Views/Tournament/Screen/BroadcastView.swift b/PadelClub/Views/Tournament/Screen/BroadcastView.swift index 836197d..ba1d37b 100644 --- a/PadelClub/Views/Tournament/Screen/BroadcastView.swift +++ b/PadelClub/Views/Tournament/Screen/BroadcastView.swift @@ -113,10 +113,7 @@ struct BroadcastView: View { .foregroundStyle(.logoRed) } } - #if DEBUG - #else - .disabled((tournament.isPrivate && Guard.main.purchasedTransactions.isEmpty)) - #endif + .disabled(_disablePrivateToggle()) } footer: { let verb : String = tournament.isPrivate ? "est" : "sera" let footerString = " Le tournoi \(verb) masqué sur le site [Padel Club](\(URLs.main.rawValue))" @@ -326,6 +323,14 @@ struct BroadcastView: View { } } + private func _disablePrivateToggle() -> Bool { + #if DEBUG + return false + #else + return (tournament.isPrivate && Guard.main.purchasedTransactions.isEmpty) + #endif + } + private func _save() { do { if [tournament.publishTeams, tournament.publishSummons, tournament.publishBrackets, tournament.publishGroupStages].anySatisfy({ $0 == true }) { From d4a40a20b6c45fbae6a5d5176afd8110cfe4d405 Mon Sep 17 00:00:00 2001 From: Raz Date: Fri, 6 Sep 2024 12:15:04 +0200 Subject: [PATCH 7/7] clean up --- PadelClub/Data/TeamRegistration.swift | 4 --- .../Views/Calling/TeamsCallingView.swift | 4 +-- PadelClub/Views/Team/EditingTeamView.swift | 30 ++++++++++--------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/PadelClub/Data/TeamRegistration.swift b/PadelClub/Data/TeamRegistration.swift index 1c90fef..58c1b62 100644 --- a/PadelClub/Data/TeamRegistration.swift +++ b/PadelClub/Data/TeamRegistration.swift @@ -503,10 +503,6 @@ final class TeamRegistration: ModelObject, Storable { else { confirmationDate = nil } } - func didConfirmSummon() -> Bool { - confirmationDate != nil - } - func tournamentObject() -> Tournament? { return Store.main.findById(tournament) } diff --git a/PadelClub/Views/Calling/TeamsCallingView.swift b/PadelClub/Views/Calling/TeamsCallingView.swift index 4575acb..86e4d23 100644 --- a/PadelClub/Views/Calling/TeamsCallingView.swift +++ b/PadelClub/Views/Calling/TeamsCallingView.swift @@ -32,7 +32,7 @@ struct TeamsCallingView: View { } } .buttonStyle(.plain) - .listRowView(isActive: team.didConfirmSummon(), color: .green, hideColorVariation: true) + .listRowView(isActive: team.confirmed(), color: .green, hideColorVariation: true) } } } @@ -52,7 +52,7 @@ struct TeamsCallingView: View { Logger.error(error) } } label: { - if team.didConfirmSummon() { + if team.confirmed() { Label("Confirmation reçue", systemImage: "checkmark.circle.fill").foregroundStyle(.green) } else { Label("Confirmation reçue", systemImage: "circle").foregroundStyle(.logoRed) diff --git a/PadelClub/Views/Team/EditingTeamView.swift b/PadelClub/Views/Team/EditingTeamView.swift index d3ac838..16eaad7 100644 --- a/PadelClub/Views/Team/EditingTeamView.swift +++ b/PadelClub/Views/Team/EditingTeamView.swift @@ -77,21 +77,10 @@ struct EditingTeamView: View { Text("Convocation") } - Button { - team.toggleSummonConfirmation() - do { - try self.tournament.tournamentStore.teamRegistrations.addOrUpdate(instance: team) - } catch { - Logger.error(error) - } - } label: { - if team.didConfirmSummon() { - Label("Confirmation reçue", systemImage: "checkmark.circle.fill").foregroundStyle(.green) - } else { - Label("Confirmation reçue", systemImage: "circle").foregroundStyle(.logoRed) - } + Toggle(isOn: confirmationReceived) { + Text("Confirmation reçue") + Text("L'équipe vous a confirmé leur convocation") } - } else { Text("Cette équipe n'a pas été convoquée") } @@ -273,6 +262,19 @@ struct EditingTeamView: View { .navigationBarTitleDisplayMode(.inline) } + private var confirmationReceived: Binding { + Binding { + team.confirmed() + } set: { confirmed in + team.confirmationDate = confirmed ? Date() : nil + do { + try tournamentStore.teamRegistrations.addOrUpdate(instance: team) + } catch { + Logger.error(error) + } + } + } + private var hasArrived: Binding { Binding { team.unsortedPlayers().allSatisfy({ $0.hasArrived })