Skip to content

Instantly share code, notes, and snippets.

@nparsons08

nparsons08/PeopleView.swift Secret

Created May 4, 2020
Embed
What would you like to do?
// ios/TheStream/PeopleView.swift:3
struct PeopleView: View {
@EnvironmentObject var account: Account
@State var users: [String] = []
@State var showFollowedAlert: Bool = false
@State var tag: Int? = nil
var body: some View {
List {
ForEach(users.indices, id: \.self) { i in
HStack() {
Text(self.users[i]).onTapGesture {
self.tag = i
}
NavigationLink(destination: PrivateChatView(user: self.account.user!, withUser: self.users[i]), tag: i, selection: self.$tag) {
Spacer()
}
Image(systemName: "message").onTapGesture {
self.tag = i
}
Image(systemName: "plus.circle").onTapGesture {
self.account.follow(self.users[i]) {
self.showFollowedAlert = true
}
}
}
}
}
.onAppear(perform: fetch)
.alert(isPresented: $showFollowedAlert) {
Alert(title: Text("Followed"))
}
}
private func fetch() {
account.fetchUsers { users in
self.users = users.filter { $0 != self.account.user! }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.