From 1a7c7bcc915bfdd2f949b4f48bf2a538bcdd9f09 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Mon, 28 Feb 2022 18:30:36 -0800 Subject: [PATCH] initialize apple profile view modal outside of view init --- .../Registration/NewAppleSignupView.swift | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Registration/NewAppleSignupView.swift b/apple/OmnivoreKit/Sources/App/Views/Registration/NewAppleSignupView.swift index 9529f06f7..d24298116 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Registration/NewAppleSignupView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Registration/NewAppleSignupView.swift @@ -6,16 +6,13 @@ import Utils import Views final class NewAppleSignupViewModel: ObservableObject { - let userProfile: UserProfile @Published var loginError: LoginError? var subscriptions = Set() - init(userProfile: UserProfile) { - self.userProfile = userProfile - } + init() {} - func submitProfile(authenticator: Authenticator) { + func submitProfile(userProfile: UserProfile, authenticator: Authenticator) { authenticator .createAccount(userProfile: userProfile).sink( receiveCompletion: { [weak self] completion in @@ -30,14 +27,10 @@ final class NewAppleSignupViewModel: ObservableObject { struct NewAppleSignupView: View { @EnvironmentObject var authenticator: Authenticator - @StateObject private var viewModel: NewAppleSignupViewModel + @StateObject private var viewModel = NewAppleSignupViewModel() + let userProfile: UserProfile let showProfileEditView: () -> Void - init(userProfile: UserProfile, showProfileEditView: @escaping () -> Void) { - self.showProfileEditView = showProfileEditView - self._viewModel = StateObject(wrappedValue: NewAppleSignupViewModel(userProfile: userProfile)) - } - var body: some View { VStack(spacing: 28) { Text("Welcome to Omnivore!") @@ -48,14 +41,14 @@ struct NewAppleSignupView: View { Text("Your username is:") .font(.appBody) .foregroundColor(.appGrayText) - Text("@\(viewModel.userProfile.username)") + Text("@\(userProfile.username)") .font(.appHeadline) .foregroundColor(.appGrayText) } VStack { Button( - action: { viewModel.submitProfile(authenticator: authenticator) }, + action: { viewModel.submitProfile(userProfile: userProfile, authenticator: authenticator) }, label: { Text("Continue") } ) .buttonStyle(SolidCapsuleButtonStyle(color: .appDeepBackground, width: 300))