From d53e988ea67131755321a5f8a53ef1683837c57e Mon Sep 17 00:00:00 2001 From: Volodymyr Chekyrta Date: Thu, 10 Aug 2023 12:16:33 +0300 Subject: [PATCH] Codestyle --- .../Presentation/DiscoveryView.swift | 62 ++++++++++--------- .../Presentation/DiscoveryViewModel.swift | 8 ++- .../xcschemes/OpenEdXStage.xcscheme | 4 +- OpenEdX/View/MainScreenView.swift | 56 ++++++++--------- 4 files changed, 69 insertions(+), 61 deletions(-) diff --git a/Discovery/Discovery/Presentation/DiscoveryView.swift b/Discovery/Discovery/Presentation/DiscoveryView.swift index 098e56763..194805ed8 100644 --- a/Discovery/Discovery/Presentation/DiscoveryView.swift +++ b/Discovery/Discovery/Presentation/DiscoveryView.swift @@ -27,9 +27,6 @@ public struct DiscoveryView: View { public init(viewModel: DiscoveryViewModel, router: DiscoveryRouter) { self.viewModel = viewModel self.router = router - Task { - await viewModel.discovery(page: 1) - } } public var body: some View { @@ -83,25 +80,28 @@ public struct DiscoveryView: View { .padding(.bottom, 20) Spacer() }.padding(.leading, 10) - ForEach(Array(viewModel.courses.enumerated()), - id: \.offset) { index, course in - CourseCellView(model: course, - type: .discovery, - index: index, - cellsCount: viewModel.courses.count) - .padding(.horizontal, 24) - .onAppear { - Task { - await viewModel.getDiscoveryCourses(index: index) + ForEach(Array(viewModel.courses.enumerated()), id: \.offset) { index, course in + CourseCellView( + model: course, + type: .discovery, + index: index, + cellsCount: viewModel.courses.count + ).padding(.horizontal, 24) + .onAppear { + Task { + await viewModel.getDiscoveryCourses(index: index) + } + } + .onTapGesture { + viewModel.discoveryCourseClicked( + courseID: course.courseID, + courseName: course.name + ) + router.showCourseDetais( + courseID: course.courseID, + title: course.name + ) } - } - .onTapGesture { - viewModel.discoveryCourseClicked(courseID: course.courseID, courseName: course.name) - router.showCourseDetais( - courseID: course.courseID, - title: course.name - ) - } } // MARK: - ProgressBar @@ -119,13 +119,14 @@ public struct DiscoveryView: View { } // MARK: - Offline mode SnackBar - OfflineSnackBarView(connectivity: viewModel.connectivity, - reloadAction: { - viewModel.courses = [] - viewModel.totalPages = 1 - viewModel.nextPage = 1 - await viewModel.discovery(page: 1, withProgress: isIOS14) - }) + OfflineSnackBarView( + connectivity: viewModel.connectivity, + reloadAction: { + viewModel.courses = [] + viewModel.totalPages = 1 + viewModel.nextPage = 1 + await viewModel.discovery(page: 1, withProgress: isIOS14) + }) // MARK: - Error Alert if viewModel.showError { @@ -143,6 +144,11 @@ public struct DiscoveryView: View { } } } + .onFirstAppear { + Task { + await viewModel.discovery(page: 1) + } + } .background(Theme.Colors.background.ignoresSafeArea()) } } diff --git a/Discovery/Discovery/Presentation/DiscoveryViewModel.swift b/Discovery/Discovery/Presentation/DiscoveryViewModel.swift index c99e2e3f8..568a37a9b 100644 --- a/Discovery/Discovery/Presentation/DiscoveryViewModel.swift +++ b/Discovery/Discovery/Presentation/DiscoveryViewModel.swift @@ -30,9 +30,11 @@ public class DiscoveryViewModel: ObservableObject { private let interactor: DiscoveryInteractorProtocol private let analytics: DiscoveryAnalytics - public init(interactor: DiscoveryInteractorProtocol, - connectivity: ConnectivityProtocol, - analytics: DiscoveryAnalytics) { + public init( + interactor: DiscoveryInteractorProtocol, + connectivity: ConnectivityProtocol, + analytics: DiscoveryAnalytics + ) { self.interactor = interactor self.connectivity = connectivity self.analytics = analytics diff --git a/OpenEdX.xcodeproj/xcshareddata/xcschemes/OpenEdXStage.xcscheme b/OpenEdX.xcodeproj/xcshareddata/xcschemes/OpenEdXStage.xcscheme index 7fdd234a2..8e378a196 100644 --- a/OpenEdX.xcodeproj/xcshareddata/xcschemes/OpenEdXStage.xcscheme +++ b/OpenEdX.xcodeproj/xcshareddata/xcschemes/OpenEdXStage.xcscheme @@ -101,8 +101,8 @@ String { - switch selection { - case .discovery: - return DiscoveryLocalization.title - case .dashboard: - return DashboardLocalization.title - case .programs: - return CoreLocalization.Mainscreen.programs - case .profile: - return ProfileLocalization.title - } - } - enum MainTab { case discovery case dashboard @@ -37,7 +24,7 @@ struct MainScreenView: View { case profile } - let analytics = Container.shared.resolve(MainScreenAnalytics.self)! + private let analytics = Container.shared.resolve(MainScreenAnalytics.self)! init() { UITabBar.appearance().isTranslucent = false @@ -57,7 +44,7 @@ struct MainScreenView: View { Text(CoreLocalization.Mainscreen.discovery) } .tag(MainTab.discovery) - + VStack { DashboardView( viewModel: Container.shared.resolve(DashboardViewModel.self)!, @@ -78,7 +65,7 @@ struct MainScreenView: View { Text(CoreLocalization.Mainscreen.programs) } .tag(MainTab.programs) - + VStack { ProfileView( viewModel: Container.shared.resolve(ProfileViewModel.self)! @@ -93,18 +80,31 @@ struct MainScreenView: View { .navigationBarHidden(selection == .profile) .navigationBarBackButtonHidden(false) .navigationTitle(titleBar()) - .onChange(of: selection, perform: { selection in - switch selection { - case .discovery: - analytics.mainDiscoveryTabClicked() - case .dashboard: - analytics.mainDashboardTabClicked() - case .programs: - analytics.mainProgramsTabClicked() - case .profile: - analytics.mainProfileTabClicked() - } - }) + .onChange(of: selection, perform: { selection in + switch selection { + case .discovery: + analytics.mainDiscoveryTabClicked() + case .dashboard: + analytics.mainDashboardTabClicked() + case .programs: + analytics.mainProgramsTabClicked() + case .profile: + analytics.mainProfileTabClicked() + } + }) + } + + private func titleBar() -> String { + switch selection { + case .discovery: + return DiscoveryLocalization.title + case .dashboard: + return DashboardLocalization.title + case .programs: + return CoreLocalization.Mainscreen.programs + case .profile: + return ProfileLocalization.title + } } struct MainScreenView_Previews: PreviewProvider {