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

@ -8,6 +8,8 @@ public struct AccountDetailContextMenu: View {
@Environment(CurrentInstance.self) private var currentInstance
@Environment(UserPreferences.self) private var preferences
@Binding var showBlockConfirmation: Bool
var viewModel: AccountDetailViewModel
public var body: some View {
@ -42,13 +44,7 @@ public struct AccountDetailContextMenu: View {
}
} else {
Button {
Task {
do {
viewModel.relationship = try await client.post(endpoint: Accounts.block(id: account.id))
} catch {
print("Error while blocking: \(error.localizedDescription)")
}
}
showBlockConfirmation.toggle()
} label: {
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 isCreateListAlertPresented: Bool = false
@State private var createListTitle: String = ""
@State private var showBlockConfirmation: Bool = false
@State private var isEditingAccount: Bool = false
@State private var isEditingFilters: Bool = false
@ -320,7 +321,7 @@ public struct AccountDetailView: View {
}
Menu {
AccountDetailContextMenu(viewModel: viewModel)
AccountDetailContextMenu(showBlockConfirmation: $showBlockConfirmation, viewModel: viewModel)
if !viewModel.isCurrentUser {
Button {
@ -388,6 +389,21 @@ public struct AccountDetailView: View {
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 private var isEditingRelationshipNote: Bool = false
@State private var showBlockConfirmation: Bool = false
let isFollowRequest: Bool
let requestUpdated: (() -> Void)?
@ -107,7 +108,7 @@ public struct AccountsListRow: View {
routerPath.navigate(to: .accountDetailWithAccount(account: viewModel.account))
}
.contextMenu {
AccountDetailContextMenu(viewModel: .init(account: viewModel.account))
AccountDetailContextMenu(showBlockConfirmation: $showBlockConfirmation, viewModel: .init(account: viewModel.account))
} preview: {
List {
AccountDetailHeaderView(viewModel: .init(account: viewModel.account),