From 8ae21a630d626182f3ae446751620727dd1fa997 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 22 Oct 2015 10:38:28 +0200 Subject: [PATCH] Prevent "and 1 others" in list of likes Refs flarum/core#546. --- extensions/likes/js/forum/dist/extension.js | 13 +++++++------ extensions/likes/js/forum/src/addLikesList.js | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/extensions/likes/js/forum/dist/extension.js b/extensions/likes/js/forum/dist/extension.js index ca5019a45..c81f79d60 100644 --- a/extensions/likes/js/forum/dist/extension.js +++ b/extensions/likes/js/forum/dist/extension.js @@ -79,13 +79,14 @@ System.register('flarum/likes/addLikesList', ['flarum/extend', 'flarum/app', 'fl var likes = post.likes(); if (likes && likes.length) { - var limit = 3; + var limit = 4; + var overLimit = likes.length > limit; - // Construct a list of names of users who have like this post. Make sure the - // current user is first in the list, and cap a maximum of 3 names. + // Construct a list of names of users who have liked this post. Make sure the + // current user is first in the list, and cap a maximum of 4 items. var names = likes.sort(function (a) { return a === app.session.user ? -1 : 1; - }).slice(0, limit).map(function (user) { + }).slice(0, overLimit ? limit - 1 : limit).map(function (user) { return m( 'a', { href: app.route.user(user), config: m.route }, @@ -96,8 +97,8 @@ System.register('flarum/likes/addLikesList', ['flarum/extend', 'flarum/app', 'fl // If there are more users that we've run out of room to display, add a "x // others" name to the end of the list. Clicking on it will display a modal // with a full list of names. - if (likes.length > limit) { - var count = likes.length - limit; + if (overLimit) { + var count = likes.length - names.length; names.push(m( 'a', diff --git a/extensions/likes/js/forum/src/addLikesList.js b/extensions/likes/js/forum/src/addLikesList.js index 68d9e44d1..707b20acc 100644 --- a/extensions/likes/js/forum/src/addLikesList.js +++ b/extensions/likes/js/forum/src/addLikesList.js @@ -13,12 +13,13 @@ export default function() { const likes = post.likes(); if (likes && likes.length) { - const limit = 3; + const limit = 4; + const overLimit = likes.length > limit; - // Construct a list of names of users who have like this post. Make sure the - // current user is first in the list, and cap a maximum of 3 names. + // Construct a list of names of users who have liked this post. Make sure the + // current user is first in the list, and cap a maximum of 4 items. const names = likes.sort(a => a === app.session.user ? -1 : 1) - .slice(0, limit) + .slice(0, overLimit ? limit - 1 : limit) .map(user => { return ( @@ -30,8 +31,8 @@ export default function() { // If there are more users that we've run out of room to display, add a "x // others" name to the end of the list. Clicking on it will display a modal // with a full list of names. - if (likes.length > limit) { - const count = likes.length - limit; + if (overLimit) { + const count = likes.length - names.length; names.push( {