mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 10:11:00 +00:00
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:
parent
e8cb090baf
commit
4bbfdcd256
3 changed files with 22 additions and 9 deletions
|
@ -7,6 +7,8 @@ public struct AccountDetailContextMenu: View {
|
|||
@Environment(RouterPath.self) private var routerPath
|
||||
@Environment(CurrentInstance.self) private var currentInstance
|
||||
@Environment(UserPreferences.self) private var preferences
|
||||
|
||||
@Binding var showBlockConfirmation: Bool
|
||||
|
||||
var viewModel: AccountDetailViewModel
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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?")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue