mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-23 14:40:50 +01:00
Fix friend list selected users
This commit is contained in:
parent
c82b9653dd
commit
6f634cc6af
@ -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);
|
||||||
|
|
||||||
@ -51,37 +49,46 @@ export const FriendsListView: FC<FriendsListViewProps> = props =>
|
|||||||
{
|
{
|
||||||
if(userId < 0) return;
|
if(userId < 0) return;
|
||||||
|
|
||||||
const existingUserIdIndex: number = selectedFriendsIds.indexOf(userId);
|
setSelectedFriendsIds(prevValue =>
|
||||||
|
{
|
||||||
|
const newValue = [ ...prevValue ];
|
||||||
|
|
||||||
|
const existingUserIdIndex: number = newValue.indexOf(userId);
|
||||||
|
|
||||||
if(existingUserIdIndex > -1)
|
if(existingUserIdIndex > -1)
|
||||||
{
|
{
|
||||||
const clonedFriend = [...selectedFriendsIds];
|
newValue.splice(existingUserIdIndex, 1)
|
||||||
clonedFriend.splice(existingUserIdIndex, 1)
|
|
||||||
|
|
||||||
setSelectedFriendsIds([...clonedFriend]);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setSelectedFriendsIds([...selectedFriendsIds, userId]);
|
newValue.push(userId);
|
||||||
}
|
}
|
||||||
}, [ selectedFriendsIds, setSelectedFriendsIds ]);
|
|
||||||
|
|
||||||
const sendRoomInvite = useCallback((message: string) =>
|
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 (
|
||||||
<>
|
<>
|
||||||
|
Loading…
Reference in New Issue
Block a user