diff --git a/ios/Platform/Platform/Core/APIClient.swift b/ios/Platform/Platform/Core/APIClient.swift index 2ae45d5..0a8126b 100644 --- a/ios/Platform/Platform/Core/APIClient.swift +++ b/ios/Platform/Platform/Core/APIClient.swift @@ -1,5 +1,13 @@ import Foundation +// Accepts any JSON response (for void-like endpoints that return partial data) +private struct EmptyResponse: Decodable { + init(from decoder: Decoder) throws { + // Accept anything + _ = try? decoder.singleValueContainer() + } +} + enum APIError: Error, LocalizedError { case invalidURL case httpError(Int, String) @@ -138,6 +146,10 @@ final class APIClient { try await request("PUT", path: path, body: body) } + func putVoid(_ path: String, body: any Encodable) async throws { + let _: EmptyResponse = try await request("PUT", path: path, body: body) + } + func delete(_ path: String) async throws -> T { try await request("DELETE", path: path) } diff --git a/ios/Platform/Platform/Features/Fitness/API/FitnessAPI.swift b/ios/Platform/Platform/Features/Fitness/API/FitnessAPI.swift index b979ea4..51ac183 100644 --- a/ios/Platform/Platform/Features/Fitness/API/FitnessAPI.swift +++ b/ios/Platform/Platform/Features/Fitness/API/FitnessAPI.swift @@ -30,8 +30,8 @@ struct FitnessAPI { ) } - func updateGoals(_ request: UpdateGoalsRequest) async throws -> DailyGoal { - try await api.put("\(basePath)/goals", body: request) + func updateGoals(_ request: UpdateGoalsRequest) async throws { + try await api.putVoid("\(basePath)/goals", body: request) } func updateEntry(id: String, body: UpdateEntryRequest) async throws -> FoodEntry { diff --git a/ios/Platform/Platform/Features/Fitness/ViewModels/GoalsViewModel.swift b/ios/Platform/Platform/Features/Fitness/ViewModels/GoalsViewModel.swift index 3516067..b8d1926 100644 --- a/ios/Platform/Platform/Features/Fitness/ViewModels/GoalsViewModel.swift +++ b/ios/Platform/Platform/Features/Fitness/ViewModels/GoalsViewModel.swift @@ -43,9 +43,10 @@ final class GoalsViewModel { sugar: Double(editSugar) ?? 0, fiber: Double(editFiber) ?? 0 ) - let updated = try await api.updateGoals(request) - goal = updated - populateFields(from: updated) + try await api.updateGoals(request) + // Reload goals to get the full updated object + goal = try await api.getGoals(date: Date().apiDateString) + populateFields(from: goal) saveSuccess = true } catch { self.error = error.localizedDescription diff --git a/ios/Platform/Platform/Features/Home/HomeView.swift b/ios/Platform/Platform/Features/Home/HomeView.swift index 4709165..ab5cb2a 100644 --- a/ios/Platform/Platform/Features/Home/HomeView.swift +++ b/ios/Platform/Platform/Features/Home/HomeView.swift @@ -23,9 +23,17 @@ struct HomeView: View { VStack(spacing: 16) { // Top bar HStack { - Text("Home") - .font(.title.weight(.bold)) - .foregroundStyle(vm.hasBackground ? .white : Color.textPrimary) + VStack(alignment: .leading, spacing: 2) { + if let name = auth.currentUser?.displayName { + Text("Hi, \(name)") + .font(.title.weight(.bold)) + .foregroundStyle(vm.hasBackground ? .white : Color.textPrimary) + } else { + Text("Home") + .font(.title.weight(.bold)) + .foregroundStyle(vm.hasBackground ? .white : Color.textPrimary) + } + } Spacer() Menu { PhotosPicker(