import React, { useState } from 'react'; import { useQuery } from 'convex/react'; import { api } from '../../../../convex/_generated/api'; import Avatar from './Avatar'; import ColoredIcon from './ColoredIcon'; import { useOnlineUsers } from '../contexts/PresenceContext'; import friendsIcon from '../assets/icons/friends.svg'; const FriendsView = ({ onOpenDM }) => { const [activeTab, setActiveTab] = useState('Online'); const [addFriendSearch, setAddFriendSearch] = useState(''); const myId = localStorage.getItem('userId'); const { resolveStatus } = useOnlineUsers(); const allUsers = useQuery(api.auth.getPublicKeys) || []; const users = allUsers.filter(u => u.id !== myId); const getUserColor = (username) => { if (!username) return '#747f8d'; const colors = ['#5865F2', '#EBA7CD', '#57F287', '#FEE75C', '#EB459E', '#ED4245']; let hash = 0; for (let i = 0; i < username.length; i++) { hash = username.charCodeAt(i) + ((hash << 5) - hash); } return colors[Math.abs(hash) % colors.length]; }; const STATUS_COLORS = { online: '#3ba55c', idle: '#faa61a', dnd: '#ed4245', invisible: '#747f8d', offline: '#747f8d', }; const filteredUsers = activeTab === 'Online' ? users.filter(u => resolveStatus(u.status, u.id) !== 'offline') : activeTab === 'Add Friend' ? users.filter(u => u.username?.toLowerCase().includes(addFriendSearch.toLowerCase())) : users; return (