@@ -14,7 +14,6 @@ struct InviteFriendsView: View {
14
14
15
15
// Add view models for friends
16
16
@StateObject private var friendsViewModel : FriendsTabViewModel
17
- @ObservedObject private var appCache = AppCache . shared
18
17
19
18
let user : BaseUserDTO
20
19
@@ -52,14 +51,25 @@ struct InviteFriendsView: View {
52
51
. onAppear {
53
52
friendsViewModel. connectSearchViewModel ( searchViewModel)
54
53
55
- if appCache . friends. isEmpty {
54
+ if AppCache . shared . friends. isEmpty {
56
55
Task {
57
56
await friendsViewModel. fetchAllData ( )
57
+ // After fetching friends, automatically select them all if not already selected
58
+ await MainActor . run {
59
+ if activityCreationViewModel. selectedFriends. isEmpty {
60
+ activityCreationViewModel. selectedFriends = friendsViewModel. friends
61
+ }
62
+ }
58
63
}
59
64
} else {
60
65
// Use cached friends data
61
- friendsViewModel. friends = appCache. friends
62
- friendsViewModel. filteredFriends = appCache. friends
66
+ friendsViewModel. friends = AppCache . shared. friends
67
+ friendsViewModel. filteredFriends = AppCache . shared. friends
68
+
69
+ // Automatically select all friends if not already selected
70
+ if activityCreationViewModel. selectedFriends. isEmpty {
71
+ activityCreationViewModel. selectedFriends = AppCache . shared. friends
72
+ }
63
73
}
64
74
}
65
75
}
@@ -159,10 +169,7 @@ struct InviteFriendsView: View {
159
169
$0. id == friend. id
160
170
}
161
171
} else {
162
- activityCreationViewModel. selectedFriends. append ( friend) // Add to selected friends
163
- }
164
- activityCreationViewModel. selectedFriends. removeAll {
165
- $0. id == friend. id
172
+ activityCreationViewModel. selectedFriends. append ( friend)
166
173
}
167
174
}
168
175
}
@@ -245,6 +252,5 @@ struct IndividualFriendView: View {
245
252
246
253
@available ( iOS 17 . 0 , * )
247
254
#Preview {
248
- @Previewable @StateObject var appCache = AppCache . shared
249
- InviteFriendsView ( user: . danielAgapov) . environmentObject ( appCache)
255
+ InviteFriendsView ( user: . danielAgapov)
250
256
}
0 commit comments