setting up one way of doing alerts

This commit is contained in:
talksik
2022-01-01 22:55:25 -08:00
parent f1e1ab785c
commit 7c21f53183
2 changed files with 23 additions and 1 deletions
@@ -8,10 +8,29 @@
import Foundation
import AgoraRtcKit
import Firebase
import SwiftUI
class ConvoViewModel: NSObject, ObservableObject {
enum Error: Identifiable {
var id: Self { self }
case notAuthenticated
case maxLimitUsers
case convoNotFound
var alert: Alert {
switch self {
case .notAuthenticated:
return Alert(title: Text("Not Authenticated!"))
default:
return Alert(title: Text("There was a problem"))
}
}
}
@Published var selectedConvoId:String? = nil
@Published var connectionState: AgoraConnectionStateType?
@Published var error: Error?
let firestoreService = FirestoreService()
private var db = Firestore.firestore()
@@ -464,3 +483,4 @@ extension ConvoViewModel: AgoraRtcEngineDelegate {
self.selectedConvoId = nil
}
}
@@ -337,6 +337,9 @@ struct CircleGridView: View {
}
self.animateLiveConvos = true
}// univseral alert TODO: move to inner circle view and use this pattern for all view models
.alert(item: self.$convoVM.error) {error in
error.alert
}
} // scrollview reader
}
@@ -485,7 +488,6 @@ 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
else if self.convoVM.isInCall() {
// TODO: show toast
print("can't select this friend as you are in a convo")
return
}