add information about sync

sync3
Laurent 2 months ago
parent ed06b68405
commit a9ce9659f1
  1. 25
      PadelClub/Views/Navigation/Toolbox/APICallsListView.swift
  2. 46
      PadelClub/Views/Navigation/Toolbox/DebugSettingsView.swift

@ -12,20 +12,27 @@ import PadelClubData
struct APICallsListView: View {
@State var descriptors: [CollectionDescriptor] = []
@State var total = 0
var body: some View {
List {
ForEach(self.descriptors) { descriptor in
NavigationLink {
if let syncedType = descriptor.type as? any SyncedStorable.Type {
APICallsView(name: descriptor.name, type: syncedType)
Section {
LabeledContent("Total count", value: "\(total)")
}
Section {
ForEach(self.descriptors) { descriptor in
NavigationLink {
if let syncedType = descriptor.type as? any SyncedStorable.Type {
APICallsView(name: descriptor.name, type: syncedType)
}
} label: {
LabeledContent(descriptor.name, value: descriptor.count.string)
}
} label: {
LabeledContent(descriptor.name, value: descriptor.count.string)
}
}
}.onAppear {
self.load()
@ -49,6 +56,8 @@ struct APICallsListView: View {
func loadCount<T: SyncedStorable>(_ type: T.Type, _ descriptor: CollectionDescriptor) async {
let calls = await StoreCenter.main.apiCalls(type: type)
descriptor.count = calls.count
self.total = total + descriptor.count
// Logger.log("\(descriptor.name), count = \(calls.count)")
}

@ -10,6 +10,10 @@ import LeStorage
import PadelClubData
struct DebugSettingsView: View {
@State private var errorMessage: String?
@State private var showingError = false
@State private var isSynchronizing = false
var body: some View {
List {
@ -17,7 +21,19 @@ struct DebugSettingsView: View {
LabeledContent("Has Websocket Manager", value: self._hasWebSocketManager)
LabeledContent("Websocket ping", value: self._wsPingStatus)
LabeledContent("Websocket failure", value: self._wsFailure)
LabeledContent("Last sync date", value: self._lastSyncDate)
LabeledContent("Last synced object date", value: self._lastSyncDate)
if isSynchronizing {
HStack {
ProgressView()
.scaleEffect(0.8)
Text("Synchronizing...")
.foregroundColor(.secondary)
}
} else {
Button("Synchronize") {
self._synchronize()
}
}
}
Section("Settings") {
@ -40,6 +56,11 @@ struct DebugSettingsView: View {
}
}
.alert("Synchronization Error", isPresented: $showingError) {
Button("OK") { }
} message: {
Text(errorMessage ?? "An unknown error occurred")
}
}
fileprivate var _userId: String {
@ -79,6 +100,29 @@ struct DebugSettingsView: View {
fileprivate var _lastSyncDate: String {
return "\(StoreCenter.main.lastSyncDate)"
}
fileprivate func _synchronize() {
Logger.log("launch sync...")
Task {
await MainActor.run {
isSynchronizing = true
}
do {
try await StoreCenter.main.synchronizeLastUpdates()
} catch {
Logger.error(error)
await MainActor.run {
errorMessage = error.localizedDescription
showingError = true
}
}
await MainActor.run {
isSynchronizing = false
}
}
}
}
struct DebugPurchaseView: View {

Loading…
Cancel
Save