fixing things all around
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
89288ECB27675B9F00E962C4 /* OnboardingTemplateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89288ECA27675B9F00E962C4 /* OnboardingTemplateView.swift */; };
|
||||
894E80BE276ED7A700624B72 /* avatars.swift in Sources */ = {isa = PBXBuildFile; fileRef = 894E80BD276ED7A700624B72 /* avatars.swift */; };
|
||||
894E80C1276EFD0500624B72 /* AudioPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 894E80C0276EFD0400624B72 /* AudioPlayerView.swift */; };
|
||||
894E80C327702E5900624B72 /* AddBasicInfoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 894E80C227702E5800624B72 /* AddBasicInfoViewModel.swift */; };
|
||||
89AD5573276DD790001658E0 /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89AD5572276DD790001658E0 /* SplashView.swift */; };
|
||||
89AD5575276DE724001658E0 /* PhoneCodeVerificationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89AD5574276DE724001658E0 /* PhoneCodeVerificationView.swift */; };
|
||||
89AD5578276DEAB3001658E0 /* LogoHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89AD5577276DEAB3001658E0 /* LogoHeaderView.swift */; };
|
||||
@@ -94,6 +95,7 @@
|
||||
89288ECA27675B9F00E962C4 /* OnboardingTemplateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingTemplateView.swift; sourceTree = "<group>"; };
|
||||
894E80BD276ED7A700624B72 /* avatars.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = avatars.swift; sourceTree = "<group>"; };
|
||||
894E80C0276EFD0400624B72 /* AudioPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayerView.swift; sourceTree = "<group>"; };
|
||||
894E80C227702E5800624B72 /* AddBasicInfoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddBasicInfoViewModel.swift; sourceTree = "<group>"; };
|
||||
89AD5572276DD790001658E0 /* SplashView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashView.swift; sourceTree = "<group>"; };
|
||||
89AD5574276DE724001658E0 /* PhoneCodeVerificationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneCodeVerificationView.swift; sourceTree = "<group>"; };
|
||||
89AD5577276DEAB3001658E0 /* LogoHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoHeaderView.swift; sourceTree = "<group>"; };
|
||||
@@ -398,6 +400,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
89F18AF4276ECF2A00115B1E /* AddBasicInfoView.swift */,
|
||||
894E80C227702E5800624B72 /* AddBasicInfoViewModel.swift */,
|
||||
);
|
||||
path = AddBasicInfo;
|
||||
sourceTree = "<group>";
|
||||
@@ -507,6 +510,7 @@
|
||||
89BCABEB276D2A09009E9B10 /* PhoneVerificationView.swift in Sources */,
|
||||
892179E62765FECD001E6C60 /* FooterControlsViewModel.swift in Sources */,
|
||||
891A15F5276557AB00B26659 /* colors.swift in Sources */,
|
||||
894E80C327702E5900624B72 /* AddBasicInfoViewModel.swift in Sources */,
|
||||
89288ECB27675B9F00E962C4 /* OnboardingTemplateView.swift in Sources */,
|
||||
89F05BA4276ACC060002E9C7 /* ContactService.swift in Sources */,
|
||||
89B46E71276893E200B74255 /* AuthSessionStore.swift in Sources */,
|
||||
|
||||
@@ -40,17 +40,17 @@ class FirestoreService {
|
||||
}
|
||||
}
|
||||
|
||||
func updateUser(user: User) -> ServiceState {
|
||||
func updateUser(user: User, completion: @escaping((_ state: ServiceState) -> ())) {
|
||||
do {
|
||||
if user.id != nil {
|
||||
let _ = try db.collection(Collection.users.rawValue).document(user.id!).setData(from: user)
|
||||
return ServiceState.success("Updated user in firestore service")
|
||||
completion(ServiceState.success("Updated user in firestore service"))
|
||||
} else {
|
||||
return ServiceState.error(ServiceError(description: "No user id given to firestore service"))
|
||||
completion(ServiceState.error(ServiceError(description: "No user id given to firestore service")))
|
||||
}
|
||||
} catch {
|
||||
print("error in creating user \(error.localizedDescription)")
|
||||
return ServiceState.error(ServiceError(description: error.localizedDescription))
|
||||
completion(ServiceState.error(ServiceError(description: error.localizedDescription)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,10 @@ import NavigationStack
|
||||
|
||||
struct AddBasicInfoView: View {
|
||||
@EnvironmentObject var navigationStack : NavigationStack
|
||||
@EnvironmentObject var authSessionStore: AuthSessionStore
|
||||
@ObservedObject var addInfoViewModel: AddBasicInfoViewModel = AddBasicInfoViewModel()
|
||||
|
||||
@State var username = ""
|
||||
|
||||
@State var nickname = ""
|
||||
@State var selectedAvatarIndex: Int = 0
|
||||
|
||||
var columns: [GridItem] =
|
||||
@@ -80,7 +81,7 @@ struct AddBasicInfoView: View {
|
||||
|
||||
// input nickname
|
||||
VStack {
|
||||
TextField("Nickname", text: self.$username)
|
||||
TextField("Nickname", text: self.$nickname)
|
||||
.padding()
|
||||
.background(.ultraThinMaterial)
|
||||
.clipShape(Capsule())
|
||||
@@ -89,7 +90,7 @@ struct AddBasicInfoView: View {
|
||||
.font(.subheadline)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
Text("What does your mom or friends call you?")
|
||||
Text("What does your friends call you?")
|
||||
.font(.footnote)
|
||||
.foregroundColor(Color.black.opacity(0.7))
|
||||
|
||||
@@ -101,26 +102,25 @@ struct AddBasicInfoView: View {
|
||||
|
||||
// button to save information
|
||||
Button {
|
||||
if self.username.count == 0 {
|
||||
print("do nothing...user didn't input anything...maybe show an alert")
|
||||
return
|
||||
print("attempting to save information")
|
||||
var updatedUser = self.authSessionStore.user
|
||||
updatedUser?.avatar = Avatars.avatarSystemNames[self.selectedAvatarIndex]
|
||||
updatedUser?.nickname = self.nickname
|
||||
|
||||
// TODO: I need these updated attributes to be listened to when loading the circle hub next
|
||||
|
||||
if updatedUser != nil {
|
||||
self.addInfoViewModel.updateUser(currUser: updatedUser!)
|
||||
}
|
||||
|
||||
print("saving information")
|
||||
|
||||
// activate loading splashscreen
|
||||
|
||||
// let view model do work of saving to firestore
|
||||
|
||||
// note: I need these updated attributes to be listened to when loading the circle hub next
|
||||
// but maybe just change the data in cache and no need to re-fetch
|
||||
self.navigationStack.push(InnerCircleView())
|
||||
} label: {
|
||||
Text("Save")
|
||||
.fontWeight(.heavy)
|
||||
.foregroundColor(Color.white)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 20)
|
||||
.background(self.username.count == 0 ? Color.white.opacity(0.3) : NirvanaColor.teal)
|
||||
.background(self.nickname.count == 0 ? Color.white.opacity(0.3) : NirvanaColor.teal)
|
||||
.clipShape(Capsule())
|
||||
.shadow(radius:10)
|
||||
}
|
||||
@@ -129,6 +129,13 @@ struct AddBasicInfoView: View {
|
||||
}
|
||||
.frame(maxHeight: .infinity)
|
||||
}
|
||||
//TODO: hook up the alert with the view model
|
||||
// .alert(isPresented: Binding<Bool>(
|
||||
// get: { self.addInfoViewModel.state == ProfileRegistrationState.failed},
|
||||
// set: { _ in self.addInfoViewModel.state = ProfileRegistrationState.na }
|
||||
// )) {
|
||||
// Alert(title: Text("Important message"), message: Text("Wear sunscreen"), dismissButton: .default(Text("Got it!")))
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// AddBasicInfoViewModel.swift
|
||||
// nirvana-ios
|
||||
//
|
||||
// Created by Arjun Patel on 12/19/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum ProfileRegistrationState {
|
||||
case successful
|
||||
case failed(String)
|
||||
case loading
|
||||
case na
|
||||
}
|
||||
|
||||
class AddBasicInfoViewModel : ObservableObject {
|
||||
@Published var state: ProfileRegistrationState = .na
|
||||
private var firestoreService = FirestoreService()
|
||||
|
||||
// - get user data current data
|
||||
// - save user selections
|
||||
func updateUser(currUser: User) {
|
||||
// validations
|
||||
// make sure nickname is less than 25 characters for now
|
||||
|
||||
self.state = .loading
|
||||
|
||||
if currUser.nickname == nil || currUser.avatar == nil {
|
||||
self.state = .failed("Please make sure to select avatar and nickname 🙏")
|
||||
return
|
||||
}
|
||||
if currUser.nickname!.count > 25 {
|
||||
self.state = .failed("Please use a simpler nickname less than 25 characters 🙏")
|
||||
return
|
||||
}
|
||||
if !Avatars.avatarSystemNames.contains(currUser.avatar!) {
|
||||
self.state = .failed("Invalid avatar selected!")
|
||||
return
|
||||
}
|
||||
|
||||
// save in firestore
|
||||
self.firestoreService.updateUser(user: currUser) {res in
|
||||
switch res {
|
||||
case .success:
|
||||
self.state = .successful
|
||||
case .error(let error):
|
||||
self.state = .failed(error.description)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,8 +39,9 @@ final class PhoneVerificationViewModel : ObservableObject {
|
||||
// assign to nil so that server can fill it in
|
||||
user!.lastLoggedInTimestamp = nil
|
||||
|
||||
let res = self?.firestoreService.updateUser(user: user!)
|
||||
print(res)
|
||||
self?.firestoreService.updateUser(user: user!) {res in
|
||||
print(res)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user