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

refactor: [AXM-361] refactor JS bridge for IOS and Android #2580

Conversation

NiedielnitsevIvan
Copy link

AXM-361 Implement JS bridge on the server side for Problem XBlock

}

const originalAjax = $.ajax;
$.ajax = function (options) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm, I saw the ajax patch, and thought maybe in the final version we will attach event directly to the Submit event or element that submits it, but it's ok for us now

}

if (window.AndroidBridge) {
window.addEventListener("messageFromAndroid", function (event) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, those events are not according to specification

the new event to listeners for markProblemCompletedIOS and markProblemCompletedAndroid events are registered for the window

function markProblemCompleted(message) {
const data = JSON.parse(message).data;

const prob = $(".xblock-student_view");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please be more discriptive, instead of prob, please name it problemContainer

markProblemCompleted(message);
}

function markProblemCompleted(message) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add JSdoc to every function in this file

Like this -

https://jsdoc.app/about-getting-started

window?.AndroidBridge?.postMessage(message);
}

function markProblemCompletedIOS(message) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's no need to do these 2 proxy calls if there are no differences in IOS and Android calls

Copy link
Author

Choose a reason for hiding this comment

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

Yes, there are none at the moment (although we haven't had any feedback from IOS yet), but if in the future there is a need for this, it will allow us to make changes to only one function, without having to change the names on the mobile side.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the name of the function doesn't mean much we should relly on JS Event names, am I correct?

window.addEventListener("messageFromIOS"

Copy link
Author

Choose a reason for hiding this comment

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

I'l recheck this.

Copy link
Collaborator

@GlugovGrGlib GlugovGrGlib left a comment

Choose a reason for hiding this comment

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

Please apply enhancements to JS file and it's good to be merged

@NiedielnitsevIvan NiedielnitsevIvan force-pushed the NiedielnitsevIvan/AXM-361/feature/Implement-JS-bridge-on-the-server-side-for-Problem-XBlock branch from 3801f56 to 01ff507 Compare June 20, 2024 09:19
*/
const originalAjax = $.ajax;
$.ajax = function (options) {
if (options.url && options.url.endsWith("problem_check")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've thoght about it only now, but let's change the endsWith to check more specific url entry
handler/xmodule_handler/problem_check

Copy link
Collaborator

@GlugovGrGlib GlugovGrGlib Jun 20, 2024

Choose a reason for hiding this comment

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

Will it work?

Copy link
Author

Choose a reason for hiding this comment

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

Yep, updated


data.split("&").forEach(function (item) {
const [inputId, answer] = item.split('=', 2);
problemContainer.find('input[id$="' + answer + '"], input[id$="' + inputId + '"]').each(function () {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

I'll give it a try, because it was a solution for js when it was in an html file and had to build it through mako.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@NiedielnitsevIvan NiedielnitsevIvan force-pushed the NiedielnitsevIvan/AXM-361/feature/Implement-JS-bridge-on-the-server-side-for-Problem-XBlock branch from 01ff507 to af88007 Compare June 21, 2024 06:55
@NiedielnitsevIvan NiedielnitsevIvan force-pushed the NiedielnitsevIvan/AXM-361/feature/Implement-JS-bridge-on-the-server-side-for-Problem-XBlock branch from af88007 to 0202935 Compare June 21, 2024 07:16
@GlugovGrGlib GlugovGrGlib merged commit c2a7bee into mob-develop Jun 22, 2024
43 checks passed
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.

2 participants