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

Added a QR icon in Share Modal that opens to QR code on click #9233

Merged

Conversation

merwhite11
Copy link
Collaborator

@merwhite11 merwhite11 commented May 7, 2024

Closes #452

Feature: Adds a QR code icon to the share modal on books page. On icon click, a new tab opens with the QR code image.
Refactor: Changed styling of Share Modal so that for small -> tablet sized screens, the share modal icons appear larger and in two rows.

Technical

Installed qrcode dependency in requirements.txt
Imported qrcode and io in api.py for use in create_qrcode handler.

Testing

docker compose run --rm home make test : passing with warnings
docker compose run --rm home pytest openlibrary/plugins/importapi/tests/test_import_validator.py: passing with warnings
docker compose run --rm home npm run lint: passing with deprecation warnings

Screenshot

I can change the size of the icons if these are too large. I can also change the breakpoint for when to switch from large 2-row icons, to smaller single row icons. Currently I have the icons in 2 rows for everything tablet and smaller.
Screenshot 2024-05-07 at 2 01 36 PM

Stakeholders

@jimchamp
Thank you for the help!

@merwhite11 merwhite11 force-pushed the 452/feature/add-qr-to-share-modal branch from 3416158 to 2e9a182 Compare May 8, 2024 19:24
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 30 lines in your changes are missing coverage. Please review.

Project coverage is 16.11%. Comparing base (db9ead2) to head (936d6e1).
Report is 141 commits behind head on master.

Files Patch % Lines
openlibrary/plugins/openlibrary/js/modals/index.js 0.00% 27 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9233      +/-   ##
==========================================
+ Coverage   15.89%   16.11%   +0.22%     
==========================================
  Files          90       91       +1     
  Lines        4732     4785      +53     
  Branches      824      829       +5     
==========================================
+ Hits          752      771      +19     
- Misses       3468     3498      +30     
- Partials      512      516       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@merwhite11 merwhite11 force-pushed the 452/feature/add-qr-to-share-modal branch 2 times, most recently from 43e71a7 to 52650ba Compare May 8, 2024 19:35
@merwhite11 merwhite11 force-pushed the 452/feature/add-qr-to-share-modal branch 2 times, most recently from fc03faf to 6939cc6 Compare May 22, 2024 21:07
@merwhite11
Copy link
Collaborator Author

@jimchamp Could you review this when you get the chance? Thanks !

Copy link
Collaborator

@jimchamp jimchamp left a comment

Choose a reason for hiding this comment

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

Thanks @merwhite11, and sorry for the massive delay!

I've added a number of suggested changes, but they should all be pretty straight-forward. There will be more details in the following comments, but generally, the following should be addressed:

  1. Missing opening div tag has caused the page's layout to shift.
  2. Generated QR code always links to http://localhost:8080/qrcode
  3. The new addQRCodeListener JS function isn't needed if an href is set on the QR code link.
  4. The displayDynamicModal and addShareModalClickListeners functions are very similar to the existing displayModal and addClickListeners functions. I think that displayModal can be modified to handle the case where screen width is less than maxWidth (if such a change is needed). If that's true, the two new functions can be removed.

By the way, I'm uploading QR codes to this site in order to test that the encoded URL is correct.

@@ -14,7 +14,6 @@
<div class="hidden">
<div id="social-modal-content" class="floaterAdd">
<div class="content">
<div class="floaterHead right-justify">
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this change is causing the main content of the page to appear below the #contentBody div:

Screenshot from 2024-05-30 12-39-32
Screenshot from 2024-05-30 12-40-09

It's also causing the modal's X close affordance to appear on the upper-left side (instead of the upper-right):

image

At first glance, everything looks fine when this opening div tag is added back to the template.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh I see what I did there. Fixed the spacing.

openlibrary/plugins/openlibrary/api.py Outdated Show resolved Hide resolved
openlibrary/plugins/openlibrary/api.py Outdated Show resolved Hide resolved
openlibrary/plugins/openlibrary/js/modals/index.js Outdated Show resolved Hide resolved
Comment on lines 424 to 451
function displayDynamicModal(content, maxWidth) {
const maxWidthNum = parseInt(maxWidth.replace('px', ''));
const modalId = `#${content.id}`;
const context = content.dataset['context'] ? JSON.parse(content.dataset['context']) : null;
const reloadId = context ? context.reloadId : null;

function openModal() {
$.colorbox({
inline: true,
opacity: '0.5',
href: modalId,
width: '100%',
maxWidth: window.innerWidth > maxWidthNum ? maxWidth : '100%',
onClosed: function () {
if (reloadId) {
$(`#${reloadId}`).trigger('contentReload');
}
},
});
}

openModal();

$(window).on('resize', function () {
$.colorbox.remove();
openModal();
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this is exactly the same as the displayModal function, except for the change that sets maxWidth to 100% if the screen's width is less than the value that is passed.

I think that we can avoid this repeated code by modifying displayModal to include the changes that you added to displayDynamicModal.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, this change may not be needed at all. While testing, I replaced your displayDynamicModal call with a displayModal call, and everything looked the same in both mobile and desktop views (tested in Firefox and Chrome).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes testing this myself and realizing displayDynamicModal is not needed. I can use the pre-existing addClickListeners and addShareModalButtonListeners. I was trying to make it resize appropriately with the dynamic version (eg. if you open in mobile and then switch to desktop, the modal gets out of proportion), but the dynamic isn't handling that correctly either. Is that something we need to take into account for modal testing?
Screenshot 2024-05-31 at 11 52 16 AM

Copy link
Collaborator

Choose a reason for hiding this comment

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

I doubt that this will affect many people, but thanks for pointing it out!

static/css/components/shareLinks.less Outdated Show resolved Hide resolved
Comment on lines 249 to 258
function addShareModalClickListeners($modalLinks, maxWidth) {
$modalLinks.each(function (_i, modalLinkElement) {
$(modalLinkElement).on('click', function () {
// Get context, which is attached to the modal content
const content = getModalContent($(this));
displayDynamicModal(content, maxWidth);
});
});
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that we can DRY this code by modifying displayModal, and using addClickListeners to add the listeners to the share modal.

openlibrary/macros/ShareModal.html Outdated Show resolved Hide resolved
@jimchamp jimchamp added Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] and removed Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] labels May 30, 2024
@merwhite11 merwhite11 force-pushed the 452/feature/add-qr-to-share-modal branch from 05459fa to 7846873 Compare May 31, 2024 17:34
Copy link
Collaborator

@jimchamp jimchamp left a comment

Choose a reason for hiding this comment

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

This seems to be working well --- thanks so much!

@jimchamp jimchamp added the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label May 31, 2024
@jimchamp jimchamp merged commit 39c7a62 into internetarchive:master May 31, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add QR code to Share Modal
3 participants