Skip to content

Commit

Permalink
feat: added login and register capebility in discovery for pre login …
Browse files Browse the repository at this point in the history
…exploration
  • Loading branch information
saeedbashir committed Dec 11, 2023
1 parent e7eb4c8 commit 57529b6
Show file tree
Hide file tree
Showing 24 changed files with 596 additions and 446 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public struct SignInView: View {
if !viewModel.config.features.startupScreenEnabled {
Button(AuthLocalization.SignIn.registerBtn) {
viewModel.trackSignUpClicked()
viewModel.router.showRegisterScreen()
viewModel.router.showRegisterScreen(sourceScreen: viewModel.sourceScreen)
}.foregroundColor(Theme.Colors.accentColor)

Spacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class SignInViewModel: ObservableObject {
@Published private(set) var isShowProgress = false
@Published private(set) var showError: Bool = false
@Published private(set) var showAlert: Bool = false
public var sourceScreen: LogistrationSourceScreen = .default

var errorMessage: String? {
didSet {
withAnimation {
Expand Down Expand Up @@ -77,7 +79,7 @@ public class SignInViewModel: ObservableObject {
let user = try await interactor.login(username: username, password: password)
analytics.setUserID("\(user.id)")
analytics.userLogin(method: .password)
router.showMainOrWhatsNewScreen()
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)
} catch let error {
failure(error)
}
Expand Down Expand Up @@ -108,7 +110,7 @@ public class SignInViewModel: ObservableObject {
let user = try await interactor.login(externalToken: externalToken, backend: backend)
analytics.setUserID("\(user.id)")
analytics.userLogin(method: authMethod)
router.showMainOrWhatsNewScreen()
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)
} catch let error {
failure(error, authMethod: authMethod)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class SignUpViewModel: ObservableObject {
@Published var scrollTo: Int?
@Published var showError: Bool = false
@Published var thirdPartyAuthSuccess: Bool = false
public var sourceScreen: LogistrationSourceScreen = .default

var errorMessage: String? {
didSet {
withAnimation {
Expand Down Expand Up @@ -114,7 +116,7 @@ public class SignUpViewModel: ObservableObject {
analytics.setUserID("\(user.id)")
analytics.registrationSuccess()
isShowProgress = false
router.showMainOrWhatsNewScreen()
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)

} catch let error {
isShowProgress = false
Expand Down Expand Up @@ -171,7 +173,7 @@ public class SignUpViewModel: ObservableObject {
analytics.setUserID("\(user.id)")
analytics.userLogin(method: authMethod)
isShowProgress = false
router.showMainOrWhatsNewScreen()
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)
} catch {
update(fullName: response.name, email: response.email)
self.externalToken = response.token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@ import Theme
public struct LogistrationBottomView: View {
@ObservedObject
private var viewModel: StartupViewModel
private var sourceScreen: LogistrationSourceScreen

@Environment(\.isHorizontal) private var isHorizontal

public init(viewModel: StartupViewModel) {
public init(viewModel: StartupViewModel, sourceScreen: LogistrationSourceScreen) {
self.viewModel = viewModel
self.sourceScreen = sourceScreen
}

public var body: some View {
VStack(alignment: .leading) {
HStack(spacing: 24) {
StyledButton(AuthLocalization.SignIn.registerBtn) {
viewModel.router.showRegisterScreen()
viewModel.router.showRegisterScreen(sourceScreen: sourceScreen)
viewModel.tracksignUpClicked()
}
.frame(maxWidth: .infinity)

StyledButton(
AuthLocalization.SignIn.logInTitle,
action: { viewModel.router.showLoginScreen() },
action: { viewModel.router.showLoginScreen(sourceScreen: sourceScreen) },
color: .white,
textColor: Theme.Colors.accentColor,
borderColor: Theme.Colors.textInputStroke
Expand All @@ -52,12 +54,12 @@ struct LogistrationBottomView_Previews: PreviewProvider {
router: AuthorizationRouterMock(),
analytics: AuthorizationAnalyticsMock()
)
LogistrationBottomView(viewModel: vm)
LogistrationBottomView(viewModel: vm, sourceScreen: .startup)
.preferredColorScheme(.light)
.previewDisplayName("StartupView Light")
.loadFonts()

LogistrationBottomView(viewModel: vm)
LogistrationBottomView(viewModel: vm, sourceScreen: .startup)
.preferredColorScheme(.dark)
.previewDisplayName("StartupView Dark")
.loadFonts()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public struct StartupView: View {
.padding(.top, 1)
TextField(AuthLocalization.Startup.searchPlaceholder, text: $searchQuery, onCommit: {
if searchQuery.isEmpty { return }
viewModel.router.showDiscoveryScreen(searchQuery: searchQuery, fromStartupScreen: true)
viewModel.router.showDiscoveryScreen(
searchQuery: searchQuery,
sourceScreen: LogistrationSourceScreen.startup
)
})
.autocapitalization(.none)
.autocorrectionDisabled()
Expand All @@ -71,7 +74,10 @@ public struct StartupView: View {
)

Button {
viewModel.router.showDiscoveryScreen(searchQuery: searchQuery, fromStartupScreen: true)
viewModel.router.showDiscoveryScreen (
searchQuery: searchQuery,
sourceScreen: LogistrationSourceScreen.startup
)
} label: {
Text(AuthLocalization.Startup.exploreAllCourses)
.underline()
Expand All @@ -83,7 +89,7 @@ public struct StartupView: View {
}
.padding(.horizontal, isHorizontal ? 10 : 24)

LogistrationBottomView(viewModel: viewModel)
LogistrationBottomView(viewModel: viewModel, sourceScreen: .startup)
}
.padding(.top, 10)
.padding(.bottom, 2)
Expand Down
Loading

0 comments on commit 57529b6

Please sign in to comment.