mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 02:01:02 +00:00
Handle status update in post context
This commit is contained in:
parent
d600ab8800
commit
8e16764ff7
2 changed files with 21 additions and 2 deletions
|
@ -6,6 +6,8 @@ import Network
|
|||
import DesignSystem
|
||||
|
||||
public struct StatusDetailView: View {
|
||||
@EnvironmentObject private var currentAccount: CurrentAccount
|
||||
@EnvironmentObject private var watcher: StreamWatcher
|
||||
@EnvironmentObject private var client: Client
|
||||
@EnvironmentObject private var routeurPath: RouterPath
|
||||
@StateObject private var viewModel: StatusDetailViewModel
|
||||
|
@ -63,6 +65,10 @@ public struct StatusDetailView: View {
|
|||
proxy.scrollTo(viewModel.statusId, anchor: .center)
|
||||
}
|
||||
}
|
||||
.onChange(of: watcher.latestEvent?.id) { _ in
|
||||
guard let lastEvent = watcher.latestEvent else { return }
|
||||
viewModel.handleEvent(event: lastEvent, currentAccount: currentAccount.account)
|
||||
}
|
||||
}
|
||||
.navigationTitle(viewModel.title)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
|
|
|
@ -24,7 +24,6 @@ class StatusDetailViewModel: ObservableObject {
|
|||
func fetchStatusDetail() async {
|
||||
guard let client else { return }
|
||||
do {
|
||||
state = .loading
|
||||
let status: Status = try await client.get(endpoint: Statuses.status(id: statusId))
|
||||
let context: StatusContext = try await client.get(endpoint: Statuses.context(id: statusId))
|
||||
state = .display(status: status, context: context)
|
||||
|
@ -33,4 +32,18 @@ class StatusDetailViewModel: ObservableObject {
|
|||
state = .error(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func handleEvent(event: any StreamEvent, currentAccount: Account?) {
|
||||
if let event = event as? StreamEventUpdate,
|
||||
event.status.account.id == currentAccount?.id {
|
||||
Task {
|
||||
await fetchStatusDetail()
|
||||
}
|
||||
} else if event is StreamEventDelete {
|
||||
Task {
|
||||
await fetchStatusDetail()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue