mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-02-02 15:46:43 +01:00
Account about fields
This commit is contained in:
parent
0f2c2df624
commit
05b5951ee1
@ -13,6 +13,7 @@ public struct AccountDetailView: View {
|
|||||||
|
|
||||||
@StateObject private var viewModel: AccountDetailViewModel
|
@StateObject private var viewModel: AccountDetailViewModel
|
||||||
@State private var scrollOffset: CGFloat = 0
|
@State private var scrollOffset: CGFloat = 0
|
||||||
|
@State private var isFieldsSheetDisplayed: Bool = false
|
||||||
|
|
||||||
private let isCurrentUser: Bool
|
private let isCurrentUser: Bool
|
||||||
|
|
||||||
@ -111,9 +112,26 @@ public struct AccountDetailView: View {
|
|||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var featuredTagsView: some View {
|
private var featuredTagsView: some View {
|
||||||
if !viewModel.featuredTags.isEmpty {
|
if !viewModel.featuredTags.isEmpty || !viewModel.fields.isEmpty {
|
||||||
ScrollView(.horizontal, showsIndicators: false) {
|
ScrollView(.horizontal, showsIndicators: false) {
|
||||||
HStack(spacing: 4) {
|
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
|
ForEach(viewModel.featuredTags) { tag in
|
||||||
Button {
|
Button {
|
||||||
routeurPath.navigate(to: .hashTag(tag: tag.name, account: viewModel.accountId))
|
routeurPath.navigate(to: .hashTag(tag: tag.name, account: viewModel.accountId))
|
||||||
@ -127,11 +145,36 @@ public struct AccountDetailView: View {
|
|||||||
}.buttonStyle(.bordered)
|
}.buttonStyle(.bordered)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.padding(.leading, DS.Constants.layoutPadding)
|
.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 {
|
private func makeTagsListView(tags: [Tag]) -> some View {
|
||||||
Group {
|
Group {
|
||||||
ForEach(tags) { tag in
|
ForEach(tags) { tag in
|
||||||
|
@ -49,6 +49,7 @@ class AccountDetailViewModel: ObservableObject, StatusesFetcher {
|
|||||||
@Published var favourites: [Status] = []
|
@Published var favourites: [Status] = []
|
||||||
@Published var followedTags: [Tag] = []
|
@Published var followedTags: [Tag] = []
|
||||||
@Published var featuredTags: [FeaturedTag] = []
|
@Published var featuredTags: [FeaturedTag] = []
|
||||||
|
@Published var fields: [Account.Field] = []
|
||||||
@Published var selectedTab = Tab.statuses {
|
@Published var selectedTab = Tab.statuses {
|
||||||
didSet {
|
didSet {
|
||||||
reloadTabState()
|
reloadTabState()
|
||||||
@ -77,6 +78,7 @@ class AccountDetailViewModel: ObservableObject, StatusesFetcher {
|
|||||||
guard let client else { return }
|
guard let client else { return }
|
||||||
do {
|
do {
|
||||||
let account: Account = try await client.get(endpoint: Accounts.accounts(id: accountId))
|
let account: Account = try await client.get(endpoint: Accounts.accounts(id: accountId))
|
||||||
|
self.fields = account.fields
|
||||||
if isCurrentUser {
|
if isCurrentUser {
|
||||||
self.followedTags = try await client.get(endpoint: Accounts.followedTags)
|
self.followedTags = try await client.get(endpoint: Accounts.followedTags)
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,9 +6,13 @@ public struct Account: Codable, Identifiable, Equatable, Hashable {
|
|||||||
hasher.combine(id)
|
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 name: String
|
||||||
public let value: String
|
public let value: HTMLString
|
||||||
public let verifiedAt: String?
|
public let verifiedAt: String?
|
||||||
}
|
}
|
||||||
public let id: String
|
public let id: String
|
||||||
|
Loading…
x
Reference in New Issue
Block a user