-
-
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
Add reading log buttons to search results #6159
Conversation
Recommend replacing our |
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. |
bfd55b0
to
f8ade40
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.
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
<input type="hidden" id="edition_id" name="edition_id" value="$(edition_key)"/> | ||
<input type="hidden" id="work_id" name="work_id" value="$(work_key)"/> |
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.
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.
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.
Droppers are referenced only by class name in the JS. These IDs no longer serve a function.
<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'])"/> |
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.
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
.
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.
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> |
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.
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.
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.
Can I just use websafe
, which has already been imported?
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.
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 👍
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.
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.
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 actually IIRC correctly jsdef doesn't i18n correctly anyways :( So that won't help. The only benefit here would be DRY'ness.
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.
show_list
is not global. I18n strings made available client-side via hidden input.
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, it's only global if it's a $jsdef
and the corresponding HTML is before the JS (which it should be).
- Remove dead code and unused variables - Change `jsdef` functions to "regular" functions
Co-authored-by: Drini Cami <cdrini@gmail.com>
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.
Lgtm! Now also works in IE11 -- so hopefully all browsers! Nice!
</div> | ||
</div> | ||
$def i18n_input(): | ||
$ show_list_i18n_strings = { |
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.
Nice! This is a good compromise.
🚀 |
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
. Anyjsdef
functions have been redefined withdef
.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:
span
in primary button is always present. Its visibility is toggled when necessary.Testing
Test all list widget functionality on the following page types:
Screenshot
Stakeholders
@mekarpeles @cdrini