Update status on fetching detail

This commit is contained in:
Thomas Ricouard 2023-02-28 14:16:16 +01:00
parent 23fe7d3373
commit adf8d004f7
2 changed files with 8 additions and 3 deletions

View file

@ -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

View file

@ -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 {