From 099c86e76d2151e4bf26ff34ed4a4d9718e5286c Mon Sep 17 00:00:00 2001 From: Muhammad Umer Date: Thu, 21 Sep 2023 14:31:21 +0100 Subject: [PATCH] fix: fix course loading after enrolling a course (#1801) --- Source/NewCourseDashboardViewController.swift | 10 ++++++++-- Source/OEXRouter+Swift.swift | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Source/NewCourseDashboardViewController.swift b/Source/NewCourseDashboardViewController.swift index e44259bf6..413acd01a 100644 --- a/Source/NewCourseDashboardViewController.swift +++ b/Source/NewCourseDashboardViewController.swift @@ -85,10 +85,12 @@ class NewCourseDashboardViewController: UIViewController, InterfaceOrientationOv private let environment: Environment let courseID: String private let screen: CourseUpgradeScreen = .courseDashboard + private let newEnrollment: Bool - init(environment: Environment, courseID: String) { + init(environment: Environment, courseID: String, newEnrollment: Bool = false) { self.environment = environment self.courseID = courseID + self.newEnrollment = newEnrollment self.courseStream = BackedStream() self.loadStateController = LoadStateViewController() super.init(nibName: nil, bundle: nil) @@ -103,7 +105,11 @@ class NewCourseDashboardViewController: UIViewController, InterfaceOrientationOv navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil) addSubviews() - loadCourseStream() + + let delay = newEnrollment ? 0.5 : 0 + DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in + self?.loadCourseStream() + } } override func viewWillAppear(_ animated: Bool) { diff --git a/Source/OEXRouter+Swift.swift b/Source/OEXRouter+Swift.swift index df140d465..4774164d9 100644 --- a/Source/OEXRouter+Swift.swift +++ b/Source/OEXRouter+Swift.swift @@ -215,11 +215,11 @@ extension OEXRouter { let learnController = controller.children.flatMap { $0.children }.compactMap { $0 as? LearnContainerViewController } .first showContentStack(withRootController: controller, animated: animated) if let courseID = courseID, let learnController = learnController { - showCourseWithID(courseID: courseID, fromController: learnController, animated: false) + showCourseWithID(courseID: courseID, fromController: learnController, animated: false, newEnrollment: true) } } - @objc func showEnrolledTabBarView() { + @objc func showEnrolledTabBarView() { let controller = EnrolledTabBarViewController(environment: environment) showContentStack(withRootController: controller, animated: false) } @@ -560,9 +560,9 @@ extension OEXRouter { c.loadRequest(request: URLRequest(url: url as URL) as NSURLRequest) } - func showCourseWithID(courseID: String, fromController: UIViewController, animated: Bool = true, completion: ((UIViewController) -> Void)? = nil) { + func showCourseWithID(courseID: String, fromController: UIViewController, animated: Bool = true, newEnrollment: Bool = false, completion: ((UIViewController) -> Void)? = nil) { if environment.config.isNewDashboardEnabled { - let courseDashboardViewController = NewCourseDashboardViewController(environment: environment, courseID: courseID) + let courseDashboardViewController = NewCourseDashboardViewController(environment: environment, courseID: courseID, newEnrollment: newEnrollment) let controller = ForwardingNavigationController(rootViewController: courseDashboardViewController) controller.navigationController?.setNavigationBarHidden(true, animated: false) controller.modalPresentationStyle = .fullScreen