From 599c942c5910dc651db20fcea6c660dff139e08c Mon Sep 17 00:00:00 2001 From: Raz Date: Mon, 10 Jun 2024 09:49:17 +0200 Subject: [PATCH] wip --- PadelClub.xcodeproj/project.pbxproj | 4 +-- PadelClub/Data/Tournament.swift | 2 +- .../Views/Components/FooterButtonView.swift | 29 ++++++++++++++++--- .../Navigation/Agenda/ActivityView.swift | 29 +++++++++++++++++++ PadelClub/Views/Subscription/Guard.swift | 2 +- .../Screen/TournamentRankView.swift | 4 +-- 6 files changed, 60 insertions(+), 10 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 252449c..c550fc5 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -1859,7 +1859,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 43; + CURRENT_PROJECT_VERSION = 45; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; @@ -1896,7 +1896,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 43; + CURRENT_PROJECT_VERSION = 45; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index dba3201..06e87bd 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -1075,7 +1075,7 @@ class Tournament : ModelObject, Storable { } let groupStages = groupStages() - let baseRank = teamCount - teamsPerGroupStage * groupStageCount + qualifiedPerGroupStage * groupStageCount + groupStageAdditionalQualified + let baseRank = teamCount - groupStageSpots() + qualifiedPerGroupStage * groupStageCount + groupStageAdditionalQualified groupStages.forEach { groupStage in let groupStageTeams = groupStage.teams(true) diff --git a/PadelClub/Views/Components/FooterButtonView.swift b/PadelClub/Views/Components/FooterButtonView.swift index 3a44a7b..a710b18 100644 --- a/PadelClub/Views/Components/FooterButtonView.swift +++ b/PadelClub/Views/Components/FooterButtonView.swift @@ -7,22 +7,43 @@ import SwiftUI +fileprivate let defaultConfirmationMessage = "Êtes-vous sûr de vouloir faire cela ?" + struct FooterButtonView: View { + var role: ButtonRole? = nil let title: String + let confirmationMessage: String let action: () -> () - - init(_ title: String, action: @escaping () -> Void) { + @State private var askConfirmation: Bool = false + + init(_ title: String, role: ButtonRole? = nil, confirmationMessage: String? = nil, action: @escaping () -> Void) { self.title = title self.action = action + self.role = role + self.confirmationMessage = confirmationMessage ?? defaultConfirmationMessage } var body: some View { - Button { - action() + Button(role: role) { + if role == .destructive { + askConfirmation = true + } else { + action() + } } label: { Text(title) .underline() } .buttonStyle(.borderless) + .confirmationDialog("Confirmation", + isPresented: $askConfirmation, + titleVisibility: .visible) { + Button("OK") { + action() + } + Button("Annuler", role: .cancel) {} + } message: { + Text(confirmationMessage) + } } } diff --git a/PadelClub/Views/Navigation/Agenda/ActivityView.swift b/PadelClub/Views/Navigation/Agenda/ActivityView.swift index bcbeaf3..33adcab 100644 --- a/PadelClub/Views/Navigation/Agenda/ActivityView.swift +++ b/PadelClub/Views/Navigation/Agenda/ActivityView.swift @@ -27,6 +27,11 @@ struct ActivityView: View { .filter({ federalDataViewModel.isTournamentValidForFilters($0) }) } + func getRunningTournaments() -> [Tournament] { + dataStore.tournaments.filter({ $0.endDate == nil }) + .filter({ federalDataViewModel.isTournamentValidForFilters($0) }) + } + var endedTournaments: [Tournament] { dataStore.tournaments.filter({ $0.endDate != nil }) .filter({ federalDataViewModel.isTournamentValidForFilters($0) }) @@ -53,6 +58,29 @@ struct ActivityView: View { } } + @ViewBuilder + private func _pasteView() -> some View { + if UIPasteboard.general.hasStrings { + // Enable string-related control... + if let string = UIPasteboard.general.string { + // use the string here + Section { + Menu("Utiliser le contenu du presse-papier") { + Section { + ForEach(getRunningTournaments()) { tournament in + Button(tournament.tournamentTitle()) { + navigation.path.append(tournament) + tournament.navigationPath = [Screen.inscription] + } + } + } header: { + Text("coller dans") + } + } + } + } + } + } var body: some View { @Bindable var navigation = navigation NavigationStack(path: $navigation.path) { @@ -62,6 +90,7 @@ struct ActivityView: View { List { switch navigation.agendaDestination! { case .activity: + _pasteView() EventListView(tournaments: runningTournaments, viewStyle: viewStyle, sortAscending: true) case .history: EventListView(tournaments: endedTournaments, viewStyle: viewStyle, sortAscending: false) diff --git a/PadelClub/Views/Subscription/Guard.swift b/PadelClub/Views/Subscription/Guard.swift index c74974e..ca95431 100644 --- a/PadelClub/Views/Subscription/Guard.swift +++ b/PadelClub/Views/Subscription/Guard.swift @@ -141,7 +141,7 @@ import LeStorage var currentPlan: StoreItem? { // #if DEBUG -// return .monthlyUnlimited + return .monthlyUnlimited // #else if let currentBestPlan = self.currentBestPlan, let plan = StoreItem(rawValue: currentBestPlan.productID) { return plan diff --git a/PadelClub/Views/Tournament/Screen/TournamentRankView.swift b/PadelClub/Views/Tournament/Screen/TournamentRankView.swift index 3aa8c4a..ab99337 100644 --- a/PadelClub/Views/Tournament/Screen/TournamentRankView.swift +++ b/PadelClub/Views/Tournament/Screen/TournamentRankView.swift @@ -36,7 +36,7 @@ struct TournamentRankView: View { Text("Classement publié") } - RowButtonView("Publier le classement", role: .destructive) { + RowButtonView(rankingPublished ? "Re-publier le classement" : "Publier le classement", role: .destructive) { rankings.keys.sorted().forEach { rank in if let rankedTeams = rankings[rank] { rankedTeams.forEach { team in @@ -48,7 +48,7 @@ struct TournamentRankView: View { _save() } } footer: { - FooterButtonView("masquer le classement") { + FooterButtonView("masquer le classement", role: .destructive) { tournament.unsortedTeams().forEach { team in team.finalRanking = nil team.pointsEarned = nil