Skip to content

Commit

Permalink
refactor: address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedbashir committed Nov 24, 2023
1 parent 8454926 commit 8b748c8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ public struct LogistrationBottomView: View {
}
.frame(maxWidth: .infinity)

StyledButton(AuthLocalization.SignIn.logInTitle,
action: { viewModel.router.showLoginScreen() },
color: .white,
textColor: Theme.Colors.accentColor,
borderColor: Theme.Colors.textInputStroke
StyledButton(
AuthLocalization.SignIn.logInTitle,
action: { viewModel.router.showLoginScreen() },
color: .white,
textColor: Theme.Colors.accentColor,
borderColor: Theme.Colors.textInputStroke
)
.frame(width: 100)
}
Expand Down
22 changes: 13 additions & 9 deletions Discovery/Discovery/Presentation/DiscoveryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public struct DiscoveryView: View {
@StateObject
private var viewModel: DiscoveryViewModel
private var router: DiscoveryRouter
@State private var searchQuery: String = ""
@State private var isRefreshing: Bool = false

private var fromStartupScreen: Bool = false
Expand All @@ -31,11 +32,16 @@ public struct DiscoveryView: View {
.accessibilityElement(children: .ignore)
.accessibilityLabel(DiscoveryLocalization.Header.title1 + DiscoveryLocalization.Header.title2)

public init(viewModel: DiscoveryViewModel, router: DiscoveryRouter, searchQuery: String? = nil, fromStartupScreen: Bool = false) {
public init(
viewModel: DiscoveryViewModel,
router: DiscoveryRouter,
searchQuery: String? = nil,
fromStartupScreen: Bool = false
) {
self._viewModel = StateObject(wrappedValue: { viewModel }())
self.router = router
self.fromStartupScreen = fromStartupScreen
viewModel.searchQuery = searchQuery
self._searchQuery = State<String>(initialValue: searchQuery ?? "")
}

public var body: some View {
Expand All @@ -54,7 +60,7 @@ public struct DiscoveryView: View {
Spacer()
}
.onTapGesture {
router.showDiscoverySearch(searchQuery: viewModel.searchQuery)
router.showDiscoverySearch(searchQuery: searchQuery)
viewModel.discoverySearchBarClicked()
}
.frame(minHeight: 48)
Expand All @@ -68,7 +74,7 @@ public struct DiscoveryView: View {
.stroke(lineWidth: 1)
.fill(Theme.Colors.textInputUnfocusedStroke)
).onTapGesture {
router.showDiscoverySearch(searchQuery: viewModel.searchQuery)
router.showDiscoverySearch(searchQuery: searchQuery)
viewModel.discoverySearchBarClicked()
}
.padding(.top, 11.5)
Expand Down Expand Up @@ -156,17 +162,15 @@ public struct DiscoveryView: View {
}
.navigationBarHidden(fromStartupScreen ? false : true)
.onFirstAppear {
if !(viewModel.searchQuery?.isEmpty ?? true) {
router.showDiscoverySearch(searchQuery: viewModel.searchQuery)
if !(searchQuery.isEmpty) {
router.showDiscoverySearch(searchQuery: searchQuery)
searchQuery = ""
}
Task {
await viewModel.discovery(page: 1)
}
viewModel.setupNotifications()
}
.onDisappear {
viewModel.searchQuery = ""
}
.background(Theme.Colors.background.ignoresSafeArea())
}
}
Expand Down
1 change: 0 additions & 1 deletion Discovery/Discovery/Presentation/DiscoveryViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class DiscoveryViewModel: ObservableObject {

@Published var courses: [CourseItem] = []
@Published var showError: Bool = false
@Published var searchQuery: String?

var errorMessage: String? {
didSet {
Expand Down
1 change: 0 additions & 1 deletion OpenEdX/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public class Router: AuthorizationRouter,
}

public func showStartupScreen() {

if let config = Container.shared.resolve(ConfigProtocol.self), config.features.startupScreenEnabled {
let view = StartupView(viewModel: Container.shared.resolve(StartupViewModel.self)!)
let controller = UIHostingController(rootView: view)
Expand Down

0 comments on commit 8b748c8

Please sign in to comment.