From 1783ff3fafad8df0abb22c63cf6ac12996686062 Mon Sep 17 00:00:00 2001 From: Saeed Bashir Date: Thu, 19 Oct 2023 14:11:54 +0500 Subject: [PATCH] fix: blink of empty courses screens on enrolled courses list view (#1810) --- Source/CoursesContainerViewController.swift | 12 +++++++++++- Source/EnrolledCoursesViewController.swift | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Source/CoursesContainerViewController.swift b/Source/CoursesContainerViewController.swift index 596601ff0..b07979ebb 100644 --- a/Source/CoursesContainerViewController.swift +++ b/Source/CoursesContainerViewController.swift @@ -143,6 +143,8 @@ class CoursesContainerViewController: UICollectionViewController, ScrollableDele let auditModeCourses = courses.filter { valuePropEnabled(for: $0) } isAuditModeCourseAvailable = !auditModeCourses.isEmpty } + + canShowEmptyScreen = courses.isEmpty } } @@ -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 @@ -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() diff --git a/Source/EnrolledCoursesViewController.swift b/Source/EnrolledCoursesViewController.swift index d1f7c95ff..4fcc55aac 100644 --- a/Source/EnrolledCoursesViewController.swift +++ b/Source/EnrolledCoursesViewController.swift @@ -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 @@ -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() {