Improve API call execution and add developer mode

sync2
Laurent 8 months ago
parent eaabafb07e
commit 602755fe2a
  1. 24
      PadelClub/Views/Navigation/Toolbox/APICallsListView.swift
  2. 70
      PadelClub/Views/Navigation/Toolbox/ToolboxView.swift
  3. 8
      PadelClubTests/ServerDataTests.swift
  4. 8
      PadelClubTests/TokenExemptionTests.swift
  5. 29
      PadelClubTests/UserDataTests.swift

@ -192,16 +192,26 @@ struct APICallView: View {
} }
do { do {
let result = try await StoreCenter.main.execute(apiCalls: [call]) let results = try await StoreCenter.main.execute(apiCalls: [call])
print(result)
// Update UI on the main thread
await MainActor.run { await MainActor.run {
errorMessage = nil
isLoading = false isLoading = false
if let result = results.first {
// Show success popover errorMessage = result.message
showSuccessPopover = true 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 { } catch {
// Update UI on the main thread // Update UI on the main thread
await MainActor.run { await MainActor.run {

@ -15,6 +15,12 @@ struct ToolboxView: View {
@Environment(NavigationViewModel.self) private var navigation: NavigationViewModel @Environment(NavigationViewModel.self) private var navigation: NavigationViewModel
@State private var didResetApiCalls: Bool = false @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? { var lastDataSource: String? {
dataStore.appSettings.lastDataSource dataStore.appSettings.lastDataSource
} }
@ -39,25 +45,21 @@ struct ToolboxView: View {
.contextMenu { .contextMenu {
ShareLink(item: URLs.main.url) ShareLink(item: URLs.main.url)
} }
SupportButtonView(contentIsUnavailable: false) SupportButtonView(contentIsUnavailable: false)
Link(destination: URLs.appReview.url) { Link(destination: URLs.appReview.url) {
Text("Partagez vos impressions !") Text("Partagez vos impressions !")
} }
Link(destination: URLs.instagram.url) { Link(destination: URLs.instagram.url) {
Text("Compte Instagram PadelClub.app") Text("Compte Instagram PadelClub.app")
} }
} }
#if DEBUG if showDebugViews {
DebugView() DebugView()
#endif }
#if TESTFLIGHT
DebugView()
#endif
Section { Section {
NavigationLink { NavigationLink {
@ -65,7 +67,7 @@ struct ToolboxView: View {
} label: { } label: {
Label("Rechercher un joueur", systemImage: "person.fill.viewfinder") Label("Rechercher un joueur", systemImage: "person.fill.viewfinder")
} }
NavigationLink { NavigationLink {
RankCalculatorView() RankCalculatorView()
} label: { } label: {
@ -113,13 +115,13 @@ struct ToolboxView: View {
didResetApiCalls = true didResetApiCalls = true
} }
} }
Section { Section {
Link(destination: URLs.appDescription.url) { Link(destination: URLs.appDescription.url) {
Text("Page de présentation de Padel Club") Text("Page de présentation de Padel Club")
} }
} }
Section { Section {
Link(destination: URLs.privacy.url) { Link(destination: URLs.privacy.url) {
Text("Politique de confidentialité") 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) { .overlay(alignment: .bottom) {
if didResetApiCalls { if didResetApiCalls {
Label("logs effacés", systemImage: "checkmark") Label("logs effacés", systemImage: "checkmark")
@ -148,8 +160,16 @@ struct ToolboxView: View {
} }
} }
} }
.navigationTitle(TabDestination.toolbox.title) .navigationBarTitleDisplayMode(.large)
// .navigationTitle(TabDestination.toolbox.title)
.toolbar { .toolbar {
ToolbarItem(placement: .principal) {
Text(TabDestination.toolbox.title)
.font(.headline)
.onTapGesture {
_handleTitleTap()
}
}
ToolbarItem(placement: .topBarLeading) { ToolbarItem(placement: .topBarLeading) {
Link(destination: URLs.appStore.url) { Link(destination: URLs.appStore.url) {
Text("v\(PadelClubApp.appVersion)") 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 { //#Preview {

@ -64,8 +64,12 @@ final class ServerDataTests: XCTestCase {
inserted_club.phone = "123456" inserted_club.phone = "123456"
inserted_club.lastUpdate = Date() inserted_club.lastUpdate = Date()
let updated_club: Club = try await StoreCenter.main.service().put(inserted_club) if let updated_club: Club = try await StoreCenter.main.service().put(inserted_club) {
assert(updated_club.phone == inserted_club.phone) assert(updated_club.phone == inserted_club.phone)
} else {
XCTFail("missing data")
}
} else { } else {
XCTFail("missing data") XCTFail("missing data")
} }

@ -47,9 +47,11 @@ final class TokenExemptionTests: XCTestCase {
let _ = try await self.login() let _ = try await self.login()
club.creator = user.id club.creator = user.id
let uc = try await StoreCenter.main.service().put(club) if let uc = try await StoreCenter.main.service().put(club) {
assert(uc.creator == user.id) assert(uc.creator == user.id)
} else {
XCTFail("missing data")
}
} }
func login() async throws -> CustomUser { func login() async throws -> CustomUser {

@ -65,20 +65,21 @@ final class UserDataTests: XCTestCase {
user.loserBracketMatchFormatPreference = MatchFormat.twoSetsOfFourGames user.loserBracketMatchFormatPreference = MatchFormat.twoSetsOfFourGames
user.loserBracketMode = .manual user.loserBracketMode = .manual
let uu = try await StoreCenter.main.service().put(user) if let uu = try await StoreCenter.main.service().put(user) {
assert(uu.summonsMessageBody == user.summonsMessageBody)
assert(uu.summonsMessageBody == user.summonsMessageBody) assert(uu.summonsMessageSignature == user.summonsMessageSignature)
assert(uu.summonsMessageSignature == user.summonsMessageSignature) assert(uu.summonsAvailablePaymentMethods == user.summonsAvailablePaymentMethods)
assert(uu.summonsAvailablePaymentMethods == user.summonsAvailablePaymentMethods) assert(uu.summonsDisplayFormat == user.summonsDisplayFormat)
assert(uu.summonsDisplayFormat == user.summonsDisplayFormat) assert(uu.summonsDisplayEntryFee == user.summonsDisplayEntryFee)
assert(uu.summonsDisplayEntryFee == user.summonsDisplayEntryFee) assert(uu.summonsUseFullCustomMessage == user.summonsUseFullCustomMessage)
assert(uu.summonsUseFullCustomMessage == user.summonsUseFullCustomMessage) assert(uu.matchFormatsDefaultDuration == user.matchFormatsDefaultDuration)
assert(uu.matchFormatsDefaultDuration == user.matchFormatsDefaultDuration) assert(uu.bracketMatchFormatPreference == user.bracketMatchFormatPreference)
assert(uu.bracketMatchFormatPreference == user.bracketMatchFormatPreference) assert(uu.groupStageMatchFormatPreference == user.groupStageMatchFormatPreference)
assert(uu.groupStageMatchFormatPreference == user.groupStageMatchFormatPreference) assert(uu.loserBracketMatchFormatPreference == user.loserBracketMatchFormatPreference)
assert(uu.loserBracketMatchFormatPreference == user.loserBracketMatchFormatPreference) assert(uu.loserBracketMode == user.loserBracketMode)
assert(uu.loserBracketMode == user.loserBracketMode) } else {
XCTFail("missing data")
}
} }
} }

Loading…
Cancel
Save