Skip to content

Commit

Permalink
Fix success notification upon clicking the follow button when user is…
Browse files Browse the repository at this point in the history
… not signed in #6688 (#6703)

* fix success notification on /tags

* refactor condition for follow flash notice
  • Loading branch information
rebecarancan authored and jywarren committed Nov 25, 2019
1 parent b28eafb commit 833e0b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions app/assets/javascripts/async_tag_subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ $(document).ready(function()
$('.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);
window.history.pushState("", "", data_recv.url); // Preserve state
if(data_recv.id) {
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));
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/subscription_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def add
if request.xhr?
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 }
render json: { status: status, message: message, id: tag.tid, tagname: params[:name], url: "/tags" + "?_=" + Time.now.to_i.to_s } if current_user
else
flash[:notice] = "You are now following '#{params[:name]}'."
redirect_to "/subscriptions" + "?_=" + Time.now.to_i.to_s
Expand Down

0 comments on commit 833e0b6

Please sign in to comment.