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,23 +8,18 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct User: Identifiable, Hashable {
|
public struct User: Codable {
|
||||||
var id:String = UUID().uuidString
|
let id: String
|
||||||
var email:String?
|
let firstName: String
|
||||||
var displayName:String?
|
let lastName: String?
|
||||||
var profilePictureUrl:URL?
|
let phoneNumber: String?
|
||||||
var phoneNumber:String?
|
let emailAddress:String?
|
||||||
|
let avatar:String?
|
||||||
|
|
||||||
init(_uid:String = UUID().uuidString, _email:String?, _displayName:String?, _profilePic:URL?, _phoneNumber: String?) {
|
let lastLoggedInTimestamp: Date
|
||||||
self.id = _uid
|
let createdTimestamp: Date
|
||||||
self.email = _email
|
|
||||||
self.profilePictureUrl = _profilePic
|
|
||||||
self.displayName = _displayName
|
|
||||||
self.phoneNumber = _phoneNumber
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct TestUser: Identifiable, Hashable {
|
struct TestUser: Identifiable, Hashable {
|
||||||
var id = UUID().uuidString
|
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
|
//setting in key storage
|
||||||
UserDefaults.standard.set(true, forKey: "authVerificationID")
|
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
|
// firebase either created a new user or is giving back an existing user's id
|
||||||
let userId = res?.user.uid
|
let userId = res?.user.uid
|
||||||
let userPhoneNumber = res?.user.phoneNumber
|
let userPhoneNumber = res?.user.phoneNumber
|
||||||
print("user id that was authenticated is: \(userId)")
|
print("user id that was authenticated is: \(userId)")
|
||||||
print("user id that was authenticated is: \(userPhoneNumber)")
|
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
|
// then sending to next page
|
||||||
self.navigationStack.push(OnboardingTrioView()) // verify code page
|
self.navigationStack.push(OnboardingTrioView()) // verify code page
|
||||||
|
|||||||
@@ -13,31 +13,10 @@ final class PhoneVerificationViewModel : ObservableObject {
|
|||||||
public func verifyPhoneAndSendSMS(phoneNumber: String) {
|
public func verifyPhoneAndSendSMS(phoneNumber: String) {
|
||||||
// TODO: do some string validation here
|
// TODO: do some string validation here
|
||||||
// do auth stuff from firebase
|
// 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 {
|
extension String {
|
||||||
|
|||||||
@@ -8,67 +8,18 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct HeaderView: View {
|
struct HeaderView: View {
|
||||||
@EnvironmentObject var authStore:AuthSessionStore
|
|
||||||
@State var averageColor: UIColor = UIColor(NirvanaColor.teal)
|
|
||||||
@State var showingMenu: Bool = false
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if authStore.sessionState == SessionState.isLoggedOut {
|
HStack {
|
||||||
HStack {
|
Image("undraw_handcrafts_leaf")
|
||||||
Image("undraw_handcrafts_leaf")
|
.resizable()
|
||||||
.resizable()
|
.frame(width: 20.0, height: 32.132)
|
||||||
.frame(width: 20.0, height: 32.132)
|
|
||||||
|
|
||||||
Text("nirvana")
|
Text("nirvana")
|
||||||
.font(Font.custom("Satisfy-Regular", size: 35))
|
.font(Font.custom("Satisfy-Regular", size: 35))
|
||||||
.foregroundColor(NirvanaColor.teal)
|
.foregroundColor(NirvanaColor.teal)
|
||||||
.multilineTextAlignment(.center)
|
.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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setAverageColor() {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct HeaderView_Previews: PreviewProvider {
|
struct HeaderView_Previews: PreviewProvider {
|
||||||
|
|||||||
Reference in New Issue
Block a user