Update friend list

This commit is contained in:
Bill 2021-07-08 04:25:57 -04:00
parent c7fe32411f
commit 7893de3a34
3 changed files with 29 additions and 4 deletions

View File

@ -0,0 +1,20 @@
import { FriendListEvent } from './FriendListEvent';
export class FriendListSendFriendRequestEvent extends FriendListEvent
{
public static SEND_FRIEND_REQUEST: string = 'FLSFRE_SEND_FRIEND_REQUEST';
private _userId: number;
constructor(userId: number)
{
super(FriendListSendFriendRequestEvent.SEND_FRIEND_REQUEST);
this._userId = userId;
}
public get userId(): number
{
return this._userId;
}
}

View File

@ -1,8 +1,9 @@
import { MessengerInitComposer, RoomEngineObjectEvent, RoomObjectCategory } from 'nitro-renderer'; import { MessengerInitComposer, RoomEngineObjectEvent, RoomObjectCategory, RoomObjectUserType } from 'nitro-renderer';
import React, { FC, useCallback, useEffect, useReducer, useState } from 'react'; import React, { FC, useCallback, useEffect, useReducer, useState } from 'react';
import { createPortal } from 'react-dom'; import { createPortal } from 'react-dom';
import { GetRoomSession } from '../../api'; import { GetRoomSession } from '../../api';
import { FriendEnteredRoomEvent, FriendListEvent } from '../../events'; import { FriendEnteredRoomEvent, FriendListEvent } from '../../events';
import { FriendListSendFriendRequestEvent } from '../../events/friend-list/FriendListSendFriendRequestEvent';
import { useRoomEngineEvent } from '../../hooks/events'; import { useRoomEngineEvent } from '../../hooks/events';
import { dispatchUiEvent, useUiEvent } from '../../hooks/events/ui/ui-event'; import { dispatchUiEvent, useUiEvent } from '../../hooks/events/ui/ui-event';
import { SendMessageHook } from '../../hooks/messages/message-event'; import { SendMessageHook } from '../../hooks/messages/message-event';
@ -32,11 +33,15 @@ export const FriendListView: FC<FriendListViewProps> = props =>
case FriendListEvent.TOGGLE_FRIEND_LIST: case FriendListEvent.TOGGLE_FRIEND_LIST:
setIsVisible(value => !value); setIsVisible(value => !value);
return; return;
case FriendListSendFriendRequestEvent.SEND_FRIEND_REQUEST:
const requestEvent = (event as FriendListSendFriendRequestEvent);
return;
} }
}, []); }, []);
useUiEvent(FriendListEvent.SHOW_FRIEND_LIST, onFriendListEvent); useUiEvent(FriendListEvent.SHOW_FRIEND_LIST, onFriendListEvent);
useUiEvent(FriendListEvent.TOGGLE_FRIEND_LIST, onFriendListEvent); useUiEvent(FriendListEvent.TOGGLE_FRIEND_LIST, onFriendListEvent);
useUiEvent(FriendListSendFriendRequestEvent.SEND_FRIEND_REQUEST, onFriendListEvent);
useEffect(() => useEffect(() =>
{ {
@ -60,7 +65,7 @@ export const FriendListView: FC<FriendListViewProps> = props =>
const userData = roomSession.userDataManager.getUserDataByIndex(event.objectId); const userData = roomSession.userDataManager.getUserDataByIndex(event.objectId);
if(!userData) return; if(!userData || (userData.type !== RoomObjectUserType.getTypeNumber(RoomObjectUserType.USER))) return;
const friend = friendListState.friends.find(friend => const friend = friendListState.friends.find(friend =>
{ {

View File

@ -1,6 +1,6 @@
import { FollowFriendComposer, MouseEventType } from 'nitro-renderer'; import { FollowFriendComposer, MouseEventType } from 'nitro-renderer';
import { FC, useCallback, useEffect, useRef, useState } from 'react'; import { FC, useCallback, useEffect, useRef, useState } from 'react';
import { GetConnection } from '../../../../api'; import { SendMessageHook } from '../../../../hooks/messages';
import { LocalizeText } from '../../../../utils/LocalizeText'; import { LocalizeText } from '../../../../utils/LocalizeText';
import { AvatarImageView } from '../../../shared/avatar-image/AvatarImageView'; import { AvatarImageView } from '../../../shared/avatar-image/AvatarImageView';
import { FriendBarItemViewProps } from './FriendBarItemView.types'; import { FriendBarItemViewProps } from './FriendBarItemView.types';
@ -13,7 +13,7 @@ export const FriendBarItemView: FC<FriendBarItemViewProps> = props =>
const followFriend = useCallback(() => const followFriend = useCallback(() =>
{ {
GetConnection().send(new FollowFriendComposer(friend.id)); SendMessageHook(new FollowFriendComposer(friend.id));
}, [ friend ]); }, [ friend ]);
const onClick = useCallback((event: MouseEvent) => const onClick = useCallback((event: MouseEvent) =>