Heim: weißer Gradient raus, Tagesbild pro Tag cachen wie die PWA
- 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
This commit is contained in:
parent
3059a5eb2c
commit
f2e9d5deaf
1 changed files with 23 additions and 8 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue