Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: webview based discovery implementation #219

Merged
merged 15 commits into from
Jan 17, 2024

Conversation

saeedbashir
Copy link
Contributor

@saeedbashir saeedbashir commented Jan 8, 2024

This PR adds support for web-view-based discovery. The switch between native discovery and web-view-based discovery is being controlled from the config file.

Note:
By default, the discovery will be disabled because some providers don't want to provide discovery to their users.

Sample Config Foe WebDiscovery:

DISCOVERY:
    TYPE: 'native'

Sample Config For WebDiscovery:

DISCOVERY:
    TYPE: 'webview'
    WEBVIEW:
        BASE_URL: 'base discovery url'
        COURSE_DETAIL_TEMPLATE: 'discovery detail template URL'
        PROGRAM_DETAIL_TEMPLATE: 'program detail template URL'

Working Video:

web.discovery.mov

@saeedbashir saeedbashir changed the title chore: webview based discovery chore: webview based discovery implementation Jan 8, 2024
@rnr
Copy link
Contributor

rnr commented Jan 8, 2024

@saeedbashir could you please provide properly configured config with added parameters to test this? Thank you

@saeedbashir
Copy link
Contributor Author

@saeedbashir could you please provide properly configured config with added parameters to test this? Thank you

@rnr Our prod config is already configured for the web view based discovery. You can use that to test it.

@rnr
Copy link
Contributor

rnr commented Jan 10, 2024

Hello @saeedbashir
I am facing a problem while testing the Discovery web view. The first time it works, but when I go to Dashboard and go back to Discovery, it stops working. I tested on the device and on the simulator. Please look on video below.

Screen.Recording.2024-01-10.at.13.31.11.mov

@saeedbashir
Copy link
Contributor Author

Hello @saeedbashir I am facing a problem while testing the Discovery web view. The first time it works, but when I go to Dashboard and go back to Discovery, it stops working. I tested on the device and on the simulator. Please look on video below.

Screen.Recording.2024-01-10.at.13.31.11.mov

@rnr Can you please try it now?

@rnr
Copy link
Contributor

rnr commented Jan 11, 2024

Hello @saeedbashir I am facing a problem while testing the Discovery web view. The first time it works, but when I go to Dashboard and go back to Discovery, it stops working. I tested on the device and on the simulator. Please look on video below.
Screen.Recording.2024-01-10.at.13.31.11.mov

@rnr Can you please try it now?

@saeedbashir now it's working fine. thank you

