Add block confirmation

This commit is contained in:
Thomas Ricouard 2024-01-31 07:56:50 +01:00
parent de757c58f8
commit b348f37f1a
3 changed files with 27 additions and 11 deletions

View File

@ -18,9 +18,11 @@ public struct StatusRowView: View {
@Environment(QuickLook.self) private var quickLook @Environment(QuickLook.self) private var quickLook
@Environment(Theme.self) private var theme @Environment(Theme.self) private var theme
@Environment(Client.self) private var client
@State private var viewModel: StatusRowViewModel @State private var viewModel: StatusRowViewModel
@State private var showSelectableText: Bool = false @State private var showSelectableText: Bool = false
@State private var isBlockConfirmationPresented = false
public enum Context { case timeline, detail } public enum Context { case timeline, detail }
private let context: Context private let context: Context
@ -31,7 +33,9 @@ public struct StatusRowView: View {
} }
var contextMenu: some View { var contextMenu: some View {
StatusRowContextMenu(viewModel: viewModel, showTextForSelection: $showSelectableText) StatusRowContextMenu(viewModel: viewModel,
showTextForSelection: $showSelectableText,
isBlockConfirmationPresented: $isBlockConfirmationPresented)
} }
public var body: some View { public var body: some View {
@ -95,7 +99,8 @@ public struct StatusRowView: View {
if !reasons.contains(.placeholder), if !reasons.contains(.placeholder),
viewModel.showActions, isFocused || theme.statusActionsDisplay != .none, viewModel.showActions, isFocused || theme.statusActionsDisplay != .none,
!isInCaptureMode { !isInCaptureMode {
StatusRowActionsView(viewModel: viewModel) StatusRowActionsView(isBlockConfirmationPresented: $isBlockConfirmationPresented,
viewModel: viewModel)
.tint(isFocused ? theme.tintColor : .gray) .tint(isFocused ? theme.tintColor : .gray)
.contentShape(Rectangle()) .contentShape(Rectangle())
} }
@ -189,6 +194,19 @@ public struct StatusRowView: View {
secondaryButton: .cancel() 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 .alignmentGuide(.listRowSeparatorLeading) { _ in
-100 -100
} }

View File

@ -17,6 +17,8 @@ struct StatusRowActionsView: View {
@State private var showTextForSelection: Bool = false @State private var showTextForSelection: Bool = false
@Binding var isBlockConfirmationPresented: Bool
var viewModel: StatusRowViewModel var viewModel: StatusRowViewModel
var isNarrow: Bool { var isNarrow: Bool {
@ -186,7 +188,9 @@ struct StatusRowActionsView: View {
Spacer() Spacer()
} else if action == .menu { } else if action == .menu {
Menu { Menu {
StatusRowContextMenu(viewModel: viewModel, showTextForSelection: $showTextForSelection) StatusRowContextMenu(viewModel: viewModel,
showTextForSelection: $showTextForSelection,
isBlockConfirmationPresented: $isBlockConfirmationPresented)
.onAppear { .onAppear {
Task { Task {
await viewModel.loadAuthorRelationship() await viewModel.loadAuthorRelationship()

View File

@ -20,6 +20,7 @@ struct StatusRowContextMenu: View {
var viewModel: StatusRowViewModel var viewModel: StatusRowViewModel
@Binding var showTextForSelection: Bool @Binding var showTextForSelection: Bool
@Binding var isBlockConfirmationPresented: Bool
var boostLabel: some View { var boostLabel: some View {
if viewModel.status.visibility == .priv, viewModel.status.account.id == account.account?.id { if viewModel.status.visibility == .priv, viewModel.status.account.id == account.account?.id {
@ -283,14 +284,7 @@ struct StatusRowContextMenu: View {
} }
} else { } else {
Button { Button {
Task { isBlockConfirmationPresented = true
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)")
}
}
} label: { } label: {
Label("account.action.block", systemImage: "person.crop.circle.badge.xmark") Label("account.action.block", systemImage: "person.crop.circle.badge.xmark")
} }