mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 10:11:00 +00:00
Account about fields
This commit is contained in:
parent
0f2c2df624
commit
05b5951ee1
3 changed files with 58 additions and 9 deletions
|
@ -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
|
||||
|
||||
|
@ -111,9 +112,26 @@ public struct AccountDetailView: View {
|
|||
|
||||
@ViewBuilder
|
||||
private var featuredTagsView: some View {
|
||||
if !viewModel.featuredTags.isEmpty {
|
||||
if !viewModel.featuredTags.isEmpty || !viewModel.fields.isEmpty {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(spacing: 4) {
|
||||
if !viewModel.fields.isEmpty {
|
||||
Button {
|
||||
isFieldsSheetDisplayed.toggle()
|
||||
} label: {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
Text("About")
|
||||
.font(.callout)
|
||||
Text("\(viewModel.fields.count) fields")
|
||||
.font(.caption2)
|
||||
}
|
||||
}
|
||||
.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))
|
||||
|
@ -127,11 +145,36 @@ public struct AccountDetailView: View {
|
|||
}.buttonStyle(.bordered)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.leading, DS.Constants.layoutPadding)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue