commiting changes to user and such without the breaking changes
This commit is contained in:
@@ -7,9 +7,8 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
// dummy parent navigation page to test out all pages for now
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
// @State private var selectedView: NavigationViews? = NavigationViews.welcomeView
|
@EnvironmentObject var authSession: AuthSessionStore
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
@@ -21,18 +20,17 @@ struct ContentView: View {
|
|||||||
NavigationLink(destination: HomeView()) {
|
NavigationLink(destination: HomeView()) {
|
||||||
Text("Home Page")
|
Text("Home Page")
|
||||||
}
|
}
|
||||||
|
|
||||||
NavigationLink(destination: WelcomeView()) {
|
|
||||||
Text("Onboarding - 1")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.navigationBarTitle("View All Pages", displayMode: .inline)
|
.navigationBarTitle("View All Pages", displayMode: .inline)
|
||||||
|
}.onAppear(perform: self.getUser)
|
||||||
}
|
|
||||||
|
|
||||||
// .navigationViewStyle(StackNavigationViewStyle())
|
// .navigationViewStyle(StackNavigationViewStyle())
|
||||||
// .environmentObject()//can pass anything to send to all views within navigation view
|
// .environmentObject()//can pass anything to send to all views within navigation view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getUser () {
|
||||||
|
authSession.listen()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ContentView_Previews: PreviewProvider {
|
struct ContentView_Previews: PreviewProvider {
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// AuthSessionStore.swift
|
||||||
|
// nirvana-ios
|
||||||
|
//
|
||||||
|
// Created by Arjun Patel on 12/13/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import Firebase
|
||||||
|
import Combine
|
||||||
|
|
||||||
|
class AuthSessionStore : ObservableObject {
|
||||||
|
@Published public var firebaseUser : User?
|
||||||
|
private var handle: AuthStateDidChangeListenerHandle?
|
||||||
|
|
||||||
|
func listen() {
|
||||||
|
// monitor authentication changes using firebase
|
||||||
|
handle = Auth.auth().addStateDidChangeListener { (auth, user) in
|
||||||
|
if let user = user {
|
||||||
|
// if we have a user, create a new user model
|
||||||
|
print("Got user: \(user)")
|
||||||
|
self.firebaseUser = User(
|
||||||
|
_uid: user.uid, _email: user.email, _displayName: user.displayName, _profilePic: user.photoURL, _phoneNumber: user.phoneNumber)
|
||||||
|
} else {
|
||||||
|
// if we don't have a user, set our session to nil
|
||||||
|
self.firebaseUser = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,23 @@ import Foundation
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct User: Identifiable, Hashable {
|
struct User: Identifiable, Hashable {
|
||||||
|
var id:String = UUID().uuidString
|
||||||
|
var email:String?
|
||||||
|
var displayName:String?
|
||||||
|
var profilePictureUrl:URL?
|
||||||
|
var phoneNumber:String?
|
||||||
|
|
||||||
|
init(_uid:String = UUID().uuidString, _email:String?, _displayName:String?, _profilePic:URL?, _phoneNumber: String?) {
|
||||||
|
self.id = _uid
|
||||||
|
self.email = _email
|
||||||
|
self.profilePictureUrl = _profilePic
|
||||||
|
self.displayName = _displayName
|
||||||
|
self.phoneNumber = _phoneNumber
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct TestUser: Identifiable, Hashable {
|
||||||
var id = UUID().uuidString
|
var id = UUID().uuidString
|
||||||
|
|
||||||
var profilePictureUrl:String
|
var profilePictureUrl:String
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ struct ChatsCarouselView: View {
|
|||||||
@StateObject var viewModel:ChatsCarouselViewModel = ChatsCarouselViewModel()
|
@StateObject var viewModel:ChatsCarouselViewModel = ChatsCarouselViewModel()
|
||||||
// current snapped/selected user
|
// current snapped/selected user
|
||||||
@State var selectedUserId: String = ""
|
@State var selectedUserId: String = ""
|
||||||
@State var selectedUser: User?
|
@State var selectedUser: TestUser?
|
||||||
|
|
||||||
func getSelectedUser(userId: String) -> User {
|
func getSelectedUser(userId: String) -> TestUser {
|
||||||
return self.viewModel.carouselUsers.filter{user in
|
return self.viewModel.carouselUsers.filter{user in
|
||||||
return user.id == userId
|
return user.id == userId
|
||||||
}[0]
|
}[0]
|
||||||
|
|||||||
@@ -8,15 +8,15 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
final class ChatsCarouselViewModel: ObservableObject {
|
final class ChatsCarouselViewModel: ObservableObject {
|
||||||
@Published var carouselUsers:[User]
|
@Published var carouselUsers:[TestUser]
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
self.carouselUsers = [
|
self.carouselUsers = [
|
||||||
User(_profilePic: "liam", _firstN: "Liam", _lastN: "Digregorio"),
|
TestUser(_profilePic: "liam", _firstN: "Liam", _lastN: "Digregorio"),
|
||||||
User(_profilePic: "heran", _firstN: "Heran", _lastN: "Patel"),
|
TestUser(_profilePic: "heran", _firstN: "Heran", _lastN: "Patel"),
|
||||||
User(_profilePic: "sarth", _firstN: "Sarth", _lastN: "Shah"),
|
TestUser(_profilePic: "sarth", _firstN: "Sarth", _lastN: "Shah"),
|
||||||
User(_profilePic: "kevin", _firstN: "Kevin", _lastN: "Le"),
|
TestUser(_profilePic: "kevin", _firstN: "Kevin", _lastN: "Le"),
|
||||||
User(_profilePic: "rohan", _firstN: "Rohan", _lastN: "Chadha")
|
TestUser(_profilePic: "rohan", _firstN: "Rohan", _lastN: "Chadha")
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user