Skip to content

Commit

Permalink
Fix follow button bug on tags (#6576)
Browse files Browse the repository at this point in the history
* Fix bug on issue #6570

* Persist data
  • Loading branch information
crisner authored and cesswairimu committed Nov 3, 2019
1 parent f42c4b0 commit 8128a30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 7 additions & 6 deletions app/assets/javascripts/async_tag_subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ $(document).ready(function()
window.location = "/tag/" + ($('#taginput').val()).replace(/\s/g, '-');
});
$('.index-follow-buttons').on('ajax:success', function(data, status, xhr){
console.log("Hello");
var data_recv = JSON.parse(JSON.stringify(status));
notyNotification('relax', 3000, 'success', 'top', data_recv.message + 'Click <a href="../subscriptions"> here </a> to manage your subscriptions. ');
var html_new = '<a rel="tooltip" title=Following class="btn btn-default btn-sm active" href="/unsubscribe/tag/'+ data_recv.tagname + '"> <i class="fa fa-user-plus" aria-hidden="true"></i>Following</a>';
$('#follow-unfollow-column-'+data_recv.id).html(html_new);
});
console.log("Hello");
var data_recv = JSON.parse(JSON.stringify(status));
notyNotification('relax', 3000, 'success', 'top', data_recv.message + 'Click <a href="../subscriptions"> here </a> to manage your subscriptions. ');
var html_new = '<a rel="tooltip" title=Following class="btn btn-default btn-sm active" href="/unsubscribe/tag/'+ data_recv.tagname + '"> <i class="fa fa-user-plus" aria-hidden="true"></i>Following</a>';
$('#follow-unfollow-column-'+data_recv.id).html(html_new);
window.history.pushState("", "", data_recv.url); // Preserve state
});
$('.index-follow-buttons').on('ajax:error', function(data, status, xhr){
var data_recv = JSON.parse(JSON.stringify(status));
notyNotification('relax', 3000, 'error', 'top', data_recv.message + 'Click <a href="../subscriptions"> here </a> to manage your subscriptions. ');
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/subscription_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ def add

if set_following(true, params[:type], tag.tid)
if request.xhr?
# message = "Started following #{params[:name]}!"
# status = "200"
message = "Started following #{params[:name]}!"
status = "200"
render json: { status: status, message: message, id: tag.tid, tagname: params[:name], url: "/tags" + "?_=" + Time.now.to_i.to_s }
else
flash[:notice] = "You are now following '#{params[:name]}'."
redirect_to "/subscriptions" + "?_=" + Time.now.to_i.to_s
Expand Down

0 comments on commit 8128a30

Please sign in to comment.