2023-01-04 20:56:26 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import MastodonSwift
|
|
|
|
|
|
|
|
struct UserProfileView: View {
|
2023-01-06 13:05:21 +01:00
|
|
|
@EnvironmentObject private var applicationState: ApplicationState
|
|
|
|
|
2023-01-04 20:56:26 +01:00
|
|
|
@State public var accountId: String
|
|
|
|
@State public var accountDisplayName: String?
|
|
|
|
@State public var accountUserName: String
|
|
|
|
@State private var account: Account? = nil
|
2023-01-05 11:55:20 +01:00
|
|
|
@State private var relationship: Relationship? = nil
|
2023-01-04 20:56:26 +01:00
|
|
|
|
|
|
|
var body: some View {
|
2023-01-05 11:55:20 +01:00
|
|
|
ScrollView {
|
2023-01-09 10:06:21 +01:00
|
|
|
if let account = self.account, let relationship = self.relationship {
|
|
|
|
UserProfileHeader(account: account, relationship: relationship)
|
|
|
|
UserProfileStatuses(accountId: account.id)
|
2023-01-04 20:56:26 +01:00
|
|
|
} else {
|
2023-01-06 13:05:21 +01:00
|
|
|
LoadingIndicator()
|
2023-01-04 20:56:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.navigationBarTitle(self.accountDisplayName ?? self.accountUserName)
|
|
|
|
.onAppear {
|
|
|
|
Task {
|
|
|
|
do {
|
2023-01-09 08:29:55 +01:00
|
|
|
try await self.loadData()
|
2023-01-04 20:56:26 +01:00
|
|
|
} catch {
|
|
|
|
print("Error \(error.localizedDescription)")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-09 08:29:55 +01:00
|
|
|
|
|
|
|
private func loadData() async throws {
|
|
|
|
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.relationship, self.account) = try await (relationshipTask, accountTask)
|
|
|
|
}
|
2023-01-04 20:56:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct UserProfileView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
UserProfileView(accountId: "", accountDisplayName: "", accountUserName: "")
|
|
|
|
}
|
|
|
|
}
|