mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-22 16:31:00 +00:00
Add block confirmation
This commit is contained in:
parent
de757c58f8
commit
b348f37f1a
3 changed files with 27 additions and 11 deletions
|
@ -18,9 +18,11 @@ public struct StatusRowView: View {
|
|||
|
||||
@Environment(QuickLook.self) private var quickLook
|
||||
@Environment(Theme.self) private var theme
|
||||
@Environment(Client.self) private var client
|
||||
|
||||
@State private var viewModel: StatusRowViewModel
|
||||
@State private var showSelectableText: Bool = false
|
||||
@State private var isBlockConfirmationPresented = false
|
||||
|
||||
public enum Context { case timeline, detail }
|
||||
private let context: Context
|
||||
|
@ -31,7 +33,9 @@ public struct StatusRowView: View {
|
|||
}
|
||||
|
||||
var contextMenu: some View {
|
||||
StatusRowContextMenu(viewModel: viewModel, showTextForSelection: $showSelectableText)
|
||||
StatusRowContextMenu(viewModel: viewModel,
|
||||
showTextForSelection: $showSelectableText,
|
||||
isBlockConfirmationPresented: $isBlockConfirmationPresented)
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
|
@ -95,7 +99,8 @@ public struct StatusRowView: View {
|
|||
if !reasons.contains(.placeholder),
|
||||
viewModel.showActions, isFocused || theme.statusActionsDisplay != .none,
|
||||
!isInCaptureMode {
|
||||
StatusRowActionsView(viewModel: viewModel)
|
||||
StatusRowActionsView(isBlockConfirmationPresented: $isBlockConfirmationPresented,
|
||||
viewModel: viewModel)
|
||||
.tint(isFocused ? theme.tintColor : .gray)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
|
@ -189,6 +194,19 @@ public struct StatusRowView: View {
|
|||
secondaryButton: .cancel()
|
||||
)
|
||||
})
|
||||
.confirmationDialog("",
|
||||
isPresented: $isBlockConfirmationPresented) {
|
||||
Button("account.action.block", role: .destructive) {
|
||||
Task {
|
||||
do {
|
||||
let operationAccount = viewModel.status.reblog?.account ?? viewModel.status.account
|
||||
viewModel.authorRelationship = try await client.post(endpoint: Accounts.block(id: operationAccount.id))
|
||||
} catch {
|
||||
print("Error while blocking: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.alignmentGuide(.listRowSeparatorLeading) { _ in
|
||||
-100
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ struct StatusRowActionsView: View {
|
|||
|
||||
@State private var showTextForSelection: Bool = false
|
||||
|
||||
@Binding var isBlockConfirmationPresented: Bool
|
||||
|
||||
var viewModel: StatusRowViewModel
|
||||
|
||||
var isNarrow: Bool {
|
||||
|
@ -186,7 +188,9 @@ struct StatusRowActionsView: View {
|
|||
Spacer()
|
||||
} else if action == .menu {
|
||||
Menu {
|
||||
StatusRowContextMenu(viewModel: viewModel, showTextForSelection: $showTextForSelection)
|
||||
StatusRowContextMenu(viewModel: viewModel,
|
||||
showTextForSelection: $showTextForSelection,
|
||||
isBlockConfirmationPresented: $isBlockConfirmationPresented)
|
||||
.onAppear {
|
||||
Task {
|
||||
await viewModel.loadAuthorRelationship()
|
||||
|
|
|
@ -20,6 +20,7 @@ struct StatusRowContextMenu: View {
|
|||
|
||||
var viewModel: StatusRowViewModel
|
||||
@Binding var showTextForSelection: Bool
|
||||
@Binding var isBlockConfirmationPresented: Bool
|
||||
|
||||
var boostLabel: some View {
|
||||
if viewModel.status.visibility == .priv, viewModel.status.account.id == account.account?.id {
|
||||
|
@ -283,14 +284,7 @@ struct StatusRowContextMenu: View {
|
|||
}
|
||||
} else {
|
||||
Button {
|
||||
Task {
|
||||
do {
|
||||
let operationAccount = viewModel.status.reblog?.account ?? viewModel.status.account
|
||||
viewModel.authorRelationship = try await client.post(endpoint: Accounts.block(id: operationAccount.id))
|
||||
} catch {
|
||||
print("Error while blocking: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
isBlockConfirmationPresented = true
|
||||
} label: {
|
||||
Label("account.action.block", systemImage: "person.crop.circle.badge.xmark")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue