2024-02-20 20:57:07 +01:00
|
|
|
//Made by Lumaa
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
2024-02-20 20:57:50 +01:00
|
|
|
struct AccountRow<Content : View>: View {
|
|
|
|
@Environment(AccountManager.self) private var accountManager: AccountManager
|
|
|
|
@EnvironmentObject private var navigator: Navigator
|
|
|
|
|
|
|
|
var acct: String
|
|
|
|
@ViewBuilder var text: Content
|
|
|
|
|
|
|
|
@State private var account: Account? = nil
|
|
|
|
|
2024-02-20 20:57:07 +01:00
|
|
|
var body: some View {
|
2024-02-20 20:57:50 +01:00
|
|
|
HStack(spacing: 20) {
|
|
|
|
if let acc = account {
|
|
|
|
ProfilePicture(url: acc.avatar, size: 64)
|
|
|
|
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
text
|
|
|
|
|
|
|
|
Text(acc.displayName ?? "@\(acc.acct)")
|
|
|
|
.multilineTextAlignment(.leading)
|
|
|
|
}
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
Button {
|
|
|
|
navigator.navigate(to: .account(acc: acc))
|
|
|
|
} label: {
|
|
|
|
Text("account.view")
|
|
|
|
}
|
|
|
|
.buttonStyle(LargeButton(filled: true, height: 7.5))
|
|
|
|
} else {
|
|
|
|
Circle()
|
|
|
|
.fill(Color.gray.opacity(0.45))
|
|
|
|
.frame(width: 54, height: 54)
|
|
|
|
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
text
|
|
|
|
.redacted(reason: .placeholder)
|
|
|
|
|
|
|
|
Text(Account.placeholder().displayName ?? "@\(Account.placeholder().acct)")
|
|
|
|
.redacted(reason: .placeholder)
|
|
|
|
.multilineTextAlignment(.leading)
|
|
|
|
}
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
Button {
|
|
|
|
print(acct)
|
|
|
|
} label: {
|
|
|
|
Text("account.view")
|
|
|
|
.redacted(reason: .placeholder)
|
|
|
|
}
|
|
|
|
.buttonStyle(LargeButton(filled: true, height: 7.5))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.task {
|
|
|
|
await findAccount()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func findAccount() async {
|
|
|
|
guard let client = accountManager.getClient() else { return }
|
|
|
|
do {
|
|
|
|
try await Task.sleep(for: .milliseconds(250))
|
|
|
|
let results: SearchResults = try await client.get(endpoint: Search.search(query: acct, type: "accounts", offset: nil, following: nil), forceVersion: .v2)
|
|
|
|
account = results.accounts.first
|
|
|
|
// let relationships: [Relationship] = try await client.get(endpoint: Accounts.relationships(ids: results.accounts.map(\.id)))
|
|
|
|
// relationship = relationships.first
|
|
|
|
} catch {
|
|
|
|
print(error)
|
|
|
|
}
|
2024-02-20 20:57:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#Preview {
|
2024-02-20 20:57:50 +01:00
|
|
|
List {
|
|
|
|
AccountRow(acct: "@lumaa@techhub.social") {
|
|
|
|
EmptyView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.environmentObject(Navigator())
|
|
|
|
.environment(AccountManager.shared)
|
2024-02-20 20:57:07 +01:00
|
|
|
}
|