Fixed a number of sync issues I noticed
All checks were successful
Ascently - Sync Deploy / build-and-push (push) Successful in 2m30s

This commit is contained in:
2026-01-09 14:39:28 -07:00
parent afb0456692
commit d002c703d5
6 changed files with 478 additions and 954 deletions

View File

@@ -6,6 +6,7 @@ import UniformTypeIdentifiers
enum SheetType {
case export(Data)
case importData
case syncSettings
}
struct SettingsView: View {
@@ -16,7 +17,7 @@ struct SettingsView: View {
var body: some View {
NavigationStack {
List {
SyncSection()
SyncSection(activeSheet: $activeSheet)
.environmentObject(dataManager.syncService)
HealthKitSection()
@@ -67,6 +68,9 @@ struct SettingsView: View {
ExportDataView(data: data)
case .importData:
ImportDataView()
case .syncSettings:
SyncSettingsView()
.environmentObject(dataManager.syncService)
}
}
}
@@ -78,6 +82,7 @@ extension SheetType: Identifiable {
switch self {
case .export: return "export"
case .importData: return "import"
case .syncSettings: return "sync_settings"
}
}
}
@@ -526,7 +531,7 @@ struct SyncSection: View {
@EnvironmentObject var syncService: SyncService
@EnvironmentObject var dataManager: ClimbingDataManager
@EnvironmentObject var themeManager: ThemeManager
@State private var showingSyncSettings = false
@Binding var activeSheet: SheetType?
@State private var showingDisconnectAlert = false
private static let logTag = "SyncSection"
@@ -567,7 +572,7 @@ struct SyncSection: View {
// Configure Server
Button(action: {
showingSyncSettings = true
activeSheet = .syncSettings
}) {
HStack {
Image(systemName: "gear")
@@ -657,10 +662,6 @@ struct SyncSection: View {
}
}
}
.sheet(isPresented: $showingSyncSettings) {
SyncSettingsView()
.environmentObject(syncService)
}
.alert("Disconnect from Server", isPresented: $showingDisconnectAlert) {
Button("Cancel", role: .cancel) {}
Button("Disconnect", role: .destructive) {
@@ -702,24 +703,14 @@ struct SyncSettingsView: View {
NavigationStack {
Form {
Section {
TextField("Server URL", text: $serverURL)
.textFieldStyle(.roundedBorder)
TextField("Server URL", text: $serverURL, prompt: Text("http://your-server:8080"))
.keyboardType(.URL)
.autocapitalization(.none)
.disableAutocorrection(true)
.placeholder(when: serverURL.isEmpty) {
Text("http://your-server:8080")
.foregroundColor(.secondary)
}
TextField("Auth Token", text: $authToken)
.textFieldStyle(.roundedBorder)
TextField("Auth Token", text: $authToken, prompt: Text("your-secret-token"))
.autocapitalization(.none)
.disableAutocorrection(true)
.placeholder(when: authToken.isEmpty) {
Text("your-secret-token")
.foregroundColor(.secondary)
}
} header: {
Text("Server Configuration")
} footer: {
@@ -845,37 +836,34 @@ struct SyncSettingsView: View {
let originalURL = syncService.serverURL
let originalToken = syncService.authToken
Task {
Task { @MainActor in
do {
// Ensure we are using the server provider
await MainActor.run {
if syncService.providerType != .server {
syncService.providerType = .server
}
if syncService.providerType != .server {
syncService.providerType = .server
}
// Temporarily set the values for testing
syncService.serverURL = testURL
syncService.authToken = testToken
// Explicitly sync UserDefaults to ensure immediate availability
UserDefaults.standard.synchronize()
try await syncService.testConnection()
await MainActor.run {
isTesting = false
testResultMessage =
"Connection successful! You can now save and sync your data."
showingTestResult = true
}
isTesting = false
testResultMessage =
"Connection successful! You can now save and sync your data."
showingTestResult = true
} catch {
// Restore original values if test failed
syncService.serverURL = originalURL
syncService.authToken = originalToken
await MainActor.run {
isTesting = false
testResultMessage = "Connection failed: \(error.localizedDescription)"
showingTestResult = true
}
isTesting = false
testResultMessage = "Connection failed: \(error.localizedDescription)"
showingTestResult = true
}
}
}