-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Fix follow buttons #382
Fix follow buttons #382
Conversation
3ede8c6
to
6e578db
Compare
22d1faf
to
1b07744
Compare
Works mostly fine now, just one unfortunate Bootstrap weirdness: not sure how to deal with that. Hard-code the |
What about putting this in between them? <div class="hidden">dummy to stop Bootstrap from adding padding to the second button</div> |
That should work as well. Maybe put the text as Jinja comment ( |
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 worked! Should be all set now, thanks for the extensive fixes 👍
Motivation
I've wanted to rework the very janky follow/unfollow buttons since #343, but that pull request had a lot of other things going on and I did not want to increase its scope. #379 focused exclusively on the follow buttons, and this pull request replaces that one.
Too much of the visual and style info about the follow/unfollow buttons has been encoded into client script code. The
click
event handler manipulates the text, tooltips, glyphicon classes, etc., to transform a follow button into an unfollow button and vice versa. This essentially means the client script code needs to know everything about how these buttons are supposed to appear, which is hard to maintain and prone to bugs.Problems
/register
page.Causes
With the database changes from Let users choose which emails to receive #369, the code in
mods.unfollow()
no longer works. It was kinda weird anyways.With the mod box redesign from Improve mod box appearance #343 the code for (un)follow buttons has been changed in a way that assumes it would only be called for the mod box star buttons, however it's still executed for the big (un)follow buttons on the mod pages. It tries to add the (empty) star glyphicon to the button, which fails to render correctly.
The JS code tries to select the follow buttons in the mod boxes by id, however the id selector will only ever return up to one element, as more than one element with the same id is invalid HTML: https://api.jquery.com/id-selector/
The
click
handler of the follow button updates the solid star indicator for all copies of a mod in the page, but for everything else it only modifies the element you clicked onBootstrap removes alerts from the DOM when they are dismissed:
https://getbootstrap.com/docs/4.0/components/alerts/
$().alert('close')
So the next time we try to show that alert, its element is no longer available; an exception is thrown, and the
click
handler interprets this as the user not being logged in and redirects them to/register
.Changes
mod_followers
/Following
table, and delete all rows with for that mod and user (hopefully there's only one, but it handles any case fine).id
attributes inmod-box.html
are moved to classes, as none of them would ever be unique on a page. The follow button code queries and toggles the stars based on the class, not id.I couldn't find any use of the other
modbox-*-*
ids in any code, so nothing else should need adjusting..not-following-mod
with.following-mod
or vice versa for all elements that match.mod-{{mod.id}}
, which is intended to be any element that depends on following or not-following state. Instead of manipulating the details of the elements' attributes, we're just telling them whether the mod should show a following state, and stylesheet rules take care of what should be shown or hidden. This makes the toggle work properly for all copies of a mod that are in the page, and means that we can freely change how the buttons look in the templates without the client script code missing them up.hidden
stylesheet class rather than removing it from the DOM (suppressed by returning false). This way it remains available in case we want to show it again.