Skip to content

Commit c5ab26c

Browse files
committed
macOS: refactor alert to fix the issue in prod
1 parent bc34ee5 commit c5ab26c

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

apple/InlineMac/Views/MainSidebar/SpaceItem.swift

+15-19
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,16 @@ struct SpaceItem: View {
3232
.padding(.horizontal, -Theme.sidebarItemPadding)
3333

3434
// Alert for delete confirmation
35-
.alert(isPresented: $alertPresented) {
36-
Alert(
37-
title: Text("Are you sure?"),
38-
message: Text(
39-
"Confirm you want to \(actionText.lowercased()) this space"
40-
),
41-
primaryButton: .destructive(Text(actionText)) {
42-
Task {
43-
act(pendingAction!)
44-
}
45-
},
46-
secondaryButton: .cancel {
47-
pendingAction = nil
48-
}
49-
)
50-
}
35+
.alert("Are you sure?", isPresented: $alertPresented, presenting: pendingAction, actions: { action in
36+
Button(actionText(action), role: .destructive) {
37+
act(action)
38+
}
39+
Button("Cancel", role: .cancel) {
40+
pendingAction = nil
41+
}
42+
}, message: { action in
43+
Text("Confirm you want to \(actionText(action).lowercased()) this space")
44+
})
5145

5246
// Actions on space
5347
.contextMenu {
@@ -82,8 +76,8 @@ struct SpaceItem: View {
8276
}
8377
}
8478

85-
var actionText: String {
86-
pendingAction == .delete ? "Delete" : "Leave"
79+
func actionText(_ action: Action) -> String {
80+
action == .delete ? "Delete" : "Leave"
8781
}
8882

8983
enum Action {
@@ -93,7 +87,9 @@ struct SpaceItem: View {
9387

9488
private func startPendingAct(_ action: Action) {
9589
pendingAction = action
96-
alertPresented = true
90+
DispatchQueue.main.async {
91+
alertPresented = true
92+
}
9793
}
9894

9995
private func act(_ action: Action) {

0 commit comments

Comments
 (0)