@@ -139,8 +188,8 @@ public struct WebView: UIViewRepresentable {
webView.backgroundColor = .clear
webView.scrollView.backgroundColor = Theme.Colors.white.uiColor()
webView.scrollView.alwaysBounceVertical = false
webView.scrollView.layer.cornerRadius = 24
webView.scrollView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
// webView.scrollView.layer.cornerRadius = 24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saeedbashir do we need this commented out code?

let isWebViewDelegateHandled = await (
parent.webViewNavDelegate?.webView(
webView,
shouldLoad: navigationAction.request, navigationAction: navigationAction) ?? false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you follow style 'each argument on its own line' here please

var sourceScreen: LogistrationSourceScreen

var userloggedIn: Bool {
return !(storage.user?.username?.isEmpty ?? true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't storage.user?.username?.isEmpty == false more clear here?

func showCourseDetais(courseID: String, title: String)
func showWebDiscoveryDetails(pathID: String, discoveryType: DiscoveryWebviewType, sourceScreen: LogistrationSourceScreen)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix please SwiftLint line length warning here

@@ -23,8 +32,18 @@ public class DiscoveryRouterMock: BaseRouterMock, DiscoveryRouter {
public override init() {}

public func showCourseDetais(courseID: String, title: String) {}
public func showWebDiscoveryDetails(pathID: String, discoveryType: DiscoveryWebviewType, sourceScreen: LogistrationSourceScreen) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix please SwiftLint line length warning here

}

var isValidAppURLScheme: Bool {
return scheme ?? "" == URIString.appURLScheme.rawValue ? true : false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't just scheme ?? "" == URIString.appURLScheme.rawValue work here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty scheme ("") is valid too here (in case URIString.appURLScheme gets empty someway)?
maybe need to add && scheme?.isEmpty == false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty scheme ("") is valid too here (in case URIString.appURLScheme gets empty someway)?

It's a defined value, so it shouldn't be needed to address it at the moment.

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

"DETAILS.TITLE" = "Course details";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add these to uk.lproj too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

let request = CDCourseDetails.fetchRequest()
request.predicate = NSPredicate(format: "courseID = %@", courseID)
guard let courseDetails = try? context.fetch(request).first else { throw NoCachedDataError() }
return CourseDetails(courseID: courseDetails.courseID ?? "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please format to have parameter on its own line

let view = DiscoveryWebview(
viewModel: Container.shared.resolve(
DiscoveryWebviewModel.self,
argument: sourceScreen)!,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's fine because having the ( brackets of the argument on the next line breaks the arguments flow.

DiscoveryWebview(
viewModel: Container.shared.resolve(
DiscoveryWebviewModel.self,
argument: viewModel.sourceScreen)!,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saeedbashir saeedbashir requested a review from rnr January 15, 2024 07:58
@volodymyr-chekyrta
Copy link
Contributor

@saeedbashir, could you please fix the tests?
Here is the log from CI.

Testing failed:
	Expected expression after operator
	Command SwiftCompile failed with a nonzero exit code
	Testing cancelled because the build failed.

** TEST FAILED **


The following build commands failed:
	SwiftCompile normal x86_64 Compiling\ DiscoveryViewModel.swift,\ DiscoveryInteractor.swift,\ DiscoveryView.swift,\ CourseDetailsViewModel.swift,\ DiscoveryRouter.swift,\ URL+PathExtension.swift,\ Data_CourseDetailsResponse.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/NativeDiscovery/DiscoveryViewModel.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Domain/DiscoveryInteractor.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/NativeDiscovery/DiscoveryView.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/NativeDiscovery/CourseDetailsViewModel.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/DiscoveryRouter.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/WebDiscovery/URL+PathExtension.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Data/Model/Data_CourseDetailsResponse.swift (in target 'Discovery' from project 'Discovery')
	SwiftCompile normal x86_64 /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/WebDiscovery/URL+PathExtension.swift (in target 'Discovery' from project 'Discovery')
	SwiftCompile normal x86_64 Compiling\ UpdateRecommendedView.swift,\ CourseDetails.swift,\ DiscoveryEndpoint.swift,\ UpdateRequiredView.swift,\ SearchViewModel.swift,\ CourseDetailsView.swift,\ DiscoveryURIDetails.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/UpdateViews/UpdateRecommendedView.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Data/Model/CourseDetails.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Data/Network/DiscoveryEndpoint.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/UpdateViews/UpdateRequiredView.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/NativeDiscovery/SearchViewModel.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/NativeDiscovery/CourseDetailsView.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/WebDiscovery/DiscoveryURIDetails.swift (in target 'Discovery' from project 'Discovery')
(3 failures)
[08:08:11]: Exit status: 65

@rnr
Copy link
Contributor

rnr commented Jan 15, 2024

@saeedbashir, could you please fix the tests? Here is the log from CI.

Testing failed:
	Expected expression after operator
	Command SwiftCompile failed with a nonzero exit code
	Testing cancelled because the build failed.

** TEST FAILED **


The following build commands failed:
	SwiftCompile normal x86_64 Compiling\ DiscoveryViewModel.swift,\ DiscoveryInteractor.swift,\ DiscoveryView.swift,\ CourseDetailsViewModel.swift,\ DiscoveryRouter.swift,\ URL+PathExtension.swift,\ Data_CourseDetailsResponse.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/NativeDiscovery/DiscoveryViewModel.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Domain/DiscoveryInteractor.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/NativeDiscovery/DiscoveryView.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/NativeDiscovery/CourseDetailsViewModel.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/DiscoveryRouter.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/WebDiscovery/URL+PathExtension.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Data/Model/Data_CourseDetailsResponse.swift (in target 'Discovery' from project 'Discovery')
	SwiftCompile normal x86_64 /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/WebDiscovery/URL+PathExtension.swift (in target 'Discovery' from project 'Discovery')
	SwiftCompile normal x86_64 Compiling\ UpdateRecommendedView.swift,\ CourseDetails.swift,\ DiscoveryEndpoint.swift,\ UpdateRequiredView.swift,\ SearchViewModel.swift,\ CourseDetailsView.swift,\ DiscoveryURIDetails.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/UpdateViews/UpdateRecommendedView.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Data/Model/CourseDetails.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Data/Network/DiscoveryEndpoint.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/UpdateViews/UpdateRequiredView.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/NativeDiscovery/SearchViewModel.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/NativeDiscovery/CourseDetailsView.swift /Users/runner/work/openedx-app-ios/openedx-app-ios/Discovery/Discovery/Presentation/WebDiscovery/DiscoveryURIDetails.swift (in target 'Discovery' from project 'Discovery')
(3 failures)
[08:08:11]: Exit status: 65

@saeedbashir project isn't compilable after fix (there is misspelling in URL+PathExtension.swift)

rnr
rnr previously approved these changes Jan 15, 2024
@saeedbashir saeedbashir changed the title chore: webview based discovery implementation feat: webview based discovery implementation Jan 16, 2024
@touchapp
Copy link

Hi @volodymyr-chekyrta any other info needed to review this PR?

@volodymyr-chekyrta
Copy link
Contributor

Hi @volodymyr-chekyrta any other info needed to review this PR?

Hi @touchapp, I'll do my best to finish review today

rnr
rnr previously approved these changes Jan 17, 2024
@@ -69,6 +69,7 @@

"WEBVIEW.ALERT.OK" = "Так";
"WEBVIEW.ALERT.CANCEL" = "Скасувати";
"WEBVIEW.ALERT.CONTINUE" = "Continue";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to have a localized version of the string at this moment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't add translations on the go. Files will be translated later.

Comment on lines 76 to 80
if enroll.statusCode == 200 {
return true
} else {
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can refactor it like:

return enroll.statusCode == 200


var path: String {
switch self {
case .getDiscovery:
return "/api/courses/v1/courses/"
case .searchCourses:
return "/api/courses/v1/courses/"
case .getCourseDetail(courseID: let courseID, _):
return "/api/courses/v1/courses/\(courseID)"
case .enrollToCourse(courseID: _):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting warning in code:

Empty Enum Arguments Violation: Arguments can be omitted when matching enums with associated values if they are not used (empty_enum_arguments)

}
}

var httpMethod: HTTPMethod {
switch self {
case .getDiscovery, .searchCourses:
return .get
case .getCourseDetail(courseID: _, username: _):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same warning here:

Empty Enum Arguments Violation: Arguments can be omitted when matching enums with associated values if they are not used (empty_enum_arguments)

}

var isValidAppURLScheme: Bool {
return scheme ?? "" == URIString.appURLScheme.rawValue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address warning:

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)

Copy link
Contributor

@shafqat-muneer shafqat-muneer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@saeedbashir saeedbashir merged commit 06f0993 into openedx:develop Jan 17, 2024
3 checks passed
@saeedbashir saeedbashir deleted the saeed/web_discovery branch January 17, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iOS] Webview Discovery Experience
5 participants