Various fixes

This commit is contained in:
Thomas Ricouard 2022-12-27 09:11:12 +01:00
parent 5db6d2d991
commit 94d4db6214
5 changed files with 58 additions and 33 deletions

View file

@ -15,6 +15,7 @@ struct AccountDetailHeaderView: View {
let isCurrentUser: Bool
let account: Account
let relationship: Relationshionship?
let scrollViewProxy: ScrollViewProxy?
@Binding var scrollOffset: CGFloat
@ -83,7 +84,13 @@ struct AccountDetailHeaderView: View {
}
Spacer()
Group {
Button {
withAnimation {
scrollViewProxy?.scrollTo("status", anchor: .top)
}
} label: {
makeCustomInfoLabel(title: "Posts", count: account.statusesCount)
}
NavigationLink(value: RouteurDestinations.following(id: account.id)) {
makeCustomInfoLabel(title: "Following", count: account.followingCount)
}
@ -139,6 +146,7 @@ struct AccountDetailHeaderView_Previews: PreviewProvider {
AccountDetailHeaderView(isCurrentUser: false,
account: .placeholder(),
relationship: .placeholder(),
scrollViewProxy: nil,
scrollOffset: .constant(0))
}
}

View file

@ -34,15 +34,17 @@ public struct AccountDetailView: View {
}
public var body: some View {
ScrollViewReader { proxy in
ScrollViewOffsetReader { offset in
self.scrollOffset = offset
} content: {
LazyVStack(alignment: .leading) {
headerView
makeHeaderView(proxy: proxy)
familliarFollowers
.offset(y: -36)
featuredTagsView
.offset(y: -36)
Group {
if isCurrentUser {
Picker("", selection: $viewModel.selectedTab) {
ForEach(AccountDetailViewModel.Tab.allCases, id: \.self) { tab in
@ -56,6 +58,8 @@ public struct AccountDetailView: View {
Divider()
.offset(y: -20)
}
}
.id("status")
switch viewModel.tabState {
case .statuses:
@ -65,6 +69,7 @@ public struct AccountDetailView: View {
}
}
}
}
.task {
guard reasons != .placeholder else { return }
viewModel.client = client
@ -90,18 +95,20 @@ public struct AccountDetailView: View {
}
@ViewBuilder
private var headerView: some View {
private func makeHeaderView(proxy: ScrollViewProxy?) -> some View {
switch viewModel.accountState {
case .loading:
AccountDetailHeaderView(isCurrentUser: isCurrentUser,
account: .placeholder(),
relationship: .placeholder(),
scrollViewProxy: proxy,
scrollOffset: $scrollOffset)
.redacted(reason: .placeholder)
case let .data(account):
AccountDetailHeaderView(isCurrentUser: isCurrentUser,
account: account,
relationship: viewModel.relationship,
scrollViewProxy: proxy,
scrollOffset: $scrollOffset)
case let .error(error):
Text("Error: \(error.localizedDescription)")

View file

@ -6,11 +6,16 @@ import Models
@MainActor
extension Account {
private struct Part: Identifiable {
let id = UUID().uuidString
let value: Substring
}
public var displayNameWithEmojis: some View {
let splittedDisplayName = displayName.split(separator: ":")
let splittedDisplayName = displayName.split(separator: ":").map{ Part(value: $0) }
return HStack(spacing: 0) {
ForEach(splittedDisplayName, id: \.self) { part in
if let emoji = emojis.first(where: { $0.shortcode == part }) {
ForEach(splittedDisplayName, id: \.id) { part in
if let emoji = emojis.first(where: { $0.shortcode == part.value }) {
LazyImage(url: emoji.url) { state in
if let image = state.image {
image
@ -24,7 +29,7 @@ extension Account {
.processors([ImageProcessors.Resize(size: .init(width: 20, height: 20))])
.frame(width: 20, height: 20)
} else {
Text(part)
Text(part.value)
}
}
}

View file

@ -41,6 +41,9 @@ public struct StatusRowView: View {
}
}
}
.contextMenu {
contextMenu
}
}
@ViewBuilder

View file

@ -75,7 +75,9 @@ public struct TimelineView: View {
if !viewModel.pendingStatuses.isEmpty {
Button {
proxy.scrollTo(Constants.scrollToTop)
withAnimation {
viewModel.displayPendingStatuses()
}
} label: {
Text(viewModel.pendingStatusesButtonTitle)
}