mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:57:10 -06:00
UX: cap likes 2 (#5237)
This commit is contained in:
parent
3831663fea
commit
4c4410225e
@ -30,7 +30,7 @@ createWidget('small-user-list', {
|
||||
let description = null;
|
||||
|
||||
if (atts.description) {
|
||||
description = I18n.t(atts.description, { icons: '' });
|
||||
description = I18n.t(atts.description, { count: atts.count });
|
||||
}
|
||||
|
||||
// oddly post_url is on the user
|
||||
|
@ -353,11 +353,13 @@ export default createWidget('post-menu', {
|
||||
|
||||
const contents = [ h('nav.post-controls.clearfix', postControls) ];
|
||||
if (state.likedUsers.length) {
|
||||
const remaining = state.total - state.likedUsers.length;
|
||||
contents.push(this.attach('small-user-list', {
|
||||
users: state.likedUsers,
|
||||
addSelf: attrs.liked,
|
||||
addSelf: attrs.liked && remaining === 0,
|
||||
listClassName: 'who-liked',
|
||||
description: 'post.actions.people.like'
|
||||
description: remaining > 0 ? 'post.actions.people.like_capped' : 'post.actions.people.like',
|
||||
count: remaining
|
||||
}));
|
||||
}
|
||||
|
||||
@ -413,6 +415,7 @@ export default createWidget('post-menu', {
|
||||
|
||||
return this.store.find('post-action-user', { id: attrs.id, post_action_type_id: LIKE_ACTION }).then(users => {
|
||||
state.likedUsers = users.map(avatarAtts);
|
||||
state.total = users.totalRows;
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -6,6 +6,9 @@ class PostActionUsersController < ApplicationController
|
||||
params.require(:id)
|
||||
post_action_type_id = params[:post_action_type_id].to_i
|
||||
|
||||
page = params[:page].to_i
|
||||
page_size = (params[:limit] || 200).to_i
|
||||
|
||||
finder = Post.where(id: params[:id].to_i)
|
||||
finder = finder.with_deleted if guardian.is_staff?
|
||||
|
||||
@ -14,7 +17,9 @@ class PostActionUsersController < ApplicationController
|
||||
|
||||
post_actions = post.post_actions.where(post_action_type_id: post_action_type_id)
|
||||
.includes(:user)
|
||||
.offset(page * page_size)
|
||||
.order('post_actions.created_at asc')
|
||||
.limit(page_size)
|
||||
|
||||
if !guardian.can_see_post_actors?(post.topic, post_action_type_id)
|
||||
if !current_user
|
||||
@ -23,6 +28,15 @@ class PostActionUsersController < ApplicationController
|
||||
post_actions = post_actions.where(user_id: current_user.id)
|
||||
end
|
||||
|
||||
render_serialized(post_actions.to_a, PostActionUserSerializer, root: 'post_action_users')
|
||||
action_type = PostActionType.types.key(post_action_type_id)
|
||||
total_count = post["#{action_type}_count"]
|
||||
|
||||
data = { post_action_users: serialize_data(post_actions.to_a, PostActionUserSerializer) }
|
||||
|
||||
if total_count > page_size
|
||||
data[:total_rows_post_action_users] = total_count
|
||||
end
|
||||
|
||||
render_json_dump(data)
|
||||
end
|
||||
end
|
||||
|
@ -1956,6 +1956,9 @@ en:
|
||||
notify_user: "sent a message"
|
||||
bookmark: "bookmarked this"
|
||||
like: "liked this"
|
||||
like_capped:
|
||||
one: "and {{count}} other liked this"
|
||||
other: "and {{count}} others liked this"
|
||||
vote: "voted for this"
|
||||
by_you:
|
||||
off_topic: "You flagged this as off-topic"
|
||||
|
@ -61,4 +61,24 @@ describe PostActionUsersController do
|
||||
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "paginates post actions" do
|
||||
user_ids = []
|
||||
5.times do
|
||||
user = Fabricate(:user)
|
||||
user_ids << user["id"]
|
||||
PostAction.act(user, post, PostActionType.types[:like])
|
||||
end
|
||||
|
||||
get :index, params: { id: post.id, post_action_type_id: PostActionType.types[:like], page: 1, limit: 2 }, format: :json
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
users = json["post_action_users"]
|
||||
total = json["total_rows_post_action_users"]
|
||||
|
||||
expect(users.length).to eq(2)
|
||||
expect(users.map { |u| u["id"] }).to eq(user_ids[2..3])
|
||||
|
||||
expect(total).to eq(5)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user