fixed the count of users not working and adding the timer, but still a little buggy

This commit is contained in:
talksik
2022-01-02 01:05:42 -08:00
parent 6c41de7264
commit 342f19393a
2 changed files with 21 additions and 13 deletions
+20 -12
View File
@@ -11,9 +11,11 @@ struct ConvoFooterView: View {
@EnvironmentObject var convoVM: ConvoViewModel
@EnvironmentObject var authSessionStore: AuthSessionStore
@State private var convoRelativeTime = "started 20 minutes ago"
@State private var convoRelativeTime = ""
@State private var selectedConvo: Convo? = nil
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
var body: some View {
ZStack(alignment:.bottomTrailing) {
@@ -22,6 +24,11 @@ struct ConvoFooterView: View {
HStack {
if self.selectedConvo != nil {
// TODO: get their info for warm intros to be made
// var unknownUsers = self.selectedConvo!.users.filter {userId in
// return !self.authSessionStore.relevantUsersDict.keys.contains(userId)
// }
// the users which I have data for
let filteredUsers = self.authSessionStore.relevantUsersDict.filter {
return self.selectedConvo!.users.contains($0.key)
}
@@ -33,7 +40,7 @@ struct ConvoFooterView: View {
// meta data of convo
VStack (alignment: .leading) {
ConvoUsernames(users: convoUsers)
ConvoUsernames(users: convoUsers, unknownUserCount: self.selectedConvo!.users.count - convoUsers.count)
switch self.convoVM.connectionState {
case .connecting:
@@ -119,17 +126,17 @@ struct ConvoFooterView: View {
return
}
// reset the selected options to start fresh
self.convoRelativeTime = ""
self.selectedConvo = newConvos.first {convo in
convo.id == self.convoVM.selectedConvoId
}
// get relative start time of convo
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .full
self.convoRelativeTime = formatter.localizedString(for: self.selectedConvo?.startedTimestamp ?? Date(), relativeTo: Date())
}
.onReceive(timer) { _ in
if self.selectedConvo != nil {
// get relative start time of convo
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .full
self.convoRelativeTime = "started " + formatter.localizedString(for: self.selectedConvo?.startedTimestamp ?? Date(), relativeTo: Date())
}
}
}
}
@@ -142,10 +149,11 @@ struct ConvoFooterView_Previews: PreviewProvider {
struct ConvoUsernames: View {
var users: [User]
var unknownUserCount: Int = 0
var body: some View {
let userNames = self.users.map{$0.nickname ?? ""}.joined(separator: ",")
Text(userNames)
let userNames = self.users.map{$0.nickname ?? ""}.joined(separator: ", ")
Text(unknownUserCount > 0 ? "\(userNames), and \(unknownUserCount) other(s)": userNames)
.font(.footnote)
.foregroundColor(NirvanaColor.light)
}
@@ -102,7 +102,7 @@ struct CircleGridView: View {
.font(.title2)
.padding(5)
.overlay(
Text("\(convoUsers.count)")
Text("\(currConvo.users.count)")
.foregroundColor(Color.white)
.font(.caption2)
)