feat(friends): pure category filter + count helpers

This commit is contained in:
simoleo89
2026-06-02 17:54:30 +02:00
parent 76b7e21494
commit f9320b4582
3 changed files with 86 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
import { MessengerFriend } from './MessengerFriend';
/**
* Filter a friend list to a single category. categoryId 0 means
* "All" (no filtering) and returns the list unchanged.
*/
export const filterFriendsByCategory = (friends: MessengerFriend[], categoryId: number): MessengerFriend[] =>
{
if(!friends) return [];
if(!categoryId) return friends;
return friends.filter(friend => (friend.categoryId === categoryId));
};
/**
* Count how many friends belong to each category id. Used to render
* member counts on the group chips.
*/
export const countFriendsByCategory = (friends: MessengerFriend[]): Map<number, number> =>
{
const counts = new Map<number, number>();
if(!friends) return counts;
for(const friend of friends)
{
counts.set(friend.categoryId, (counts.get(friend.categoryId) ?? 0) + 1);
}
return counts;
};