diff --git a/PlayDate.xcworkspace/xcuserdata/dab.xcuserdatad/UserInterfaceState.xcuserstate b/PlayDate.xcworkspace/xcuserdata/dab.xcuserdatad/UserInterfaceState.xcuserstate index 23d94b8..6c784a4 100644 Binary files a/PlayDate.xcworkspace/xcuserdata/dab.xcuserdatad/UserInterfaceState.xcuserstate and b/PlayDate.xcworkspace/xcuserdata/dab.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/PlayDate.xcworkspace/xcuserdata/dab.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/PlayDate.xcworkspace/xcuserdata/dab.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 34fdfa2..c7edc16 100644 --- a/PlayDate.xcworkspace/xcuserdata/dab.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/PlayDate.xcworkspace/xcuserdata/dab.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,22 +3,4 @@ uuid = "5632179B-7279-4079-A847-17839EB4ABAC" type = "0" version = "2.0"> - - - - - - diff --git a/PlayDate/ViewControllers/Launch/PetProfileSetupViewController.swift b/PlayDate/ViewControllers/Launch/PetProfileSetupViewController.swift index de20cc1..9b00bb1 100644 --- a/PlayDate/ViewControllers/Launch/PetProfileSetupViewController.swift +++ b/PlayDate/ViewControllers/Launch/PetProfileSetupViewController.swift @@ -192,38 +192,61 @@ class PetProfileSetupViewController: UIViewController, UIImagePickerControllerDe addPicturesButton.addTarget(self, action: #selector(uploadPetPictures(_:)), for: .touchUpInside) // Done Button + doneButton.setContentHuggingPriority(.required, for: .vertical) + doneButton.setContentCompressionResistancePriority(.required, for: .vertical) verticalStackView.addArrangedSubview(doneButton) doneButton.addTarget(self, action: #selector(doDoneButton(_:)), for: .touchUpInside) - } @objc func doDoneButton(_ sender: UIButton) { - let petName = petNameTextField.text! - let petBio = petBioTextField.text! - let petAge = Int(petAgeTextField.text!)! - let petType = petTypeTextField.text! - let petSex = petSexTextField.text! - - let id = AuthManager.id! - let user = User(userID: id) - + guard let petName = petNameTextField.text else { + self.presentAlert(title: "Oops!", message: "Looks like you left Pet Name blank. Please fix and try again.") + return + } + guard let petBio = petBioTextField.text else { + self.presentAlert(title: "Oops!", message: "Looks like you left Pet Bio blank. Please fix and try again.") + return + } + guard let petAge = petAgeTextField.text else { + self.presentAlert(title: "Oops!", message: "Looks like you left Pet Age blank. Please fix and try again.") + return + } + guard let petAgeNum = Int(petAge) else { + self.presentAlert(title: "Oops!", message: "Pet Age needs to be a number. Please fix and try again.") + return + } + guard let petType = petTypeTextField.text else { + self.presentAlert(title: "Oops!", message: "Looks like you left Pet Type blank. Please fix and try again.") + return + } + guard let petSex = petSexTextField.text else { + self.presentAlert(title: "Oops!", message: "Looks like you left Pet Sex blank. Please fix and try again.") + return + } + guard let userId = AuthManager.id else { + self.presentAlert(title: "Oops!", message: "Something went wrong with registering. Please close app and try again.") + return + } + + // Need to update/add the user's pet here + let user = User(userID: userId) let pet = Pet() pet.updateName(name: petName) pet.updateBio(bio: petBio) - pet.updateAge(age: petAge) + pet.updateAge(age: petAgeNum) pet.updateType(type: petType) pet.updateSex(sex: petSex) //user.addPet(petID: pet) - let petSetupVC = PetProfileSetupViewController() - petSetupVC.modalPresentationStyle = .fullScreen - self.navigationController?.show(petSetupVC, sender: self) + let homeTBC = HomeTabBarController() + homeTBC.modalPresentationStyle = .fullScreen + self.navigationController?.present(homeTBC, animated: true) } @objc func doSkipButton(_ sender: UIButton) { let homeTBC = HomeTabBarController() homeTBC.modalPresentationStyle = .fullScreen - self.navigationController?.show(homeTBC, sender: self) + self.navigationController?.present(homeTBC, animated: true) } @objc func uploadPetPictures(_ sender: UIButton) { @@ -276,4 +299,9 @@ class PetProfileSetupViewController: UIViewController, UIImagePickerControllerDe view.endEditing(true) } + private func presentAlert(title: String, message: String) { + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil)) + self.present(alert, animated: true) + } } diff --git a/PlayDate/ViewControllers/Launch/UserProfileSetupViewController.swift b/PlayDate/ViewControllers/Launch/UserProfileSetupViewController.swift index 05c777d..ef95089 100644 --- a/PlayDate/ViewControllers/Launch/UserProfileSetupViewController.swift +++ b/PlayDate/ViewControllers/Launch/UserProfileSetupViewController.swift @@ -151,16 +151,31 @@ class UserProfileSetupViewController: UIViewController, UIImagePickerControllerD //This needs some kind of error handling ***GUS @objc func userToPetSetup(_ sender: UIButton) { - - let username:String = userSetupLabel.text! - let bio:String = userBioTextField.text! - let age:Int = Int(userAgeTextField.text!)! - - let id = AuthManager.id! - let user = User(userID: id) + guard let username = userSetupLabel.text else { + self.presentAlert(title: "Oops!", message: "Looks like you left Username blank. Please fix and try again.") + return + } + guard let bio = userBioTextField.text else { + self.presentAlert(title: "Oops!", message: "Looks like you left Bio blank. Please fix and try again.") + return + } + guard let age = userAgeTextField.text else { + self.presentAlert(title: "Oops!", message: "Looks like you left Age blank. Please fix and try again.") + return + } + guard let ageNum = Int(age) else { + self.presentAlert(title: "Oops!", message: "Age is supposed to be a number. Please fix and try again.") + return + } + guard let userId = AuthManager.id else { + self.presentAlert(title: "Oops!", message: "Something went wrong with registering. Please close app and try again.") + return + } + + let user = User(userID: userId) user.updateName(name: username) user.updateBio(bio: bio) - user.updateAge(age: age) + user.updateAge(age: ageNum) let petSetupVC = PetProfileSetupViewController() petSetupVC.modalPresentationStyle = .fullScreen @@ -216,5 +231,10 @@ class UserProfileSetupViewController: UIViewController, UIImagePickerControllerD @objc func dismissKeyboard() { view.endEditing(true) } - + + private func presentAlert(title: String, message: String) { + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil)) + self.present(alert, animated: true) + } } diff --git a/PlayDate/ViewControllers/Launch/UserRegisterViewController.swift b/PlayDate/ViewControllers/Launch/UserRegisterViewController.swift index 943a1ba..c0bc8b9 100644 --- a/PlayDate/ViewControllers/Launch/UserRegisterViewController.swift +++ b/PlayDate/ViewControllers/Launch/UserRegisterViewController.swift @@ -184,7 +184,9 @@ class UserRegisterViewController: UIViewController { let userSetupVC = UserProfileSetupViewController() userSetupVC.modalPresentationStyle = .fullScreen - strongSelf.present(userSetupVC, animated: true) + let navVC = UINavigationController(rootViewController: userSetupVC) + navVC.modalPresentationStyle = .fullScreen + strongSelf.navigationController?.present(navVC, animated: true) } else { // Need additional error labels for // other failure conditions.