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

Commit

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

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

let delay = fromEnrollment ? 0.5 : 0
let delay = newEnrollment ? 0.5 : 0
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
self?.loadCourseStream()
}
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 showMyCoursesWithAnimated:YES pushingCourseWithID:courseID fromEnrollment:YES];
[self.environment.router showMyCoursesAnimated:YES pushingCourseWithID:courseID];
[self performSelector:@selector(postEnrollmentSuccessNotification:) withObject:message afterDelay:0.5];
}

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

@objc func showMyCourses(animated: Bool = true, pushingCourseWithID courseID: String? = nil, fromEnrollment: Bool = false) {
@objc(showMyCoursesAnimated:pushingCourseWithID:) func showMyCourses(animated: Bool = true, pushingCourseWithID courseID: String? = nil) {
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, fromEnrollment: fromEnrollment)
showCourseWithID(courseID: courseID, fromController: learnController, animated: false, newEnrollment: true)
}
}

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, fromEnrollment: Bool = false, 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, fromEnrollment: fromEnrollment)
let courseDashboardViewController = NewCourseDashboardViewController(environment: environment, courseID: courseID, newEnrollment: newEnrollment)
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, fromEnrollment: controller is OEXCourseInfoViewController ? true : false)
OEXRouter.shared().showMyCourses(animated: true, pushingCourseWithID: courseId)
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 838e0b8

Please sign in to comment.