Allow hiding or showing user boosts (#305)

* allow hiding or showing user boosts

* move notify and reboosts buttons below follow button

* move the account joined date below the name

* fix join date padding

Co-authored-by: Jérôme Danthinne <jerome.danthinne@smile.eu>
This commit is contained in:
Jérôme Danthinne 2023-01-23 18:50:59 +01:00 committed by GitHub
parent a51e81102e
commit 94ab5766a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 33 deletions

View file

@ -104,13 +104,14 @@ struct AccountDetailHeaderView: View {
private var accountInfoView: some View { private var accountInfoView: some View {
Group { Group {
accountAvatarView accountAvatarView
HStack { HStack(alignment: .firstTextBaseline) {
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
EmojiTextApp(.init(stringValue: account.safeDisplayName), emojis: account.emojis) EmojiTextApp(.init(stringValue: account.safeDisplayName), emojis: account.emojis)
.font(.scaledHeadline) .font(.scaledHeadline)
Text("@\(account.acct)") Text("@\(account.acct)")
.font(.scaledCallout) .font(.scaledCallout)
.foregroundColor(.gray) .foregroundColor(.gray)
joinedAtView
} }
Spacer() Spacer()
if let relationship = viewModel.relationship, !viewModel.isCurrentUser { if let relationship = viewModel.relationship, !viewModel.isCurrentUser {
@ -145,6 +146,20 @@ struct AccountDetailHeaderView: View {
.foregroundColor(.gray) .foregroundColor(.gray)
} }
} }
@ViewBuilder
private var joinedAtView: some View {
if let joinedAt = viewModel.account?.createdAt.asDate {
HStack(spacing: 4) {
Image(systemName: "calendar")
Text("account.joined")
Text(joinedAt, style: .date)
}
.foregroundColor(.gray)
.font(.footnote)
.padding(.top, 6)
}
}
} }
struct AccountDetailHeaderView_Previews: PreviewProvider { struct AccountDetailHeaderView_Previews: PreviewProvider {

View file

@ -43,8 +43,6 @@ public struct AccountDetailView: View {
} content: { } content: {
LazyVStack(alignment: .leading) { LazyVStack(alignment: .leading) {
makeHeaderView(proxy: proxy) makeHeaderView(proxy: proxy)
joinedAtView
.offset(y: -36)
familiarFollowers familiarFollowers
.offset(y: -36) .offset(y: -36)
featuredTagsView featuredTagsView
@ -150,22 +148,6 @@ public struct AccountDetailView: View {
} }
} }
@ViewBuilder
private var joinedAtView: some View {
if let joinedAt = viewModel.account?.createdAt.asDate {
HStack(spacing: 4) {
Image(systemName: "calendar")
Text("account.joined")
Text(joinedAt, style: .date)
}
.foregroundColor(.gray)
.font(.footnote)
.padding(.horizontal, .layoutPadding)
.padding(.top, 2)
.padding(.bottom, 5)
}
}
@ViewBuilder @ViewBuilder
private var featuredTagsView: some View { private var featuredTagsView: some View {
if !viewModel.featuredTags.isEmpty || !viewModel.fields.isEmpty { if !viewModel.featuredTags.isEmpty || !viewModel.fields.isEmpty {

View file

@ -28,7 +28,7 @@ public class FollowButtonViewModel: ObservableObject {
guard let client else { return } guard let client else { return }
isUpdating = true isUpdating = true
do { do {
relationship = try await client.post(endpoint: Accounts.follow(id: accountId, notify: false)) relationship = try await client.post(endpoint: Accounts.follow(id: accountId, notify: false, reblogs: true))
relationshipUpdated(relationship) relationshipUpdated(relationship)
} catch { } catch {
print("Error while following: \(error.localizedDescription)") print("Error while following: \(error.localizedDescription)")
@ -51,12 +51,26 @@ public class FollowButtonViewModel: ObservableObject {
func toggleNotify() async { func toggleNotify() async {
guard let client else { return } guard let client else { return }
do { do {
relationship = try await client.post(endpoint: Accounts.follow(id: accountId, notify: !relationship.notifying)) relationship = try await client.post(endpoint: Accounts.follow(id: accountId,
notify: !relationship.notifying,
reblogs: relationship.showingReblogs))
relationshipUpdated(relationship) relationshipUpdated(relationship)
} catch { } catch {
print("Error while following: \(error.localizedDescription)") print("Error while following: \(error.localizedDescription)")
} }
} }
func toggleReboosts() async {
guard let client else { return }
do {
relationship = try await client.post(endpoint: Accounts.follow(id: accountId,
notify: relationship.notifying,
reblogs: !relationship.showingReblogs))
relationshipUpdated(relationship)
} catch {
print("Error while switching reboosts: \(error.localizedDescription)")
}
}
} }
public struct FollowButton: View { public struct FollowButton: View {
@ -68,7 +82,7 @@ public struct FollowButton: View {
} }
public var body: some View { public var body: some View {
HStack { VStack {
Button { Button {
Task { Task {
if viewModel.relationship.following { if viewModel.relationship.following {
@ -87,6 +101,7 @@ public struct FollowButton: View {
.buttonStyle(.bordered) .buttonStyle(.bordered)
.disabled(viewModel.isUpdating) .disabled(viewModel.isUpdating)
if viewModel.relationship.following, viewModel.shouldDisplayNotify { if viewModel.relationship.following, viewModel.shouldDisplayNotify {
HStack {
Button { Button {
Task { Task {
await viewModel.toggleNotify() await viewModel.toggleNotify()
@ -96,6 +111,17 @@ public struct FollowButton: View {
} }
.buttonStyle(.bordered) .buttonStyle(.bordered)
.disabled(viewModel.isUpdating) .disabled(viewModel.isUpdating)
Button {
Task {
await viewModel.toggleReboosts()
}
} label: {
Image(systemName: viewModel.relationship.showingReblogs ? "arrow.left.arrow.right.circle.fill" : "arrow.left.arrow.right.circle")
}
.buttonStyle(.bordered)
.disabled(viewModel.isUpdating)
}
} }
} }
.onAppear { .onAppear {

View file

@ -22,7 +22,7 @@ public enum Accounts: Endpoint {
excludeReplies: Bool?, excludeReplies: Bool?,
pinned: Bool?) pinned: Bool?)
case relationships(ids: [String]) case relationships(ids: [String])
case follow(id: String, notify: Bool) case follow(id: String, notify: Bool, reblogs: Bool)
case unfollow(id: String) case unfollow(id: String)
case familiarFollowers(withAccount: String) case familiarFollowers(withAccount: String)
case suggestions case suggestions
@ -55,7 +55,7 @@ public enum Accounts: Endpoint {
return "accounts/\(id)/statuses" return "accounts/\(id)/statuses"
case .relationships: case .relationships:
return "accounts/relationships" return "accounts/relationships"
case let .follow(id, _): case let .follow(id, _, _):
return "accounts/\(id)/follow" return "accounts/\(id)/follow"
case let .unfollow(id): case let .unfollow(id):
return "accounts/\(id)/unfollow" return "accounts/\(id)/unfollow"
@ -106,8 +106,11 @@ public enum Accounts: Endpoint {
return ids.map { return ids.map {
URLQueryItem(name: "id[]", value: $0) URLQueryItem(name: "id[]", value: $0)
} }
case let .follow(_, notify): case let .follow(_, notify, reblogs):
return [.init(name: "notify", value: notify ? "true" : "false")] return [
.init(name: "notify", value: notify ? "true" : "false"),
.init(name: "reblogs", value: reblogs ? "true" : "false")
]
case let .familiarFollowers(withAccount): case let .familiarFollowers(withAccount):
return [.init(name: "id[]", value: withAccount)] return [.init(name: "id[]", value: withAccount)]
case let .followers(_, maxId): case let .followers(_, maxId):