2022-12-30 07:36:22 +00:00
|
|
|
import DesignSystem
|
2023-01-12 05:58:04 +00:00
|
|
|
import EmojiText
|
2023-01-17 10:36:01 +00:00
|
|
|
import Env
|
|
|
|
import SwiftUI
|
2022-12-30 07:36:22 +00:00
|
|
|
|
2023-01-12 17:17:21 +00:00
|
|
|
public struct AppAccountView: View {
|
2023-01-10 05:58:50 +00:00
|
|
|
@EnvironmentObject private var routeurPath: RouterPath
|
2022-12-30 07:36:22 +00:00
|
|
|
@EnvironmentObject var appAccounts: AppAccountsManager
|
|
|
|
@StateObject var viewModel: AppAccountViewModel
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-12 17:17:21 +00:00
|
|
|
public init(viewModel: AppAccountViewModel) {
|
|
|
|
_viewModel = .init(wrappedValue: viewModel)
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-12 17:17:21 +00:00
|
|
|
public var body: some View {
|
2022-12-30 07:36:22 +00:00
|
|
|
HStack {
|
|
|
|
if let account = viewModel.account {
|
|
|
|
ZStack(alignment: .topTrailing) {
|
|
|
|
AvatarView(url: account.avatar)
|
|
|
|
if viewModel.appAccount.id == appAccounts.currentAccount.id {
|
|
|
|
Image(systemName: "checkmark.circle.fill")
|
2023-01-08 18:45:11 +00:00
|
|
|
.foregroundStyle(.white, .green)
|
2022-12-30 07:36:22 +00:00
|
|
|
.offset(x: 5, y: -5)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
if let account = viewModel.account {
|
2023-01-12 20:12:47 +00:00
|
|
|
EmojiTextApp(account.safeDisplayName.asMarkdown, emojis: account.emojis)
|
2022-12-30 21:30:18 +00:00
|
|
|
Text("\(account.username)@\(viewModel.appAccount.server)")
|
|
|
|
.font(.subheadline)
|
2022-12-30 07:36:22 +00:00
|
|
|
.foregroundColor(.gray)
|
|
|
|
}
|
|
|
|
}
|
2023-01-10 05:58:50 +00:00
|
|
|
Spacer()
|
|
|
|
Image(systemName: "chevron.right")
|
|
|
|
.foregroundColor(.gray)
|
2022-12-30 07:36:22 +00:00
|
|
|
}
|
|
|
|
.onAppear {
|
|
|
|
Task {
|
|
|
|
await viewModel.fetchAccount()
|
|
|
|
}
|
|
|
|
}
|
2023-01-10 05:58:50 +00:00
|
|
|
.onTapGesture {
|
|
|
|
if appAccounts.currentAccount.id == viewModel.appAccount.id,
|
2023-01-17 10:36:01 +00:00
|
|
|
let account = viewModel.account
|
|
|
|
{
|
2023-01-10 05:58:50 +00:00
|
|
|
routeurPath.navigate(to: .accountDetailWithAccount(account: account))
|
|
|
|
} else {
|
|
|
|
appAccounts.currentAccount = viewModel.appAccount
|
|
|
|
}
|
|
|
|
}
|
2022-12-30 07:36:22 +00:00
|
|
|
}
|
|
|
|
}
|