/ BalanceKit / WaterDashboardViewHistorical.swift
WaterDashboardViewHistorical.swift
1 import SwiftUI 2 3 // Wasserkachel für historische Daten (ohne Plus-Button) 4 struct WaterDashboardViewHistorical: View { 5 let date: Date 6 @ObservedObject var healthManager: HealthManager 7 @State private var waterConsumed: Double = 0 8 9 var body: some View { 10 VStack(alignment: .center, spacing: 4) { 11 Text("Wasser") 12 .font(.headline) 13 .fontWeight(.medium) 14 .lineLimit(1) 15 .minimumScaleFactor(0.8) 16 .foregroundColor(.white) 17 .padding(.top, 8) 18 19 Spacer() 20 21 // Zentrierte Anzeige des Wasserverbrauchs 22 VStack(alignment: .center, spacing: 0) { 23 Text(String(format: "%.0f", waterConsumed)) 24 .font(.largeTitle) 25 .fontWeight(.bold) 26 .foregroundColor(.white) 27 28 Text("ml") 29 .font(.caption) 30 .foregroundColor(.white.opacity(0.8)) 31 } 32 33 Spacer() 34 } 35 .frame(maxWidth: .infinity, minHeight: 140) 36 .padding() 37 .background( 38 LinearGradient( 39 gradient: Gradient(colors: [Color.blue, Color.blue.opacity(0.8)]), 40 startPoint: .topLeading, 41 endPoint: .bottomTrailing 42 ) 43 ) 44 .cornerRadius(16) 45 .onAppear { 46 loadWaterData() 47 } 48 .onChange(of: date) { 49 loadWaterData() 50 } 51 } 52 53 private func loadWaterData() { 54 healthManager.fetchWaterIntakeForDate(date) { amount in 55 DispatchQueue.main.async { 56 self.waterConsumed = amount 57 } 58 } 59 } 60 }