import { RelationshipStatusInfoEvent, RelationshipStatusInfoMessageParser, UserCurrentBadgesComposer, UserCurrentBadgesEvent, UserProfileEvent, UserProfileParser, UserRelationshipsComposer } from '@nitrots/nitro-renderer'; import { FC, useCallback, useState } from 'react'; import { GetSessionDataManager, GetUserProfile, LocalizeText, SendMessageComposer } from '../../api'; import { Column, Flex, Grid, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../common'; import { BatchUpdates, UseMessageEventHook } from '../../hooks'; import { BadgesContainerView } from './views/BadgesContainerView'; import { FriendsContainerView } from './views/FriendsContainerView'; import { GroupsContainerView } from './views/GroupsContainerView'; import { UserContainerView } from './views/UserContainerView'; export const UserProfileView: FC<{}> = props => { const [ userProfile, setUserProfile ] = useState(null); const [ userBadges, setUserBadges ] = useState([]); const [ userRelationships, setUserRelationships ] = useState(null); const onClose = () => { BatchUpdates(() => { setUserProfile(null); setUserBadges([]); setUserRelationships(null); }); } const onLeaveGroup = useCallback(() => { if(!userProfile || (userProfile.id !== GetSessionDataManager().userId)) return; GetUserProfile(userProfile.id); }, [ userProfile ]); const onUserCurrentBadgesEvent = useCallback((event: UserCurrentBadgesEvent) => { const parser = event.getParser(); if(!userProfile || (parser.userId !== userProfile.id)) return; setUserBadges(parser.badges); }, [ userProfile ]); UseMessageEventHook(UserCurrentBadgesEvent, onUserCurrentBadgesEvent); const onUserRelationshipsEvent = useCallback((event: RelationshipStatusInfoEvent) => { const parser = event.getParser(); if(!userProfile || (parser.userId !== userProfile.id)) return; setUserRelationships(parser); }, [ userProfile ]); UseMessageEventHook(RelationshipStatusInfoEvent, onUserRelationshipsEvent); const onUserProfileEvent = useCallback((event: UserProfileEvent) => { const parser = event.getParser(); BatchUpdates(() => { setUserProfile(parser); setUserBadges([]); setUserRelationships(null); }); SendMessageComposer(new UserCurrentBadgesComposer(parser.id)); SendMessageComposer(new UserRelationshipsComposer(parser.id)); }, []); UseMessageEventHook(UserProfileEvent, onUserProfileEvent); if(!userProfile) return null; return ( { userRelationships && } { LocalizeText('extendedprofile.rooms') } ) }