Исправил неработющую функцию добавления пользователя через чат в группу

This commit is contained in:
max
2026-04-17 00:42:03 +03:00
parent ca9cf27716
commit e05572fc3f

View File

@@ -76,9 +76,10 @@ export default function GroupSettings({ chat, onClose, onGoToMessage }: GroupSet
const fileInputRef = useRef<HTMLInputElement>(null);
const searchInputRef = useRef<HTMLInputElement>(null);
const getSearchedUserId = (u: UserPresence & { userId?: string }) => u.id || u.userId || '';
// Keep local state in sync with chat prop
useEffect(() => {
useEffect(() => {
setGroupName(chat.name || '');
setGroupDesc(chat.description || '');
}, [chat.name, chat.description]);
@@ -95,7 +96,10 @@ export default function GroupSettings({ chat, onClose, onGoToMessage }: GroupSet
const results = await UserApi.searchUsers(searchQuery);
// Filter out users already in the group
const memberIds = new Set(chat.members.map((m) => m.user.id));
setSearchResults(results.filter((u) => !memberIds.has(u.id)));
setSearchResults(results.filter((u) => {
const candidateId = getSearchedUserId(u as UserPresence & { userId?: string });
return !!candidateId && !memberIds.has(candidateId);
}));
} catch (e) {
console.error(e);
} finally {
@@ -565,10 +569,13 @@ export default function GroupSettings({ chat, onClose, onGoToMessage }: GroupSet
<Loader2 size={16} className="text-zinc-500 animate-spin" />
</div>
)}
{searchResults.map((u) => (
{searchResults.map((u) => {
const candidateId = getSearchedUserId(u as UserPresence & { userId?: string });
if (!candidateId) return null;
return (
<button
key={u.id}
onClick={() => handleAddMember(u.id)}
key={candidateId}
onClick={() => handleAddMember(candidateId)}
className="flex items-center gap-3 w-full px-3 py-2 rounded-xl hover:bg-surface-hover transition-colors"
>
<Avatar
@@ -583,7 +590,8 @@ export default function GroupSettings({ chat, onClose, onGoToMessage }: GroupSet
</div>
<UserPlus size={14} className="text-knot-400 flex-shrink-0" />
</button>
))}
);
})}
{searchQuery.trim() && !isSearching && searchResults.length === 0 && (
<p className="text-xs text-zinc-500 text-center py-2">{t('usersNotFound')}</p>
)}