import { X, UserPlus, UserMinus } from 'lucide-react' import { useNavigate } from 'react-router-dom' import { useState } from 'react' import { followUser, unfollowUser } from '../utils/api' import { hapticFeedback } from '../utils/telegram' import './FollowListModal.css' export default function FollowListModal({ users, title, onClose, currentUser }) { const navigate = useNavigate() const [userStates, setUserStates] = useState( users.reduce((acc, user) => { acc[user._id] = { isFollowing: currentUser?.following?.some(f => f._id === user._id || f === user._id) || false } return acc }, {}) ) const handleOverlayClick = (e) => { if (e.target === e.currentTarget) { onClose() } } const handleUserClick = (userId) => { hapticFeedback('light') onClose() navigate(`/user/${userId}`) } const handleFollowToggle = async (userId, e) => { e.stopPropagation() try { hapticFeedback('light') const isCurrentlyFollowing = userStates[userId]?.isFollowing || false if (isCurrentlyFollowing) { await unfollowUser(userId) setUserStates(prev => ({ ...prev, [userId]: { isFollowing: false } })) } else { await followUser(userId) setUserStates(prev => ({ ...prev, [userId]: { isFollowing: true } })) } hapticFeedback('success') } catch (error) { console.error('Ошибка подписки:', error) hapticFeedback('error') } } return (
e.stopPropagation()} onTouchStart={(e) => e.stopPropagation()} onClick={handleOverlayClick} >
e.stopPropagation()}> {/* Хедер */}

{title}

{/* Список пользователей */}
{users.length === 0 ? (

Пока никого нет

) : (
{users.map((user) => { const isOwnProfile = user._id === currentUser?.id const isFollowing = userStates[user._id]?.isFollowing || false return (
handleUserClick(user._id)} > {user.username { e.target.src = '/default-avatar.png' }} />
{user.firstName || ''} {user.lastName || ''} {!user.firstName && !user.lastName && 'Пользователь'}
@{user.username || user.firstName || 'user'}
{!isOwnProfile && ( )}
) })}
)}
) }