Skip to content

Commit

Permalink
fix: blink of empty courses screens on enrolled courses list view (#1810
Browse files Browse the repository at this point in the history
)
  • Loading branch information
saeedbashir committed Oct 19, 2023
1 parent 7116c8f commit 1783ff3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Source/CoursesContainerViewController.swift
Expand Up @@ -143,6 +143,8 @@ class CoursesContainerViewController: UICollectionViewController, ScrollableDele
let auditModeCourses = courses.filter { valuePropEnabled(for: $0) }
isAuditModeCourseAvailable = !auditModeCourses.isEmpty
}

canShowEmptyScreen = courses.isEmpty
}
}

Expand All @@ -153,8 +155,11 @@ class CoursesContainerViewController: UICollectionViewController, ScrollableDele
}

private var shouldShowFooter: Bool {
return context == .enrollmentList && isDiscoveryEnabled && courses.isEmpty
return context == .enrollmentList && isDiscoveryEnabled && canShowEmptyScreen
}

//Empty Screen should be shown after fetching the enrollments API
var canShowEmptyScreen: Bool = false

init(environment: Environment, context: Context) {
self.environment = environment
Expand Down Expand Up @@ -299,6 +304,11 @@ class CoursesContainerViewController: UICollectionViewController, ScrollableDele
}
}

func showEmptyScreen(show: Bool = true) {
canShowEmptyScreen = show
collectionView.reloadData()
}

func removeErrorView() {
if view.subviews.contains(errorView) {
errorView.removeFromSuperview()
Expand Down
5 changes: 4 additions & 1 deletion Source/EnrolledCoursesViewController.swift
Expand Up @@ -147,12 +147,12 @@ class EnrolledCoursesViewController : OfflineSupportViewController, InterfaceOri
self?.coursesContainer.removeErrorView()
self?.coursesContainer.courses = enrollments.compactMap { $0.course }
self?.coursesContainer.collectionView.reloadData()
self?.loadController.state = .Loaded
self?.handleUpgradationLoader(success: true)

if enrollments.isEmpty {
self?.enrollmentsEmptyState()
}
self?.loadController.state = .Loaded
}
else {
self?.loadController.state = .Initial
Expand Down Expand Up @@ -194,6 +194,9 @@ class EnrolledCoursesViewController : OfflineSupportViewController, InterfaceOri
let error = NSError.oex_error(with: .unknown, message: Strings.EnrollmentList.noEnrollment)
loadController.state = LoadState.failed(error: error, icon: Icon.UnknownError)
}
else {
coursesContainer.showEmptyScreen()
}
}

private func setupObservers() {
Expand Down

0 comments on commit 1783ff3

Please sign in to comment.