Files
Yusuf Suleman fdb8aeba8a
All checks were successful
Security Checks / dependency-audit (push) Successful in 12s
Security Checks / secret-scanning (push) Successful in 3s
Security Checks / dockerfile-lint (push) Successful in 3s
restore: original UI views from first build, keep fixed models/API
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 01:54:46 -05:00

50 lines
1.1 KiB
Swift

import Foundation
@MainActor @Observable
final class HomeViewModel {
var todayEntries: [FoodEntry] = []
var goal: DailyGoal = .defaultGoal
var isLoading = true
var errorMessage: String?
private let repo = FitnessRepository.shared
var totalCalories: Double {
todayEntries.reduce(0) { $0 + $1.calories }
}
var totalProtein: Double {
todayEntries.reduce(0) { $0 + $1.protein }
}
var totalCarbs: Double {
todayEntries.reduce(0) { $0 + $1.carbs }
}
var totalFat: Double {
todayEntries.reduce(0) { $0 + $1.fat }
}
var entryCount: Int {
todayEntries.count
}
func load() async {
isLoading = true
errorMessage = nil
let today = Date().apiDateString
do {
async let entriesTask = repo.entries(for: today, forceRefresh: true)
async let goalsTask = repo.goals(for: today)
todayEntries = try await entriesTask
goal = try await goalsTask
} catch {
errorMessage = error.localizedDescription
}
isLoading = false
}
}