@@ -32,22 +32,16 @@ struct SpaceItem: View {
32
32
. padding ( . horizontal, - Theme. sidebarItemPadding)
33
33
34
34
// 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
+ } )
51
45
52
46
// Actions on space
53
47
. contextMenu {
@@ -82,8 +76,8 @@ struct SpaceItem: View {
82
76
}
83
77
}
84
78
85
- var actionText : String {
86
- pendingAction == . delete ? " Delete " : " Leave "
79
+ func actionText( _ action : Action ) -> String {
80
+ action == . delete ? " Delete " : " Leave "
87
81
}
88
82
89
83
enum Action {
@@ -93,7 +87,9 @@ struct SpaceItem: View {
93
87
94
88
private func startPendingAct( _ action: Action ) {
95
89
pendingAction = action
96
- alertPresented = true
90
+ DispatchQueue . main. async {
91
+ alertPresented = true
92
+ }
97
93
}
98
94
99
95
private func act( _ action: Action ) {
0 commit comments