Fixed on post detail

This commit is contained in:
Thomas Ricouard 2023-02-10 20:57:09 +01:00
parent a32014991c
commit 4e2d15eff6
1 changed files with 13 additions and 7 deletions

View File

@ -39,7 +39,7 @@ class StatusDetailViewModel: ObservableObject {
func fetch() async -> Bool {
if statusId != nil {
await fetchStatusDetail()
await fetchStatusDetail(animate: false)
return true
} else if remoteStatusURL != nil {
return await fetchRemoteStatus()
@ -56,7 +56,7 @@ class StatusDetailViewModel: ObservableObject {
forceVersion: .v2)
if let statusId = results?.statuses.first?.id {
self.statusId = statusId
await fetchStatusDetail()
await fetchStatusDetail(animate: false)
return true
} else {
return false
@ -68,13 +68,19 @@ class StatusDetailViewModel: ObservableObject {
let context: StatusContext
}
private func fetchStatusDetail() async {
private func fetchStatusDetail(animate: Bool) async {
guard let client, let statusId else { return }
do {
let data = try await fetchContextData(client: client, statusId: statusId)
title = "status.post-from-\(data.status.account.displayNameWithoutEmojis)"
state = .display(status: data.status, context: data.context)
scrollToId = statusId
if animate {
withAnimation {
state = .display(status: data.status, context: data.context)
}
} else {
state = .display(status: data.status, context: data.context)
scrollToId = statusId
}
} catch {
state = .error(error: error)
}
@ -91,11 +97,11 @@ class StatusDetailViewModel: ObservableObject {
event.status.account.id == currentAccount?.id
{
Task {
await fetchStatusDetail()
await fetchStatusDetail(animate: true)
}
} else if event is StreamEventDelete {
Task {
await fetchStatusDetail()
await fetchStatusDetail(animate: true)
}
}
}