Skip to content

Commit

Permalink
chore: changes
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedbashir committed Jan 8, 2024
1 parent 86f83b1 commit 3f4fef5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 38 deletions.
12 changes: 10 additions & 2 deletions Course/Course/Presentation/Details/CourseDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ private struct CourseStateView: View {
case .enrollOpen:
StyledButton(CourseLocalization.Details.enrollNow, action: {
if !viewModel.userloggedIn {
viewModel.router.showRegisterScreen(sourceScreen: .courseDetail(courseDetails.courseID, courseDetails.courseTitle))
viewModel.router.showRegisterScreen(
sourceScreen: .courseDetail(
courseDetails.courseID,
courseDetails.courseTitle)
)
} else {
Task {
await viewModel.enrollToCourse(id: courseDetails.courseID)
Expand All @@ -238,7 +242,11 @@ private struct CourseStateView: View {
case .alreadyEnrolled:
StyledButton(CourseLocalization.Details.viewCourse, action: {
if !viewModel.userloggedIn {
viewModel.router.showRegisterScreen(sourceScreen: .courseDetail(courseDetails.courseID, courseDetails.courseTitle))
viewModel.router.showRegisterScreen(
sourceScreen: .courseDetail(
courseDetails.courseID,
courseDetails.courseTitle)
)
} else {
viewModel.viewCourseClicked(
courseId: courseDetails.courseID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,8 @@ public class DiscoveryWebviewModel: ObservableObject {
}

@MainActor
func getCourseDetail(courseID: String) async {
do {
if connectivity.isInternetAvaliable {
courseDetails = try await interactor.getCourseDetails(courseID: courseID)
} else {
courseDetails = try await interactor.getLoadedCourseDetails(courseID: courseID)
}
} catch let error {
if error.isInternetError || error is NoCachedDataError {
errorMessage = CoreLocalization.Error.slowOrNoInternetConnection
} else {
errorMessage = CoreLocalization.Error.unknownError
}
}
func getCourseDetail(courseID: String) async throws -> CourseDetails? {
return try await interactor.getCourseDetails(courseID: courseID)
}

@MainActor
Expand All @@ -79,10 +67,21 @@ public class DiscoveryWebviewModel: ObservableObject {
router.showRegisterScreen(sourceScreen: .discovery)
return
}

showProgress = true
// analytics.courseEnrollClicked(courseId: id, courseName: courseDetails?.courseTitle ?? "")
courseDetails = try await getCourseDetail(courseID: courseID)

if courseDetails?.isEnrolled ?? false || courseState == .alreadyEnrolled {
showProgress = false
showCourseDetails()
return
}

let courseAnalytics = Container.shared.resolve(CourseAnalytics.self)

courseAnalytics?.courseEnrollClicked(courseId: courseID, courseName: courseDetails?.courseTitle ?? "")
_ = try await interactor.enrollToCourse(courseID: courseID)
// analytics.courseEnrollSuccess(courseId: id, courseName: courseDetails?.courseTitle ?? "")
courseAnalytics?.courseEnrollSuccess(courseId: courseID, courseName: courseDetails?.courseTitle ?? "")
courseDetails?.isEnrolled = true
showProgress = false
NotificationCenter.default.post(name: .onCourseEnrolled, object: courseID)
Expand Down Expand Up @@ -139,8 +138,8 @@ extension DiscoveryWebviewModel: WebViewNavigationDelegate {
if let url = request.url, outsideLink || capturedLink || externalLink, UIApplication.shared.canOpenURL(url) {
DispatchQueue.main.async { [weak self] in
self?.router.presentAlert(
alertTitle: "Leaving the app",
alertMessage: "You are now leaving the app and opening a browser",
alertTitle: DiscoveryLocalization.Alert.leavingAppTitle,
alertMessage: DiscoveryLocalization.Alert.leavingAppMessage,
positiveAction: CoreLocalization.Webview.Alert.continue,
onCloseTapped: {
self?.router.dismiss(animated: true)
Expand All @@ -164,16 +163,11 @@ extension DiscoveryWebviewModel: WebViewNavigationDelegate {
private func handleNavigation(url: URL, urlAction: WebviewActions) -> Bool {
switch urlAction {
case .courseEnrollment:
if courseDetails?.isEnrolled ?? false || courseState == .alreadyEnrolled {
return showCourseDetails()
} else {
if let urlData = parse(url: url), let courseID = urlData.courseId {
Task {
await enrollTo(courseID: courseID)
}
if let urlData = parse(url: url), let courseID = urlData.courseId {
Task {
await enrollTo(courseID: courseID)
}
}

case .courseDetail:
guard let pathID = detailPathID(from: url) else { return false }
router.showWebDiscoveryDetails(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ public struct DiscoveryWebview: View {
if let url = URL(string: URLString) {
viewModel.request = URLRequest(url: url)
}

if case .courseDetail(let pathID) = discoveryType {
Task {
let components = pathID.components(separatedBy: "/")
if let courseID = components.last {
await viewModel.getCourseDetail(courseID: courseID)
}
}
}
}

public var body: some View {
Expand Down Expand Up @@ -186,7 +177,6 @@ public struct DiscoveryWebview: View {
}

fileprivate extension String {

func contains(find: String) -> Bool {
return range(of: find) != nil
}
Expand Down
6 changes: 6 additions & 0 deletions Discovery/Discovery/SwiftGen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public enum DiscoveryLocalization {
public static let updateRequiredTitle = DiscoveryLocalization.tr("Localizable", "UPDATE_REQUIRED_TITLE", fallback: "App Update Required")
/// Why do I need to update?
public static let updateWhyNeed = DiscoveryLocalization.tr("Localizable", "UPDATE_WHY_NEED", fallback: "Why do I need to update?")
public enum Alert {
/// You are now leaving the app and opening a browser
public static let leavingAppMessage = DiscoveryLocalization.tr("Localizable", "ALERT.LEAVING_APP_MESSAGE", fallback: "You are now leaving the app and opening a browser")
/// Leaving the app
public static let leavingAppTitle = DiscoveryLocalization.tr("Localizable", "ALERT.LEAVING_APP_TITLE", fallback: "Leaving the app")
}
public enum Header {
/// Discover new
public static let title1 = DiscoveryLocalization.tr("Localizable", "HEADER.TITLE_1", fallback: "Discover new")
Expand Down
3 changes: 3 additions & 0 deletions Discovery/Discovery/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@
"UPDATE_NEEDED_NOT_NOW" = "Not Now";

"UPDATE_NEW_AVALIABLE" = "New update available! Upgrade now to receive the latest features and fixes";

"ALERT.LEAVING_APP_TITLE" = "Leaving the app";
"ALERT.LEAVING_APP_MESSAGE" = "You are now leaving the app and opening a browser";
3 changes: 3 additions & 0 deletions Discovery/Discovery/uk.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@
"UPDATE_NEEDED_NOT_NOW" = "Не зараз";

"UPDATE_NEW_AVALIABLE" = "Доступне нове оновлення! Оновіть зараз, щоб отримати найновіші функції та виправлення";

"ALERT.LEAVING_APP_TITLE" = "Leaving the app";
"ALERT.LEAVING_APP_MESSAGE" = "You are now leaving the app and opening a browser";

0 comments on commit 3f4fef5

Please sign in to comment.