From ea47ab2a0dd0bde4f9dcbc3cf7715235dae6427d Mon Sep 17 00:00:00 2001 From: talksik Date: Sun, 2 Jan 2022 02:08:29 -0800 Subject: [PATCH] adding alerts --- nirvana-ios/Views/Convos/ConvoViewModel.swift | 15 ++++++++++----- .../Views/InnerCircle/CircleGridView.swift | 17 +++++++++++++---- .../Views/InnerCircle/InnerCircleView.swift | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/nirvana-ios/Views/Convos/ConvoViewModel.swift b/nirvana-ios/Views/Convos/ConvoViewModel.swift index e7fc6dc..9b82635 100644 --- a/nirvana-ios/Views/Convos/ConvoViewModel.swift +++ b/nirvana-ios/Views/Convos/ConvoViewModel.swift @@ -27,11 +27,16 @@ class ConvoViewModel: NSObject, ObservableObject { case convoNotFound case probSettingUpConvo case cantAddThirdParty + case friendNotOnline + case alreadyInCall case generalError var view: AlertToast { switch self { + case .alreadyInCall: + return AlertToast(displayMode: .hud, type: .error(Color.orange), title: "Leave your current convo first!") + case .friendNotOnline: case .connecting: return AlertToast(displayMode: .hud, type: .systemImage("sensor.tag.radiowaves.forward.fill", NirvanaColor.dimTeal), title: "Connecting") case .disconnected: @@ -47,15 +52,15 @@ class ConvoViewModel: NSObject, ObservableObject { case .successfullyJoined: return AlertToast(displayMode: .hud, type: .complete(Color.green), title: "joined convo") case .probSettingUpConvo: - return AlertToast(displayMode: .hud, type: .error(Color.red), title: "Problem setting up convo ‼️") + return AlertToast(displayMode: .hud, type: .error(Color.orange), title: "Problem setting up convo ‼️") case .maxLimitUsers: - return AlertToast(displayMode: .hud, type: .error(Color.red), title: "The convo is full! Sorry! 😞") + return AlertToast(displayMode: .hud, type: .error(Color.orange), title: "The convo is full! Sorry! 😞") case .notAuthenticated: - return AlertToast(displayMode: .hud, type: .error(Color.red), title: "Not authenticated ‼️") + return AlertToast(displayMode: .hud, type: .error(Color.orange), title: "Not authenticated ‼️") case .generalError: - return AlertToast(displayMode: .hud, type: .error(Color.red), title: "Something went wrong ‼️") + return AlertToast(displayMode: .hud, type: .error(Color.orange), title: "Something went wrong ‼️") default: - return AlertToast(displayMode: .hud, type: .error(Color.red), title: "Something went wrong ‼️") + return AlertToast(displayMode: .hud, type: .error(Color.orange), title: "Something went wrong ‼️") } } } diff --git a/nirvana-ios/Views/InnerCircle/CircleGridView.swift b/nirvana-ios/Views/InnerCircle/CircleGridView.swift index 11d290d..c8304a1 100644 --- a/nirvana-ios/Views/InnerCircle/CircleGridView.swift +++ b/nirvana-ios/Views/InnerCircle/CircleGridView.swift @@ -133,6 +133,9 @@ struct CircleGridView: View { } } + else { + self.convoVM.toast = .alreadyInCall + } } // .animation( // Animation.easeInOut(duration: 4).repeatForever(autoreverses: true), @@ -183,7 +186,9 @@ struct CircleGridView: View { .gesture( LongPressGesture(minimumDuration: longPressMinDuration) .onEnded {_ in // on activation of long press - // if in a call, I cannot record or select someone...strict rules on user if in a call + print("activated long press!") + + // if in a convo, I don't want to have user footer show up if self.convoVM.isInCall() { print("can't select another friend because I am in a call...leave call first") return @@ -192,7 +197,7 @@ struct CircleGridView: View { // stop any player still playing of a message self.queuePlayer.removeAllItems() - print("activated long press!") + self.selectedFriendIndex = friendId // TODO: haptics stopped working again @@ -466,7 +471,7 @@ extension CircleGridView { extension CircleGridView { // listening to messages private func handleTap(gridItemIndex: Int, friendId: String) { - print("tap gesture activated") + print("tap gesture activated") // if friend and I are online, and I am not in a convo, start convo immediately with them if self.authSessionStore.relevantUsersDict[friendId]?.userStatus == .online @@ -488,8 +493,12 @@ extension CircleGridView { return } // if I am in a convo, don't allow listening to a message or expanding details of a friend in my circle + // also can't add friend who is not online else if self.convoVM.isInCall() { - print("can't select this friend as you are in a convo") + print("can't select this friend as you are in a convo and they are not online") + + self.convoVM.toast = .friendNotOnline + return } diff --git a/nirvana-ios/Views/InnerCircle/InnerCircleView.swift b/nirvana-ios/Views/InnerCircle/InnerCircleView.swift index 492970f..891f0d0 100644 --- a/nirvana-ios/Views/InnerCircle/InnerCircleView.swift +++ b/nirvana-ios/Views/InnerCircle/InnerCircleView.swift @@ -150,7 +150,7 @@ struct InnerCircleView: View { // set status of user to online self.authSessionStore.updateUserStatus(userStatus: .online) } - .toast(isPresenting: self.$convoViewModel.showToast) { + .toast(isPresenting: self.$convoViewModel.showToast, duration: 2) { self.convoViewModel.toast?.view ?? AlertToast(displayMode: .hud, type: .error(Color.red), title: "Something went wrong") } // .onDisappear {