SuggestedUsersView.swift (2685B)
1 // 2 // SuggestedUsersView.swift 3 // damus 4 // 5 // Created by klabo on 7/17/23. 6 // 7 8 import SwiftUI 9 10 struct SuggestedUsersView: View { 11 12 @StateObject var model: SuggestedUsersViewModel 13 14 @Environment(\.presentationMode) private var presentationMode 15 16 var body: some View { 17 NavigationView { 18 VStack { 19 List { 20 ForEach(model.groups) { group in 21 Section { 22 ForEach(group.users, id: \.self) { pk in 23 if let user = model.suggestedUser(pubkey: pk) { 24 SuggestedUserView(user: user, damus_state: model.damus_state) 25 } 26 } 27 } header: { 28 SuggestedUsersSectionHeader(group: group, model: model) 29 } 30 } 31 } 32 .listStyle(.plain) 33 34 Spacer() 35 36 Button(action: { 37 presentationMode.wrappedValue.dismiss() 38 }) { 39 Text(NSLocalizedString("Continue", comment: "Button to dismiss suggested users view and continue to the main app")) 40 .frame(minWidth: 300, maxWidth: .infinity, alignment: .center) 41 } 42 .buttonStyle(GradientButtonStyle()) 43 .padding([.leading, .trailing], 24) 44 .padding(.bottom, 16) 45 } 46 .navigationTitle(NSLocalizedString("Who to Follow", comment: "Title for a screen displaying suggestions of who to follow")) 47 .navigationBarTitleDisplayMode(.inline) 48 .navigationBarItems(trailing: Button(action: { 49 presentationMode.wrappedValue.dismiss() 50 }, label: { 51 Text(NSLocalizedString("Skip", comment: "Button to dismiss the suggested users screen")) 52 .font(.subheadline.weight(.semibold)) 53 })) 54 } 55 } 56 } 57 58 struct SuggestedUsersSectionHeader: View { 59 let group: SuggestedUserGroup 60 let model: SuggestedUsersViewModel 61 var body: some View { 62 HStack { 63 Text(group.title.uppercased()) 64 Spacer() 65 Button(NSLocalizedString("Follow All", comment: "Button to follow all users in this section")) { 66 model.follow(pubkeys: group.users) 67 } 68 .font(.subheadline.weight(.semibold)) 69 } 70 } 71 } 72 73 struct SuggestedUsersView_Previews: PreviewProvider { 74 static var previews: some View { 75 SuggestedUsersView(model: SuggestedUsersViewModel(damus_state: test_damus_state)) 76 } 77 }