StatusDataController: Properly fix update cycle

This commit is contained in:
Thomas Ricouard 2023-03-01 07:03:09 +01:00
parent 57197b9e9a
commit 05da36c27a
3 changed files with 6 additions and 6 deletions

View file

@ -32,7 +32,6 @@ 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] as? StatusDataController {
controller.updateFrom(status: status, publishUpdate: false)
return controller
}
let controller = StatusDataController(status: status, client: client)

View file

@ -150,11 +150,6 @@ public struct StatusDetailView: View {
}
}
.id(status.id)
.onAppear {
StatusDataControllerProvider.shared.dataController(for: status.reblog ?? status,
client: client)
.updateFrom(status: status, publishUpdate: true)
}
}
private var errorView: some View {

View file

@ -2,6 +2,7 @@ import Foundation
import Models
import Network
import SwiftUI
import Env
@MainActor
class StatusDetailViewModel: ObservableObject {
@ -78,6 +79,11 @@ class StatusDetailViewModel: ObservableObject {
var statuses = data.context.ancestors
statuses.append(data.status)
statuses.append(contentsOf: data.context.descendants)
StatusDataControllerProvider.shared.dataController(for: data.status,
client: client)
.updateFrom(status: data.status, publishUpdate: true)
if animate {
withAnimation {
isLoadingContext = false