mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-20 23:46:19 +00:00
feat(friends): pure category filter + count helpers
This commit is contained in:
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user