Add AJAX functions for following/unfollowing users - #9
Conversation
SriNandan33
left a comment
There was a problem hiding this comment.
coming along nicely @TJBANEY , Thanks alot. I have requested for a few changes please take a look at them.
| ) | ||
| }) | ||
|
|
||
| const user = "{{user.username}}" |
There was a problem hiding this comment.
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.
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.
Hey @SriNandan33 I made those follow/unfollow buttons snippets, and migrated the inline javascript used for following/unfollowing into a static directory
| {% 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.
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.
|
@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.