From c311f3597d624b1e80f48a4f85e795c409a50f9d Mon Sep 17 00:00:00 2001 From: simoleo89 Date: Sun, 14 Jun 2026 20:26:47 +0200 Subject: [PATCH] fix(friendbar): guarantee a single find-friends chip (filter null friends) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The legacy bar rendered MAX_DISPLAY_COUNT FriendBarItemViews and padded empty slots with null, so an empty online-friends list produced three identical 'Trova Amici' buttons. The current bar already renders a single explicit search chip, but harden it: filter null/undefined out of the online-friends array before slicing/mapping so the search chip is the only possible source of that affordance — exactly one, always. --- .../friends/views/friends-bar/FriendsBarView.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/friends/views/friends-bar/FriendsBarView.tsx b/src/components/friends/views/friends-bar/FriendsBarView.tsx index 9234a07..aa66c09 100644 --- a/src/components/friends/views/friends-bar/FriendsBarView.tsx +++ b/src/components/friends/views/friends-bar/FriendsBarView.tsx @@ -79,11 +79,17 @@ export const FriendBarView: FC<{ onlineFriends: MessengerFriend[]; requestsCount // below uses it, so a stale `indexOffset` (after the list shrinks or the fit // grows) renders correctly and self-corrects on the next arrow click — no // write-back effect needed. - const maxOffset = Math.max(0, (onlineFriends.length - maxVisible)); + // Defensive: never let a null/undefined slip into the friend map. The + // legacy bar padded empty slots with `null` and rendered each as a + // FriendBarItemView (which falls back to the "find friends" chip), so an + // empty list produced THREE "Trova Amici" buttons. Filtering here makes the + // search chip below the ONLY source of that affordance — exactly one, always. + const validFriends = onlineFriends.filter(Boolean); + const maxOffset = Math.max(0, (validFriends.length - maxVisible)); const safeOffset = Math.min(indexOffset, maxOffset); const canScrollLeft = (safeOffset > 0); const canScrollRight = (safeOffset < maxOffset); - const visibleFriends = onlineFriends.slice(safeOffset, (safeOffset + maxVisible)); + const visibleFriends = validFriends.slice(safeOffset, (safeOffset + maxVisible)); return ( - { (!onlineFriends.length && (requestsCount <= 0)) && + { (!validFriends.length && (requestsCount <= 0)) &&