diff --git a/nirvana-ios/Views/Convos/ConvoFooterView.swift b/nirvana-ios/Views/Convos/ConvoFooterView.swift index 98b645b..03fa1b7 100644 --- a/nirvana-ios/Views/Convos/ConvoFooterView.swift +++ b/nirvana-ios/Views/Convos/ConvoFooterView.swift @@ -9,89 +9,95 @@ import SwiftUI struct ConvoFooterView: View { @EnvironmentObject var convoVM: ConvoViewModel + @EnvironmentObject var authSessionStore: AuthSessionStore @State private var convoRelativeTime = "started 20 minutes ago" + @State private var selectedConvo: Convo? = nil var body: some View { + ZStack(alignment:.bottomTrailing) { VStack(alignment:.center) { Spacer() HStack { - ProfilePicturesOverlappedView(indvAvatarWidth: CGFloat(35)) - .padding(.leading, 20) - .padding(.trailing, 10) - - - // meta data of convo - VStack (alignment: .leading) { - Text("kev, sarth, and 5 others") - .font(.footnote) - .foregroundColor(NirvanaColor.light) + if self.selectedConvo != nil { + let filteredUsers = self.authSessionStore.relevantUsersDict.filter { + return self.selectedConvo!.users.contains($0.key) + } + let convoUsers: [User] = Array(filteredUsers.values) - switch self.convoVM.connectionState { - case .connecting: - Label("connecting", systemImage: "chart.bar") - .foregroundColor(Color.orange) - .font(.caption) - case .connected: - Label("connected", systemImage: "chart.bar.fill") - .foregroundColor(Color.green) - .font(.caption) - case .reconnecting: - Label("reconnecting", systemImage: "chart.bar") - .foregroundColor(Color.orange) - .font(.caption) - case .failed: - Label("failed", systemImage: "chart.bar") - .foregroundColor(Color.red) - .font(.caption) - case .disconnected: - Label("disconnected", systemImage: "chart.bar") - .foregroundColor(Color.red) - .font(.caption) - default: - Label("disconnected", systemImage: "chart.bar") - .foregroundColor(Color.red) - .font(.caption) + ProfilePicturesOverlappedView(indvAvatarWidth: CGFloat(35), users: convoUsers) + .padding(.leading, 20) + .padding(.trailing, 10) + + // meta data of convo + VStack (alignment: .leading) { + ConvoUsernames(users: convoUsers) + + switch self.convoVM.connectionState { + case .connecting: + Label("connecting", systemImage: "chart.bar") + .foregroundColor(Color.orange) + .font(.caption) + case .connected: + Label("connected", systemImage: "chart.bar.fill") + .foregroundColor(Color.green) + .font(.caption) + case .reconnecting: + Label("reconnecting", systemImage: "chart.bar") + .foregroundColor(Color.orange) + .font(.caption) + case .failed: + Label("failed", systemImage: "chart.bar") + .foregroundColor(Color.red) + .font(.caption) + case .disconnected: + Label("disconnected", systemImage: "chart.bar") + .foregroundColor(Color.red) + .font(.caption) + default: + Label("disconnected", systemImage: "chart.bar") + .foregroundColor(Color.red) + .font(.caption) + } + + Text(self.convoRelativeTime) + .font(.caption2) + .foregroundColor(.gray) } - Text(self.convoRelativeTime) - .font(.caption2) - .foregroundColor(.gray) - } - - Spacer() - - // disconnect button - Button { - print("showing more info about the chat") + Spacer() - // show a sheet of the members in the call and add them if I want + // disconnect button + Button { + print("showing more info about the chat") + + // show a sheet of the members in the call and add them if I want + + } label: { + Label("attendees", systemImage: "person.2.circle.fill") + .labelStyle(.iconOnly) + .foregroundColor(NirvanaColor.teal) + .font(.title2) + .padding(.trailing, 5) + } - } label: { - Label("attendees", systemImage: "person.2.circle.fill") - .labelStyle(.iconOnly) - .foregroundColor(NirvanaColor.teal) - .font(.title2) - .padding(.trailing, 5) + // disconnect button + Button { + print("disconnecting user now ") + + self.convoVM.leaveConvo() + + // show success or failure toast + } label: { + Label("Call", systemImage: "powerplug.fill") + .labelStyle(.iconOnly) + .foregroundColor(Color.orange) + .font(.title2) + .padding(.trailing, 5) + } } - - // disconnect button - Button { - print("disconnecting user now ") - - self.convoVM.leaveConvo() - - // show success or failure toast - } label: { - Label("Call", systemImage: "powerplug.fill") - .labelStyle(.iconOnly) - .foregroundColor(Color.orange) - .font(.title2) - .padding(.trailing, 5) - } - } .frame(maxWidth: .infinity, maxHeight: 60) // 60 is the height of the footer control big circle .background(Color.white.opacity(0.5)) @@ -105,17 +111,20 @@ struct ConvoFooterView: View { x:0, y:self.convoVM.selectedConvoId == nil ? 150 : 0 ) - .onChange(of: self.convoVM.selectedConvoId) {newConvo in + .onReceive(self.convoVM.$selectedConvoId) {newConvoId in // update meta data based on which convo was selected // reset the selected options to start fresh -// self.convoRelativeTime = "" + self.convoRelativeTime = "" + + self.selectedConvo = self.convoVM.relevantConvos.first {convo in + convo.id == newConvoId + } // get relative start time of convo -// let formatter = RelativeDateTimeFormatter() -// formatter.unitsStyle = .full -// -// let relativeDate = formatter.localizedString(for: ?.sentTimestamp ?? Date(), relativeTo: Date()) + let formatter = RelativeDateTimeFormatter() + formatter.unitsStyle = .full + self.convoRelativeTime = formatter.localizedString(for: self.selectedConvo?.startedTimestamp ?? Date(), relativeTo: Date()) } } } @@ -125,3 +134,14 @@ struct ConvoFooterView_Previews: PreviewProvider { ConvoFooterView() } } + +struct ConvoUsernames: View { + var users: [User] + + var body: some View { + let userNames = self.users.map{$0.nickname ?? ""}.joined(separator: ",") + Text(userNames) + .font(.footnote) + .foregroundColor(NirvanaColor.light) + } +} diff --git a/nirvana-ios/Views/Convos/ConvosView.swift b/nirvana-ios/Views/Convos/ConvosView.swift index 2edb1b8..67ddb11 100644 --- a/nirvana-ios/Views/Convos/ConvosView.swift +++ b/nirvana-ios/Views/Convos/ConvosView.swift @@ -7,67 +7,70 @@ import SwiftUI -struct ConvosView: View { - @EnvironmentObject var vm: ConvoViewModel - @State var animate = false - - var body: some View { - ScrollView([.horizontal]) { - HStack { - ForEach(0..