Fix friend list selected users

This commit is contained in:
Bill 2022-03-16 22:34:15 -04:00
parent c82b9653dd
commit 6f634cc6af

View File

@ -21,9 +21,7 @@ interface FriendsListViewProps
export const FriendsListView: FC<FriendsListViewProps> = props => export const FriendsListView: FC<FriendsListViewProps> = props =>
{ {
const { onlineFriends = [], offlineFriends = [], friendRequests = [], onCloseClick = null } = props; const { onlineFriends = [], offlineFriends = [], friendRequests = [], onCloseClick = null } = props;
const [ selectedFriendsIds, setSelectedFriendsIds ] = useState<number[]>([]); const [ selectedFriendsIds, setSelectedFriendsIds ] = useState<number[]>([]);
const [ showRoomInvite, setShowRoomInvite ] = useState<boolean>(false); const [ showRoomInvite, setShowRoomInvite ] = useState<boolean>(false);
const [ showRemoveFriendsConfirmation, setShowRemoveFriendsConfirmation ] = useState<boolean>(false); const [ showRemoveFriendsConfirmation, setShowRemoveFriendsConfirmation ] = useState<boolean>(false);
@ -44,44 +42,53 @@ export const FriendsListView: FC<FriendsListViewProps> = props =>
userNames.push(existingFriend.name); userNames.push(existingFriend.name);
} }
return LocalizeText('friendlist.removefriendconfirm.userlist', ['user_names'], [userNames.join(', ')]); return LocalizeText('friendlist.removefriendconfirm.userlist', [ 'user_names' ], [ userNames.join(', ') ]);
}, [offlineFriends, onlineFriends, selectedFriendsIds]); }, [offlineFriends, onlineFriends, selectedFriendsIds]);
const selectFriend = useCallback((userId: number) => const selectFriend = useCallback((userId: number) =>
{ {
if(userId < 0) return; if(userId < 0) return;
const existingUserIdIndex: number = selectedFriendsIds.indexOf(userId);
if(existingUserIdIndex > -1) setSelectedFriendsIds(prevValue =>
{ {
const clonedFriend = [...selectedFriendsIds]; const newValue = [ ...prevValue ];
clonedFriend.splice(existingUserIdIndex, 1)
setSelectedFriendsIds([...clonedFriend]);
}
else
{
setSelectedFriendsIds([...selectedFriendsIds, userId]);
}
}, [ selectedFriendsIds, setSelectedFriendsIds ]);
const sendRoomInvite = useCallback((message: string) => const existingUserIdIndex: number = newValue.indexOf(userId);
if(existingUserIdIndex > -1)
{
newValue.splice(existingUserIdIndex, 1)
}
else
{
newValue.push(userId);
}
return newValue;
});
}, [ setSelectedFriendsIds ]);
const sendRoomInvite = (message: string) =>
{ {
if(selectedFriendsIds.length === 0 || !message || message.length === 0) return; if(selectedFriendsIds.length === 0 || !message || message.length === 0) return;
SendMessageComposer(new SendRoomInviteComposer(message, ...selectedFriendsIds)); SendMessageComposer(new SendRoomInviteComposer(message, ...selectedFriendsIds));
setShowRoomInvite(false); setShowRoomInvite(false);
}, [ selectedFriendsIds, setShowRoomInvite ]); }
const removeSelectedFriends = useCallback(() => const removeSelectedFriends = () =>
{ {
if(selectedFriendsIds.length === 0) return; if(selectedFriendsIds.length === 0) return;
SendMessageComposer(new RemoveFriendComposer(...selectedFriendsIds)); setSelectedFriendsIds(prevValue =>
setSelectedFriendsIds([]); {
SendMessageComposer(new RemoveFriendComposer(...prevValue));
return [];
});
setShowRemoveFriendsConfirmation(false); setShowRemoveFriendsConfirmation(false);
}, [ selectedFriendsIds ]); }
return ( return (
<> <>