the count is now incremented/decremented correctly on the view followers/friends pages

This commit is contained in:
nilsding 2014-12-08 19:48:12 +01:00
parent f381baa702
commit e63e52f585
5 changed files with 13 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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