Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dashboard empty state #36

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions Dashboard/Dashboard/Presentation/DashboardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions Dashboard/Dashboard/Presentation/DashboardViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
Expand Down