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