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

Add reading log buttons to search results #6159

Merged
merged 16 commits into from
Mar 3, 2022

Conversation

jimchamp
Copy link
Collaborator

@jimchamp jimchamp commented Feb 17, 2022

Closes #6122, closes #5501

Refactors the list widget, moving the reading log dropper into a separate file and removing inline JS. Adds reading log button to search results.

Technical

In no particular order:

The need for uniquely identifying list widgets is gone. Instead, event listeners are added to specific elements by class. Listeners are added to the droppers and their child elements, and to various owner list items found on the page (the ones that can be removed by clicking the [X] ).

All Javascript and unused code and variables have been removed from list/widget.html. Any jsdef functions have been redefined with def.

The reading log dropper is now in it's own dedicated file. The "Create a new list" model has also been included in the new file.

Some changes have been made to the dropper:

  1. Two hidden inputs have been added to the dropper: the patron's key and a default seed key.
  2. Checkmark span in primary button is always present. Its visibility is toggled when necessary.
  3. Buttons in dropdown no longer dynamically generated. All three are now present, but the button that corresponds to the primary button is hidden. Visibility is toggled on successful form submit.

Testing

Test all list widget functionality on the following page types:

  • Book page
  • Search results page
  • Author page
  • Subject page

Screenshot

Screenshot from 2022-02-18 22-07-59

Stakeholders

@mekarpeles @cdrini

@jimchamp jimchamp added the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label Feb 19, 2022
@jimchamp jimchamp marked this pull request as ready for review February 19, 2022 03:12
@mekarpeles mekarpeles self-assigned this Feb 22, 2022
@mekarpeles mekarpeles requested a review from cdrini February 22, 2022 20:47
@mekarpeles mekarpeles added the Priority: 1 Do this week, receiving emails, time sensitive, . [managed] label Feb 22, 2022
@jimchamp
Copy link
Collaborator Author

Recommend replacing our ReadingLogButton.html buttons (used in the "My Books" page) with the new reading log dropper when this is merged.

@mekarpeles
Copy link
Member

I recall there being one issue where selecting a reading log shelf to "Already Read" and then clearing the selection shows a grey btn w/ text "Already Read".

I reviewed the code and nothing looks too dangerous. I suggest us moving forward and adding test cases where we learn it breaks (like the case mentioned above). I don't think we should block on hitting an arbitrary quality/coverage number.

@jimchamp jimchamp force-pushed the wanna-read branch 2 times, most recently from bfd55b0 to f8ade40 Compare March 1, 2022 17:57
@jimchamp jimchamp mentioned this pull request Mar 1, 2022
Copy link
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

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

Nice! Code looks headed in a good direction :)

Testing:

  • ❌ Broken on IE11 with Object doesn't support property or method 'closest' -- use jquery ?
    • Not a blocker; but could cause issues for other browsers to :/ Create an issue to keep track of it.
  • ✅ Adding book to CR works from search
  • ✅ Clicking button works + no refresh
  • ✅ Deleting works
  • ✅ Adding work vs edition works
  • Small regression: previously the user's lists would filter based on whether the "work" checkbox was ticked. It doesn't do that anymore. Not a blocker.

Blockers:

  • Add a unit test to grease the flow, as discussed on call
  • Removing the bit of HTML inside the JS would be great to keep our i18n healthy and avoid unescaped html

openlibrary/macros/ReadingLogDropper.html Outdated Show resolved Hide resolved
Comment on lines +41 to +42
<input type="hidden" id="edition_id" name="edition_id" value="$(edition_key)"/>
<input type="hidden" id="work_id" name="work_id" value="$(work_key)"/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should not have IDs anymore, since they can appear in multiple places in the page. Update any downstream code that refers to these.

Test: Adding work, or edition to list both still work.

Copy link
Collaborator Author

@jimchamp jimchamp Mar 1, 2022

Choose a reason for hiding this comment

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

Droppers are referenced only by class name in the JS. These IDs no longer serve a function.

openlibrary/macros/ReadingLogDropper.html Show resolved Hide resolved
openlibrary/macros/ReadingLogDropper.html Outdated Show resolved Hide resolved
openlibrary/plugins/openlibrary/js/lists/index.js Outdated Show resolved Hide resolved
Comment on lines +86 to +88
<input type="hidden" name="seed-title" value="$(seed_info['title'])"/>
<input type="hidden" name="seed-key" value="$(seed_info['seed']['key'])"/>
<input type="hidden" name="seed-type" value="$(seed_info['type'])"/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where is seed_info coming from? Is it in the global scope? Pass it in as an argument; we want to keep these fns encapsulated and relying less on global scope, to aid in the fact that they can be rendered multiple times now. That'll also let you use this as a jsdef.

Copy link
Collaborator Author

@jimchamp jimchamp Mar 1, 2022

Choose a reason for hiding this comment

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

seed_info is coming from line 64.

const splitKey = listKey.split('/')
const userKey = `/${splitKey[1]}/${splitKey[2]}`
const itemMarkUp = `<span class="image">
<a href="${listKey}"><img src="${coverUrl}" alt="Cover of: ${listTitle}" title="Cover of: ${listTitle}"/></a>
Copy link
Collaborator

Choose a reason for hiding this comment

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

listTitle needs to be html escaped, potential XSS issue. Use the jsdef from the HTML ; it's available as a global here (or on the window object; e.g. window.show_list(...)). It might seem messy but honestly it's a good compromise and keeps things DRY. It also let's the form be i18n'd, since that's not supported yet for HTML in JS.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can I just use websafe, which has already been imported?

Copy link
Collaborator

@cdrini cdrini Mar 1, 2022

Choose a reason for hiding this comment

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

That will fix the html escaping issue, but won't help with the i18n or the code duplication. But I think it's good enough for now 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, not sure if that was happening before. Will this change cause issues for folks?

Agree that it should be done, just trying not to mess up anybody's lists.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh actually IIRC correctly jsdef doesn't i18n correctly anyways :( So that won't help. The only benefit here would be DRY'ness.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

show_list is not global. I18n strings made available client-side via hidden input.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, it's only global if it's a $jsdef and the corresponding HTML is before the JS (which it should be).

openlibrary/templates/lists/widget.html Show resolved Hide resolved
@jimchamp jimchamp requested a review from cdrini March 3, 2022 20:28
Copy link
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

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

Lgtm! Now also works in IE11 -- so hopefully all browsers! Nice!

</div>
</div>
$def i18n_input():
$ show_list_i18n_strings = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! This is a good compromise.

@mekarpeles
Copy link
Member

🚀

@mekarpeles mekarpeles merged commit 94488c7 into internetarchive:master Mar 3, 2022
@jimchamp jimchamp deleted the wanna-read branch July 15, 2022 23:14
@jimchamp jimchamp removed the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: 1 Do this week, receiving emails, time sensitive, . [managed]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate list on subject pages Show "Want to Read" button for books on search results page.
3 participants