Fixed on post detail

This commit is contained in:
Thomas Ricouard 2023-02-10 20:57:09 +01:00
parent a32014991c
commit 4e2d15eff6

View file

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