From 602755fe2a79c091a381f99711d534345bf747fa Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 11 Mar 2025 15:28:06 +0100 Subject: [PATCH] Improve API call execution and add developer mode --- .../Navigation/Toolbox/APICallsListView.swift | 24 +++++-- .../Navigation/Toolbox/ToolboxView.swift | 70 +++++++++++++++---- PadelClubTests/ServerDataTests.swift | 8 ++- PadelClubTests/TokenExemptionTests.swift | 8 ++- PadelClubTests/UserDataTests.swift | 29 ++++---- 5 files changed, 100 insertions(+), 39 deletions(-) diff --git a/PadelClub/Views/Navigation/Toolbox/APICallsListView.swift b/PadelClub/Views/Navigation/Toolbox/APICallsListView.swift index c99abd0..4c904d6 100644 --- a/PadelClub/Views/Navigation/Toolbox/APICallsListView.swift +++ b/PadelClub/Views/Navigation/Toolbox/APICallsListView.swift @@ -192,16 +192,26 @@ struct APICallView: View { } do { - let result = try await StoreCenter.main.execute(apiCalls: [call]) - print(result) - // Update UI on the main thread + let results = try await StoreCenter.main.execute(apiCalls: [call]) + await MainActor.run { - errorMessage = nil isLoading = false - - // Show success popover - showSuccessPopover = true + if let result = results.first { + errorMessage = result.message + showSuccessPopover = (200..<300).contains(result.status) + } else { + errorMessage = "no results" + } } + + // Update UI on the main thread +// await MainActor.run { +// errorMessage = nil +// isLoading = false +// +// // Show success popover +// showSuccessPopover = true +// } } catch { // Update UI on the main thread await MainActor.run { diff --git a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift index 439d714..3e9836c 100644 --- a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift +++ b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift @@ -15,6 +15,12 @@ struct ToolboxView: View { @Environment(NavigationViewModel.self) private var navigation: NavigationViewModel @State private var didResetApiCalls: Bool = false + @State var showDebugViews: Bool = false + + @State private var tapCount = 0 + @State private var lastTapTime: Date? = nil + private let tapTimeThreshold: TimeInterval = 1.0 + var lastDataSource: String? { dataStore.appSettings.lastDataSource } @@ -39,25 +45,21 @@ struct ToolboxView: View { .contextMenu { ShareLink(item: URLs.main.url) } - + SupportButtonView(contentIsUnavailable: false) Link(destination: URLs.appReview.url) { Text("Partagez vos impressions !") } - + Link(destination: URLs.instagram.url) { Text("Compte Instagram PadelClub.app") } } - #if DEBUG - DebugView() - #endif - - #if TESTFLIGHT - DebugView() - #endif + if showDebugViews { + DebugView() + } Section { NavigationLink { @@ -65,7 +67,7 @@ struct ToolboxView: View { } label: { Label("Rechercher un joueur", systemImage: "person.fill.viewfinder") } - + NavigationLink { RankCalculatorView() } label: { @@ -113,13 +115,13 @@ struct ToolboxView: View { didResetApiCalls = true } } - + Section { Link(destination: URLs.appDescription.url) { Text("Page de présentation de Padel Club") } } - + Section { Link(destination: URLs.privacy.url) { Text("Politique de confidentialité") @@ -136,6 +138,16 @@ struct ToolboxView: View { } } } + .onAppear { +//#if DEBUG +// self.showDebugViews = true +//#endif +// +//#if TESTFLIGHT +// self.showDebugViews = true +//#endif + + } .overlay(alignment: .bottom) { if didResetApiCalls { Label("logs effacés", systemImage: "checkmark") @@ -148,8 +160,16 @@ struct ToolboxView: View { } } } - .navigationTitle(TabDestination.toolbox.title) + .navigationBarTitleDisplayMode(.large) + // .navigationTitle(TabDestination.toolbox.title) .toolbar { + ToolbarItem(placement: .principal) { + Text(TabDestination.toolbox.title) + .font(.headline) + .onTapGesture { + _handleTitleTap() + } + } ToolbarItem(placement: .topBarLeading) { Link(destination: URLs.appStore.url) { Text("v\(PadelClubApp.appVersion)") @@ -171,6 +191,30 @@ struct ToolboxView: View { } } } + + private func _handleTitleTap() { + // Reset counter if too much time elapsed since last tap + if let lastTime = lastTapTime, Date().timeIntervalSince(lastTime) > tapTimeThreshold { + tapCount = 0 + } + + // Update tap count and time + tapCount += 1 + lastTapTime = Date() + + print("Tap count: \(tapCount)") + + // Check if we've reached 4 taps + if tapCount == 4 { + _secretFeatureActivated() + tapCount = 0 + } + } + + private func _secretFeatureActivated() { + self.showDebugViews = true + } + } //#Preview { diff --git a/PadelClubTests/ServerDataTests.swift b/PadelClubTests/ServerDataTests.swift index 3614a8b..9fe95a4 100644 --- a/PadelClubTests/ServerDataTests.swift +++ b/PadelClubTests/ServerDataTests.swift @@ -64,8 +64,12 @@ final class ServerDataTests: XCTestCase { inserted_club.phone = "123456" inserted_club.lastUpdate = Date() - let updated_club: Club = try await StoreCenter.main.service().put(inserted_club) - assert(updated_club.phone == inserted_club.phone) + if let updated_club: Club = try await StoreCenter.main.service().put(inserted_club) { + assert(updated_club.phone == inserted_club.phone) + } else { + XCTFail("missing data") + } + } else { XCTFail("missing data") } diff --git a/PadelClubTests/TokenExemptionTests.swift b/PadelClubTests/TokenExemptionTests.swift index 458e48b..e257ddf 100644 --- a/PadelClubTests/TokenExemptionTests.swift +++ b/PadelClubTests/TokenExemptionTests.swift @@ -47,9 +47,11 @@ final class TokenExemptionTests: XCTestCase { let _ = try await self.login() club.creator = user.id - let uc = try await StoreCenter.main.service().put(club) - assert(uc.creator == user.id) - + if let uc = try await StoreCenter.main.service().put(club) { + assert(uc.creator == user.id) + } else { + XCTFail("missing data") + } } func login() async throws -> CustomUser { diff --git a/PadelClubTests/UserDataTests.swift b/PadelClubTests/UserDataTests.swift index 4d98ac1..c5a9f63 100644 --- a/PadelClubTests/UserDataTests.swift +++ b/PadelClubTests/UserDataTests.swift @@ -65,20 +65,21 @@ final class UserDataTests: XCTestCase { user.loserBracketMatchFormatPreference = MatchFormat.twoSetsOfFourGames user.loserBracketMode = .manual - let uu = try await StoreCenter.main.service().put(user) - - assert(uu.summonsMessageBody == user.summonsMessageBody) - assert(uu.summonsMessageSignature == user.summonsMessageSignature) - assert(uu.summonsAvailablePaymentMethods == user.summonsAvailablePaymentMethods) - assert(uu.summonsDisplayFormat == user.summonsDisplayFormat) - assert(uu.summonsDisplayEntryFee == user.summonsDisplayEntryFee) - assert(uu.summonsUseFullCustomMessage == user.summonsUseFullCustomMessage) - assert(uu.matchFormatsDefaultDuration == user.matchFormatsDefaultDuration) - assert(uu.bracketMatchFormatPreference == user.bracketMatchFormatPreference) - assert(uu.groupStageMatchFormatPreference == user.groupStageMatchFormatPreference) - assert(uu.loserBracketMatchFormatPreference == user.loserBracketMatchFormatPreference) - assert(uu.loserBracketMode == user.loserBracketMode) - + if let uu = try await StoreCenter.main.service().put(user) { + assert(uu.summonsMessageBody == user.summonsMessageBody) + assert(uu.summonsMessageSignature == user.summonsMessageSignature) + assert(uu.summonsAvailablePaymentMethods == user.summonsAvailablePaymentMethods) + assert(uu.summonsDisplayFormat == user.summonsDisplayFormat) + assert(uu.summonsDisplayEntryFee == user.summonsDisplayEntryFee) + assert(uu.summonsUseFullCustomMessage == user.summonsUseFullCustomMessage) + assert(uu.matchFormatsDefaultDuration == user.matchFormatsDefaultDuration) + assert(uu.bracketMatchFormatPreference == user.bracketMatchFormatPreference) + assert(uu.groupStageMatchFormatPreference == user.groupStageMatchFormatPreference) + assert(uu.loserBracketMatchFormatPreference == user.loserBracketMatchFormatPreference) + assert(uu.loserBracketMode == user.loserBracketMode) + } else { + XCTFail("missing data") + } } }