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 {
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 {

@ -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 {

@ -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")
}

@ -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 {

@ -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")
}
}
}

Loading…
Cancel
Save