// // https://mczachurski.dev // Copyright © 2023 Marcin Czachurski and the repository contributors. // Licensed under the MIT License. // import SwiftUI import MastodonKit struct UserProfileView: View { @EnvironmentObject private var applicationState: ApplicationState @State public var accountId: String @State public var accountDisplayName: String? @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 { if let account = self.account { ScrollView { UserProfileHeader(account: account, relationship: relationship) UserProfileStatuses(accountId: account.id) } } else { Spacer() LoadingIndicator() Spacer() } } .navigationBarTitle(self.accountDisplayName ?? self.accountUserName) .task { do { try await self.loadData() } catch { ErrorService.shared.handle(error, message: "Error during download account from server.", showToastr: !Task.isCancelled) } } } 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) } }