Impressia/Vernissage/Views/UserProfileView.swift

56 lines
1.8 KiB
Swift
Raw Normal View History

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
2023-01-10 08:04:25 +01:00
import MastodonKit
2023-01-04 20:56:26 +01:00
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 {
VStack {
if let account = self.account {
ScrollView {
UserProfileHeader(account: account, relationship: relationship)
UserProfileStatuses(accountId: account.id)
}
2023-01-04 20:56:26 +01:00
} else {
Spacer()
2023-01-06 13:05:21 +01:00
LoadingIndicator()
Spacer()
2023-01-04 20:56:26 +01:00
}
}
.navigationBarTitle(self.accountDisplayName ?? self.accountUserName)
2023-01-11 13:16:43 +01:00
.task {
do {
try await self.loadData()
} catch {
print("Error \(error.localizedDescription)")
2023-01-04 20:56:26 +01:00
}
}
}
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: "")
}
}