Fix issue with downloading the same statuses after come back from details to user profile.

This commit is contained in:
Marcin Czachursk 2023-01-12 13:59:13 +01:00
parent 3638d36d78
commit 8b251fb617
3 changed files with 16 additions and 0 deletions

View File

@ -17,6 +17,7 @@ struct StatusView: View {
@State private var messageForStatus: StatusViewModel?
@State private var showCompose = false
@State private var firstLoadFinished = false
@State private var statusViewModel: StatusViewModel?
@ -97,6 +98,10 @@ struct StatusView: View {
})
.task {
do {
guard firstLoadFinished == false else {
return
}
// Get status from API.
if let status = try await TimelineService.shared.getStatus(withId: self.statusId, and: self.applicationState.accountData) {
let statusViewModel = StatusViewModel(status: status)
@ -110,6 +115,7 @@ struct StatusView: View {
}
self.statusViewModel = statusViewModel
self.firstLoadFinished = true
// If we have status in database then we can update data.
if let accountData = self.applicationState.accountData,

View File

@ -15,6 +15,7 @@ struct UserProfileView: View {
@State public var accountUserName: String
@State private var account: Account? = nil
@State private var relationship: Relationship? = nil
@State private var firstLoadFinished = false
var body: some View {
VStack {
@ -40,10 +41,15 @@ struct UserProfileView: View {
}
private func loadData() async throws {
guard firstLoadFinished == false else {
return
}
async let relationshipTask = AccountService.shared.getRelationship(withId: self.accountId, forUser: self.applicationState.accountData)
async let accountTask = AccountService.shared.getAccount(withId: self.accountId, and: self.applicationState.accountData)
// Wait for download account and relationships.
self.firstLoadFinished = true
(self.relationship, self.account) = try await (relationshipTask, accountTask)
}
}

View File

@ -59,6 +59,10 @@ struct UserProfileStatuses: View {
}
private func loadStatuses() async throws {
guard firstLoadFinished == false else {
return
}
let statuses = try await AccountService.shared.getStatuses(
forAccountId: self.accountId,
andContext: self.applicationState.accountData,