Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
chore: handle delay from enrollment
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Umer committed Sep 21, 2023
1 parent 692d7dc commit dc1cf4d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
8 changes: 5 additions & 3 deletions Source/NewCourseDashboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ class NewCourseDashboardViewController: UIViewController, InterfaceOrientationOv
private let environment: Environment
let courseID: String
private let screen: CourseUpgradeScreen = .courseDashboard
private let fromEnrollment: Bool

init(environment: Environment, courseID: String) {
init(environment: Environment, courseID: String, fromEnrollment: Bool = false) {
self.environment = environment
self.courseID = courseID
self.fromEnrollment = fromEnrollment
self.courseStream = BackedStream<UserCourseEnrollment>()
self.loadStateController = LoadStateViewController()
super.init(nibName: nil, bundle: nil)
Expand All @@ -104,10 +106,10 @@ class NewCourseDashboardViewController: UIViewController, InterfaceOrientationOv
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
addSubviews()

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
let delay = fromEnrollment ? 0.5 : 0
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
self?.loadCourseStream()
}

}

override func viewWillAppear(_ animated: Bool) {
Expand Down
2 changes: 1 addition & 1 deletion Source/OEXCourseInfoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ - (void)parseURL:(NSURL*)url getCourseID:(NSString* __autoreleasing*)courseID em
}

- (void)showMainScreenWithMessage:(NSString*)message courseID:(NSString*)courseID {
[self.environment.router showMyCoursesAnimated:YES pushingCourseWithID:courseID];
[self.environment.router showMyCoursesWithAnimated:YES pushingCourseWithID:courseID fromEnrollment:YES];
[self performSelector:@selector(postEnrollmentSuccessNotification:) withObject:message afterDelay:0.5];
}

Expand Down
10 changes: 5 additions & 5 deletions Source/OEXRouter+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,16 @@ extension OEXRouter {
return controllerForBlockWithID(blockID: block.blockID, type: block.displayType, courseID: courseID, gated: block.isGated, shouldCelebrationAppear: shouldCelebrationAppear)
}

@objc(showMyCoursesAnimated:pushingCourseWithID:) func showMyCourses(animated: Bool = true, pushingCourseWithID courseID: String? = nil) {
@objc func showMyCourses(animated: Bool = true, pushingCourseWithID courseID: String? = nil, fromEnrollment: Bool = false) {
let controller = EnrolledTabBarViewController(environment: environment)
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, fromEnrollment: fromEnrollment)
}
}

@objc func showEnrolledTabBarView() {
@objc func showEnrolledTabBarView() {
let controller = EnrolledTabBarViewController(environment: environment)
showContentStack(withRootController: controller, animated: false)
}
Expand Down Expand Up @@ -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, fromEnrollment: Bool = false, completion: ((UIViewController) -> Void)? = nil) {
if environment.config.isNewDashboardEnabled {
let courseDashboardViewController = NewCourseDashboardViewController(environment: environment, courseID: courseID)
let courseDashboardViewController = NewCourseDashboardViewController(environment: environment, courseID: courseID, fromEnrollment: fromEnrollment)
let controller = ForwardingNavigationController(rootViewController: courseDashboardViewController)
controller.navigationController?.setNavigationBarHidden(true, animated: false)
controller.modalPresentationStyle = .fullScreen
Expand Down
2 changes: 1 addition & 1 deletion Source/WebView/DiscoveryHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ enum WebviewActions: String {
}

private class func showMainScreen(with message: String, and courseId: String, from controller: UIViewController) {
OEXRouter.shared().showMyCourses(animated: true, pushingCourseWithID: courseId)
OEXRouter.shared().showMyCourses(animated: true, pushingCourseWithID: courseId, fromEnrollment: controller is OEXCourseInfoViewController ? true : false)
let delay = DispatchTime.now() + Double(Int64(0.5 * TimeInterval(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
DispatchQueue.main.asyncAfter(deadline: delay) {
postEnrollmentSuccessNotification(message: message, from: controller)
Expand Down

0 comments on commit dc1cf4d

Please sign in to comment.