Feature request: Block user confirmation dialog (#1606)

- Using State property and Binding between ContextMenu and AccountDetailView to show a confirmation dialog when the block button is pressed.

Co-authored-by: Eric Chaing <eric@Erics-MacBook-Pro.local>
This commit is contained in:
Eric 2023-10-04 00:40:54 -07:00 committed by GitHub
parent e8cb090baf
commit 4bbfdcd256
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 9 deletions

View file

@ -7,6 +7,8 @@ public struct AccountDetailContextMenu: View {
@Environment(RouterPath.self) private var routerPath @Environment(RouterPath.self) private var routerPath
@Environment(CurrentInstance.self) private var currentInstance @Environment(CurrentInstance.self) private var currentInstance
@Environment(UserPreferences.self) private var preferences @Environment(UserPreferences.self) private var preferences
@Binding var showBlockConfirmation: Bool
var viewModel: AccountDetailViewModel var viewModel: AccountDetailViewModel
@ -42,13 +44,7 @@ public struct AccountDetailContextMenu: View {
} }
} else { } else {
Button { Button {
Task { showBlockConfirmation.toggle()
do {
viewModel.relationship = try await client.post(endpoint: Accounts.block(id: account.id))
} catch {
print("Error while blocking: \(error.localizedDescription)")
}
}
} label: { } label: {
Label("account.action.block", systemImage: "person.crop.circle.badge.xmark") Label("account.action.block", systemImage: "person.crop.circle.badge.xmark")
} }

View file

@ -24,6 +24,7 @@ public struct AccountDetailView: View {
@State private var isCurrentUser: Bool = false @State private var isCurrentUser: Bool = false
@State private var isCreateListAlertPresented: Bool = false @State private var isCreateListAlertPresented: Bool = false
@State private var createListTitle: String = "" @State private var createListTitle: String = ""
@State private var showBlockConfirmation: Bool = false
@State private var isEditingAccount: Bool = false @State private var isEditingAccount: Bool = false
@State private var isEditingFilters: Bool = false @State private var isEditingFilters: Bool = false
@ -320,7 +321,7 @@ public struct AccountDetailView: View {
} }
Menu { Menu {
AccountDetailContextMenu(viewModel: viewModel) AccountDetailContextMenu(showBlockConfirmation: $showBlockConfirmation, viewModel: viewModel)
if !viewModel.isCurrentUser { if !viewModel.isCurrentUser {
Button { Button {
@ -388,6 +389,21 @@ public struct AccountDetailView: View {
LocalizedStringKey("accessibility.tabs.profile.options.inputLabel2"), LocalizedStringKey("accessibility.tabs.profile.options.inputLabel2"),
]) ])
} }
.confirmationDialog("Block User", isPresented: $showBlockConfirmation) {
if let account = viewModel.account {
Button("Block \(account.username)", role: .destructive) {
Task {
do {
viewModel.relationship = try await client.post(endpoint: Accounts.block(id: account.id))
} catch {
print("Error while blocking: \(error.localizedDescription)")
}
}
}
}
} message: {
Text("Do you want to block this user?")
}
} }
} }
} }

View file

@ -30,6 +30,7 @@ public struct AccountsListRow: View {
@State var viewModel: AccountsListRowViewModel @State var viewModel: AccountsListRowViewModel
@State private var isEditingRelationshipNote: Bool = false @State private var isEditingRelationshipNote: Bool = false
@State private var showBlockConfirmation: Bool = false
let isFollowRequest: Bool let isFollowRequest: Bool
let requestUpdated: (() -> Void)? let requestUpdated: (() -> Void)?
@ -107,7 +108,7 @@ public struct AccountsListRow: View {
routerPath.navigate(to: .accountDetailWithAccount(account: viewModel.account)) routerPath.navigate(to: .accountDetailWithAccount(account: viewModel.account))
} }
.contextMenu { .contextMenu {
AccountDetailContextMenu(viewModel: .init(account: viewModel.account)) AccountDetailContextMenu(showBlockConfirmation: $showBlockConfirmation, viewModel: .init(account: viewModel.account))
} preview: { } preview: {
List { List {
AccountDetailHeaderView(viewModel: .init(account: viewModel.account), AccountDetailHeaderView(viewModel: .init(account: viewModel.account),