starting firestore stuff
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
//
|
||||
// Firestore.swift
|
||||
// nirvana-ios
|
||||
//
|
||||
// Created by Arjun Patel on 12/15/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public class Firestore {
|
||||
// public struct User: Codable {
|
||||
// let id: String
|
||||
// let firstName: String
|
||||
// let lastName: String?
|
||||
// let mainPhoneNumber: String?
|
||||
// let emailAddress:String?
|
||||
// let photoUrl:String?
|
||||
//
|
||||
// let lastLoggedInTimestamp: Date
|
||||
// let createdTimestamp: Date
|
||||
// }
|
||||
//
|
||||
// public struct Messages: Codable {
|
||||
// let id: String
|
||||
// let senderId: String
|
||||
// let receiverId: String
|
||||
//
|
||||
// let sentTimestamp:Date
|
||||
// let listenedTimestamp:Date
|
||||
// let audioDataUrl:String
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Messages.swift
|
||||
// nirvana-ios
|
||||
//
|
||||
// Created by Arjun Patel on 12/15/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct Messages: Codable {
|
||||
let id: String
|
||||
let senderId: String
|
||||
let receiverId: String
|
||||
|
||||
let sentTimestamp:Date
|
||||
let listenedTimestamp:Date
|
||||
let audioDataUrl:String
|
||||
}
|
||||
|
||||
|
||||
@@ -8,22 +8,17 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
public struct User: Codable {
|
||||
let id: String
|
||||
let firstName: String
|
||||
let lastName: String?
|
||||
let phoneNumber: String?
|
||||
let emailAddress:String?
|
||||
let avatar:String?
|
||||
|
||||
let lastLoggedInTimestamp: Date
|
||||
let createdTimestamp: Date
|
||||
}
|
||||
|
||||
struct TestUser: Identifiable, Hashable {
|
||||
var id = UUID().uuidString
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// FirestoreService.swift
|
||||
// nirvana-ios
|
||||
//
|
||||
// Created by Arjun Patel on 12/18/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Firebase
|
||||
import FirebaseStorage
|
||||
|
||||
class FirestoreService {
|
||||
enum Collections: String {
|
||||
case users = "users"
|
||||
case messages = "messages"
|
||||
case user_friends = "user_friends" // associating a user to
|
||||
}
|
||||
|
||||
private var db = Firestore.firestore()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// EditProfileView.swift
|
||||
// nirvana-ios
|
||||
//
|
||||
// Created by Arjun Patel on 12/18/21.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct EditProfileView: View {
|
||||
var body: some View {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
}
|
||||
|
||||
struct EditProfileView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
EditProfileView()
|
||||
}
|
||||
}
|
||||
@@ -92,14 +92,16 @@ struct PhoneCodeVerificationView: View {
|
||||
//setting in key storage
|
||||
UserDefaults.standard.set(true, forKey: "authVerificationID")
|
||||
|
||||
//TODO: is the auth listener going to find that this person signed in? idk test it
|
||||
|
||||
// firebase either created a new user or is giving back an existing user's id
|
||||
let userId = res?.user.uid
|
||||
let userPhoneNumber = res?.user.phoneNumber
|
||||
print("user id that was authenticated is: \(userId)")
|
||||
print("user id that was authenticated is: \(userPhoneNumber)")
|
||||
|
||||
|
||||
// get user from firestore using the firebase userid given,
|
||||
// if not there, create
|
||||
|
||||
|
||||
|
||||
// then sending to next page
|
||||
self.navigationStack.push(OnboardingTrioView()) // verify code page
|
||||
|
||||
@@ -13,31 +13,10 @@ final class PhoneVerificationViewModel : ObservableObject {
|
||||
public func verifyPhoneAndSendSMS(phoneNumber: String) {
|
||||
// TODO: do some string validation here
|
||||
// do auth stuff from firebase
|
||||
PhoneAuthProvider.provider()
|
||||
.verifyPhoneNumber(phoneNumber, uiDelegate: nil) { verificationID, error in
|
||||
print("firebase auth done, now running my callback")
|
||||
|
||||
// got a response...done loading... either error to show or next page
|
||||
// self.isLoading.toggle()
|
||||
|
||||
// problem verifying number showing alert...maybe fake number or something from user
|
||||
if error != nil {
|
||||
// self.toastText = "⚠️ Please try again."
|
||||
// self.toastSubMessage = "There was an issue validating your phone number"
|
||||
// self.showToast.toggle()
|
||||
|
||||
print((error?.localizedDescription)!)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// use this in the next screen to verify with the code provided
|
||||
UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
|
||||
|
||||
// self.navigationStack.push(PhoneCodeVerificationView()) // verify code page
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func
|
||||
}
|
||||
|
||||
extension String {
|
||||
|
||||
@@ -7,68 +7,19 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct HeaderView: View {
|
||||
@EnvironmentObject var authStore:AuthSessionStore
|
||||
@State var averageColor: UIColor = UIColor(NirvanaColor.teal)
|
||||
@State var showingMenu: Bool = false
|
||||
|
||||
struct HeaderView: View {
|
||||
var body: some View {
|
||||
if authStore.sessionState == SessionState.isLoggedOut {
|
||||
HStack {
|
||||
Image("undraw_handcrafts_leaf")
|
||||
.resizable()
|
||||
.frame(width: 20.0, height: 32.132)
|
||||
|
||||
Text("nirvana")
|
||||
.font(Font.custom("Satisfy-Regular", size: 35))
|
||||
.foregroundColor(NirvanaColor.teal)
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
} else {
|
||||
HStack(alignment:.center) {
|
||||
Image("undraw_handcrafts_leaf")
|
||||
.resizable()
|
||||
.frame(width: 20.0, height: 32.132)
|
||||
.padding(.leading, 20)
|
||||
|
||||
Spacer()
|
||||
|
||||
Menu {
|
||||
Button("Log out") {
|
||||
print("log out button clicked")
|
||||
self.authStore.logOut()
|
||||
}
|
||||
Button("Friends") {
|
||||
print("manage friends page")
|
||||
}
|
||||
} label: {
|
||||
RemoteImage(url: self.authStore.user?.profilePictureUrl?.absoluteString ?? "https://avatars.githubusercontent.com/u/41487836")
|
||||
.background(NirvanaColor.teal)
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(width: 40, height: 40)
|
||||
.clipShape(Circle())
|
||||
.padding(5)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
// .background(Color(self.averageColor)) // color based on user's profilepicture dominant color
|
||||
.background(NirvanaColor.solidBlue)
|
||||
.cornerRadius(100)
|
||||
.padding(.horizontal)
|
||||
.shadow(radius: 10)
|
||||
.onAppear{
|
||||
// set background color based on profile picture tint
|
||||
if let userPicUrl = authStore.user?.profilePictureUrl {
|
||||
if let avgColor = NirvanaImage.getAverageColor(url: userPicUrl.absoluteString) {
|
||||
self.averageColor = avgColor
|
||||
}
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
Image("undraw_handcrafts_leaf")
|
||||
.resizable()
|
||||
.frame(width: 20.0, height: 32.132)
|
||||
|
||||
Text("nirvana")
|
||||
.font(Font.custom("Satisfy-Regular", size: 35))
|
||||
.foregroundColor(NirvanaColor.teal)
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
}
|
||||
|
||||
private func setAverageColor() {
|
||||
}
|
||||
}
|
||||
|
||||
struct HeaderView_Previews: PreviewProvider {
|
||||
|
||||
Reference in New Issue
Block a user