From f2e9d5deafa81faa9ddb4666eb1f2cd047bc7669 Mon Sep 17 00:00:00 2001 From: rene Date: Sat, 30 May 2026 12:51:16 +0200 Subject: [PATCH] =?UTF-8?q?Heim:=20wei=C3=9Fer=20Gradient=20raus,=20Tagesb?= =?UTF-8?q?ild=20pro=20Tag=20cachen=20wie=20die=20PWA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - LinearGradient zum systemBackground entfernt — der Übergang war zu hart weiß und hat das Foto verschluckt - UserDefaults-Cache 'heimPhoto_{userId}_{dogId}_YYYY-MM-DD' analog zur PWA (bg3_{userId}_YYYY-MM-DD). Sobald ein Foto pro Tag gewählt ist, sticht es bis Mitternacht — damit kippt's nicht mehr, wenn zwischendrin neue Bilder hochgeladen werden und die tick%len-Rotation auf einen anderen Index zeigt --- BanYaroGo/Views/HeimView.swift | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/BanYaroGo/Views/HeimView.swift b/BanYaroGo/Views/HeimView.swift index ef60d37..6de0dd0 100644 --- a/BanYaroGo/Views/HeimView.swift +++ b/BanYaroGo/Views/HeimView.swift @@ -5,8 +5,17 @@ struct HeimView: View { @Environment(ActiveDogStore.self) private var activeDog @State private var dashboard: DashboardSnapshot? + @State private var cachedPhotoUrl: String? @State private var isLoading = false + private var photoCacheKey: String? { + guard let userId = auth.profile?.id, + let dogId = activeDog.activeDog?.id else { return nil } + let f = DateFormatter() + f.dateFormat = "yyyy-MM-dd" + return "heimPhoto_\(userId)_\(dogId)_\(f.string(from: .now))" + } + private var greeting: String { let hour = Calendar.current.component(.hour, from: .now) let name = auth.profile?.name ?? auth.userName ?? "" @@ -59,7 +68,7 @@ struct HeimView: View { private var background: some View { ZStack { Color.accentColor.opacity(0.08).ignoresSafeArea() - if let path = dashboard?.randomPhoto?.url, + if let path = cachedPhotoUrl ?? dashboard?.randomPhoto?.url, let url = URL(string: "https://banyaro.app\(path)") { AsyncImage(url: url) { phase in switch phase { @@ -71,13 +80,6 @@ struct HeimView: View { } .frame(maxWidth: .infinity, maxHeight: 320, alignment: .top) .clipped() - .overlay( - LinearGradient( - colors: [.clear, .clear, Color(.systemBackground).opacity(0.95), Color(.systemBackground)], - startPoint: .top, - endPoint: .bottom - ) - ) .frame(maxHeight: .infinity, alignment: .top) } } @@ -241,8 +243,21 @@ struct HeimView: View { private func load() async { guard let dog = activeDog.activeDog else { return } + + // 1. Cached photo URL bevorzugen — bleibt stabil über den Tag, identisch + // zur PWA (gleiches Cache-Schema: pro user+dog+datum). + // Auch nil setzen, falls der Cache-Key zum anderen Hund gehört. + cachedPhotoUrl = photoCacheKey.flatMap { UserDefaults.standard.string(forKey: $0) } + isLoading = true defer { isLoading = false } dashboard = try? await APIClient.shared.get("/api/dogs/\(dog.id)/welcome-dashboard") + + // 2. Wenn noch nichts gecacht ist und das Backend ein Foto liefert, + // festhalten — bis Mitternacht zeigen wir dasselbe Bild. + if cachedPhotoUrl == nil, let fresh = dashboard?.randomPhoto?.url, let key = photoCacheKey { + UserDefaults.standard.set(fresh, forKey: key) + cachedPhotoUrl = fresh + } } }