Account about fields

This commit is contained in:
Thomas Ricouard 2022-12-21 20:53:23 +01:00
parent 0f2c2df624
commit 05b5951ee1
3 changed files with 58 additions and 9 deletions

View File

@ -13,6 +13,7 @@ public struct AccountDetailView: View {
@StateObject private var viewModel: AccountDetailViewModel
@State private var scrollOffset: CGFloat = 0
@State private var isFieldsSheetDisplayed: Bool = false
private let isCurrentUser: Bool
@ -108,23 +109,41 @@ public struct AccountDetailView: View {
Text("Error: \(error.localizedDescription)")
}
}
@ViewBuilder
private var featuredTagsView: some View {
if !viewModel.featuredTags.isEmpty {
if !viewModel.featuredTags.isEmpty || !viewModel.fields.isEmpty {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 4) {
ForEach(viewModel.featuredTags) { tag in
if !viewModel.fields.isEmpty {
Button {
routeurPath.navigate(to: .hashTag(tag: tag.name, account: viewModel.accountId))
isFieldsSheetDisplayed.toggle()
} label: {
VStack(alignment: .leading, spacing: 0) {
Text("#\(tag.name)")
Text("About")
.font(.callout)
Text("\(tag.statusesCount) posts")
Text("\(viewModel.fields.count) fields")
.font(.caption2)
}
}.buttonStyle(.bordered)
}
.buttonStyle(.bordered)
.sheet(isPresented: $isFieldsSheetDisplayed) {
fieldSheetView
}
}
if !viewModel.featuredTags.isEmpty {
ForEach(viewModel.featuredTags) { tag in
Button {
routeurPath.navigate(to: .hashTag(tag: tag.name, account: viewModel.accountId))
} label: {
VStack(alignment: .leading, spacing: 0) {
Text("#\(tag.name)")
.font(.callout)
Text("\(tag.statusesCount) posts")
.font(.caption2)
}
}.buttonStyle(.bordered)
}
}
}
.padding(.leading, DS.Constants.layoutPadding)
@ -132,6 +151,30 @@ public struct AccountDetailView: View {
}
}
private var fieldSheetView: some View {
NavigationStack {
List {
ForEach(viewModel.fields) { field in
VStack(alignment: .leading, spacing: 2) {
Text(field.name)
.font(.headline)
HStack {
if field.verifiedAt != nil {
Image(systemName: "checkmark.seal")
.foregroundColor(Color.green.opacity(0.80))
}
Text(field.value.asSafeAttributedString)
.foregroundColor(.brand)
}
.font(.body)
}
.listRowBackground(field.verifiedAt != nil ? Color.green.opacity(0.15) : nil)
}
}
.navigationTitle("About")
}
}
private func makeTagsListView(tags: [Tag]) -> some View {
Group {
ForEach(tags) { tag in

View File

@ -49,6 +49,7 @@ class AccountDetailViewModel: ObservableObject, StatusesFetcher {
@Published var favourites: [Status] = []
@Published var followedTags: [Tag] = []
@Published var featuredTags: [FeaturedTag] = []
@Published var fields: [Account.Field] = []
@Published var selectedTab = Tab.statuses {
didSet {
reloadTabState()
@ -77,6 +78,7 @@ class AccountDetailViewModel: ObservableObject, StatusesFetcher {
guard let client else { return }
do {
let account: Account = try await client.get(endpoint: Accounts.accounts(id: accountId))
self.fields = account.fields
if isCurrentUser {
self.followedTags = try await client.get(endpoint: Accounts.followedTags)
} else {

View File

@ -6,9 +6,13 @@ public struct Account: Codable, Identifiable, Equatable, Hashable {
hasher.combine(id)
}
public struct Field: Codable, Equatable {
public struct Field: Codable, Equatable, Identifiable {
public var id: String {
value + name
}
public let name: String
public let value: String
public let value: HTMLString
public let verifiedAt: String?
}
public let id: String