the count is now incremented/decremented correctly on the view followers/friends pages
This commit is contained in:
parent
f381baa702
commit
e63e52f585
|
@ -1,9 +1,11 @@
|
|||
$(document).on "click", "button[name=user-action]", ->
|
||||
btn = $(this)
|
||||
btn.button "loading"
|
||||
type = btn[0].dataset.type
|
||||
target = btn[0].dataset.target
|
||||
action = btn[0].dataset.action
|
||||
count = Number $("h4.entry-text#follower-count").html()
|
||||
if type in ['follower', 'friend']
|
||||
count = Number $("h4.entry-text##{type}-count").html()
|
||||
|
||||
target_url = switch action
|
||||
when 'follow'
|
||||
|
@ -23,7 +25,8 @@ $(document).on "click", "button[name=user-action]", ->
|
|||
success: (data, status, jqxhr) ->
|
||||
success = data.success
|
||||
if data.success
|
||||
$("h4.entry-text#follower-count").html(count)
|
||||
if type in ['follower', 'friend']
|
||||
$("h4.entry-text##{type}-count").html(count)
|
||||
showNotification data.message, data.success
|
||||
error: (jqxhr, status, error) ->
|
||||
console.log jqxhr, status, error
|
||||
|
|
|
@ -25,6 +25,7 @@ class UserController < ApplicationController
|
|||
@title = 'Followers'
|
||||
@user = User.find_by_screen_name!(params[:username])
|
||||
@users = @user.followers.reverse_order.paginate(page: params[:page])
|
||||
@type = :friend
|
||||
render 'show_follow'
|
||||
end
|
||||
|
||||
|
@ -32,6 +33,7 @@ class UserController < ApplicationController
|
|||
@title = 'Following'
|
||||
@user = User.find_by_screen_name!(params[:username])
|
||||
@users = @user.friends.reverse_order.paginate(page: params[:page])
|
||||
@type = :friend
|
||||
render 'show_follow'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/ TODO: pixeldesu pls
|
||||
- type ||= @type || :nil
|
||||
.panel.panel-default
|
||||
.panel-body
|
||||
.media
|
||||
|
@ -21,4 +22,4 @@
|
|||
.col-md-6.col-sm-6.col-xs-6
|
||||
%h4.entry-text#answered-count= user.answered_count
|
||||
%h6.entry-subtext Answers
|
||||
= render 'user/actions', user: user
|
||||
= render 'user/actions', user: user, type: type
|
|
@ -1,10 +1,11 @@
|
|||
- if user_signed_in?
|
||||
- type ||= :nil
|
||||
- if user == current_user
|
||||
%a.btn.btn-default.btn-block{href: edit_user_profile_path} Edit profile
|
||||
- else
|
||||
- if current_user.following? user
|
||||
%button#editprofile.btn.btn-default.btn-block{type: :button, name: 'user-action', data: { action: :unfollow, target: user.screen_name }}
|
||||
%button#editprofile.btn.btn-default.btn-block{type: :button, name: 'user-action', data: { action: :unfollow, type: type, target: user.screen_name }}
|
||||
Unfollow
|
||||
- else
|
||||
%button#editprofile.btn.btn-primary.btn-block{type: :button, name: 'user-action', data: { action: :follow, target: user.screen_name }}
|
||||
%button#editprofile.btn.btn-primary.btn-block{type: :button, name: 'user-action', data: { action: :follow, type: type, target: user.screen_name }}
|
||||
Follow
|
|
@ -39,4 +39,4 @@
|
|||
.col-md-6.col-sm-6.col-xs-6
|
||||
%h4.entry-text#answered-count= @user.answered_count
|
||||
%h6.entry-subtext Answers
|
||||
= render 'user/actions', user: @user
|
||||
= render 'user/actions', user: @user, type: :follower
|
Loading…
Reference in New Issue