diff --git a/BanYaroGo/Views/HeimView.swift b/BanYaroGo/Views/HeimView.swift index db2de2f..b1f553c 100644 --- a/BanYaroGo/Views/HeimView.swift +++ b/BanYaroGo/Views/HeimView.swift @@ -68,7 +68,7 @@ struct HeimView: View { private var background: some View { ZStack { Color.accentColor.opacity(0.08).ignoresSafeArea() - if let path = cachedPhotoUrl ?? dashboard?.randomPhoto?.url, + if let path = dashboard?.randomPhoto?.url ?? cachedPhotoUrl, let url = URL(string: "https://banyaro.app\(path)") { AsyncImage(url: url) { phase in switch phase { @@ -244,19 +244,20 @@ 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. + // Cache als Fallback, falls Backend offline. Nicht als Vorzug — + // sonst klebt eine tote URL (gelöschtes Bild) über den ganzen Tag. 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) + // Backend ist Source-of-Truth: wenn es ein Foto liefert, ist das + // aktuell und im Server-Cache stabil. Lokal denselben Wert ablegen. + if let fresh = dashboard?.randomPhoto?.url, let key = photoCacheKey { + if fresh != cachedPhotoUrl { + UserDefaults.standard.set(fresh, forKey: key) + } cachedPhotoUrl = fresh } }