From efa50da9bded5ee7a0acc52abd315f95aa345c1c Mon Sep 17 00:00:00 2001 From: Volodymyr Chekyrta Date: Thu, 1 Jun 2023 14:34:29 +0300 Subject: [PATCH] Fix dashboard empty state --- Dashboard/Dashboard/Presentation/DashboardView.swift | 10 +++------- .../Dashboard/Presentation/DashboardViewModel.swift | 9 +++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Dashboard/Dashboard/Presentation/DashboardView.swift b/Dashboard/Dashboard/Presentation/DashboardView.swift index d353148cf..78e3c802a 100644 --- a/Dashboard/Dashboard/Presentation/DashboardView.swift +++ b/Dashboard/Dashboard/Presentation/DashboardView.swift @@ -44,11 +44,9 @@ public struct DashboardView: View { ZStack { RefreshableScrollViewCompat(action: { - await viewModel.getMyCourses(page: 1, - withProgress: isIOS14, - refresh: true) + await viewModel.getMyCourses(page: 1, refresh: true) }) { - if !viewModel.fetchInProgress || viewModel.courses.isEmpty { + if viewModel.courses.isEmpty && !viewModel.fetchInProgress { EmptyPageIcon() } else { LazyVStack(spacing: 0) { @@ -104,9 +102,7 @@ public struct DashboardView: View { // MARK: - Offline mode SnackBar OfflineSnackBarView(connectivity: viewModel.connectivity, reloadAction: { - await viewModel.getMyCourses( page: 1, - withProgress: isIOS14, - refresh: true) + await viewModel.getMyCourses(page: 1, refresh: true) }) // MARK: - Error Alert diff --git a/Dashboard/Dashboard/Presentation/DashboardViewModel.swift b/Dashboard/Dashboard/Presentation/DashboardViewModel.swift index 1b5711508..0ffe9a547 100644 --- a/Dashboard/Dashboard/Presentation/DashboardViewModel.swift +++ b/Dashboard/Dashboard/Presentation/DashboardViewModel.swift @@ -14,7 +14,7 @@ public class DashboardViewModel: ObservableObject { public var nextPage = 1 public var totalPages = 1 - public private(set) var fetchInProgress = false + @Published public private(set) var fetchInProgress = false @Published var courses: [CourseItem] = [] @Published var showError: Bool = false @@ -46,8 +46,9 @@ public class DashboardViewModel: ObservableObject { } @MainActor - public func getMyCourses(page: Int, withProgress: Bool = true, refresh: Bool = false) async { + public func getMyCourses(page: Int, refresh: Bool = false) async { do { + fetchInProgress = true if connectivity.isInternetAvaliable { if refresh { courses = try await interactor.getMyCourses(page: page) @@ -77,13 +78,13 @@ public class DashboardViewModel: ObservableObject { } @MainActor - public func getMyCoursesPagination(index: Int, withProgress: Bool = true) async { + public func getMyCoursesPagination(index: Int) async { if !fetchInProgress { if totalPages > 1 { if index == courses.count - 3 { if totalPages != 1 { if nextPage <= totalPages { - await getMyCourses(page: self.nextPage, withProgress: withProgress) + await getMyCourses(page: self.nextPage) } } }