-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Added a QR icon in Share Modal that opens to QR code on click #9233
Conversation
3416158
to
2e9a182
Compare
Codecov ReportAttention: Patch coverage is
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. |
43e71a7
to
52650ba
Compare
fc03faf
to
6939cc6
Compare
@jimchamp Could you review this when you get the chance? Thanks ! |
There was a problem hiding this 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:
- Missing opening
div
tag has caused the page's layout to shift. - Generated QR code always links to
http://localhost:8080/qrcode
- The new
addQRCodeListener
JS function isn't needed if anhref
is set on the QR code link. - The
displayDynamicModal
andaddShareModalClickListeners
functions are very similar to the existingdisplayModal
andaddClickListeners
functions. I think thatdisplayModal
can be modified to handle the case where screen width is less thanmaxWidth
(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.
openlibrary/macros/ShareModal.html
Outdated
@@ -14,7 +14,6 @@ | |||
<div class="hidden"> | |||
<div id="social-modal-content" class="floaterAdd"> | |||
<div class="content"> | |||
<div class="floaterHead right-justify"> |
There was a problem hiding this comment.
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:
It's also causing the modal's X
close affordance to appear on the upper-left side (instead of the upper-right):
At first glance, everything looks fine when this opening div
tag is added back to the template.
There was a problem hiding this comment.
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.
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(); | ||
}); | ||
} |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
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); | ||
}); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
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.
for more information, see https://pre-commit.ci
05459fa
to
7846873
Compare
There was a problem hiding this 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!
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 warningsdocker compose run --rm home pytest openlibrary/plugins/importapi/tests/test_import_validator.py
: passing with warningsdocker compose run --rm home npm run lint
: passing with deprecation warningsScreenshot
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.
Stakeholders
@jimchamp
Thank you for the help!