From adf8d004f7cdb856eaceaf8a397cf9b3b90e26dd Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Tue, 28 Feb 2023 14:16:16 +0100 Subject: [PATCH] Update status on fetching detail --- Packages/Env/Sources/Env/StatusDataController.swift | 6 +++--- .../Status/Sources/Status/Detail/StatusDetailView.swift | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Packages/Env/Sources/Env/StatusDataController.swift b/Packages/Env/Sources/Env/StatusDataController.swift index e7ae132a..1ecdce06 100644 --- a/Packages/Env/Sources/Env/StatusDataController.swift +++ b/Packages/Env/Sources/Env/StatusDataController.swift @@ -31,8 +31,8 @@ public final class StatusDataControllerProvider { public func dataController(for status: any AnyStatus, client: Client) -> StatusDataController { let key = CacheKey(statusId: status.id, client: client) - if let controller = cache[key] { - return controller as! StatusDataController + if let controller = cache[key] as? StatusDataController { + return controller } let controller = StatusDataController(status: status, client: client) cache[key] = controller @@ -66,7 +66,7 @@ public final class StatusDataController: StatusDataControlling { self.favoritesCount = status.favouritesCount } - private func updateFrom(status: Status) { + public func updateFrom(status: Status) { self.isReblogged = status.reblogged == true self.isBookmarked = status.bookmarked == true self.isFavorited = status.favourited == true diff --git a/Packages/Status/Sources/Status/Detail/StatusDetailView.swift b/Packages/Status/Sources/Status/Detail/StatusDetailView.swift index 40ebbf91..bbb1bd6e 100644 --- a/Packages/Status/Sources/Status/Detail/StatusDetailView.swift +++ b/Packages/Status/Sources/Status/Detail/StatusDetailView.swift @@ -150,6 +150,11 @@ public struct StatusDetailView: View { } } .id(status.id) + .onAppear { + StatusDataControllerProvider.shared.dataController(for: status.reblog ?? status, + client: client) + .updateFrom(status: status) + } } private var errorView: some View {