-
Notifications
You must be signed in to change notification settings - Fork 37
Add AJAX functions for following/unfollowing users #9
base: master
Are you sure you want to change the base?
Conversation
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.
coming along nicely @TJBANEY , Thanks alot. I have requested for a few changes please take a look at them.
app/templates/base.html
Outdated
@@ -95,6 +100,48 @@ | |||
} | |||
) | |||
}) | |||
|
|||
const user = "{{user.username}}" |
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.
user object is only available in user.html, it is not available in base.html. It will work for /user/ endpoint, but it will not work for other endpoints, you may get jinja2.exceptions.UndefinedError
, please check.
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 suggest moving follow, unfollow links to some reusable html template and use it everywhere, and move this javascript code to the new template created.
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.
Hey @SriNandan33 I made those follow/unfollow buttons snippets, and migrated the inline javascript used for following/unfollowing into a static directory
app/templates/user.html
Outdated
{% elif current_user.is_following(user) %} | ||
<p><a href="{{ url_for('core.unfollow', username=user.username)}}">Unfollow</a></p> | ||
<div class="follow-link"> | ||
<p onclick="unFollowUser()">Unfollow</p> |
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.
Please use button
here just to denote it is clickable and add some css to it. Don't forget to add cursor:pointer
to css rule.
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 one is also good to go 👍
@SriNandan33 Made a few more edits that maintains follow/unfollow functionality inside hover popups |
I added a JavaScript file with logic to asynchronously hit the follow and unfollow Flask routes. I also turned the follow/unfollow buttons into template snippets so they can be re-used throughout the application where needed, and where a context user can be provided.