From 262fe87660bd832e35cb233fc338147e6e1ecc96 Mon Sep 17 00:00:00 2001 From: Dank074 Date: Fri, 13 Aug 2021 02:46:37 -0500 Subject: [PATCH] fix relationships --- src/views/Styles.scss | 1 + .../views/user/InfoStandWidgetUserView.tsx | 25 ++++++- src/views/user-profile/UserProfileVew.scss | 39 ----------- src/views/user-profile/UserProfileView.tsx | 18 ++--- .../badges-container/BadgesContainerView.tsx | 12 +++- .../FriendsContainerView.tsx | 45 ++---------- .../FriendsContainerView.types.ts | 4 +- .../RelationshipsContainerView.scss | 38 ++++++++++ .../RelationshipsContainerView.tsx | 69 +++++++++++++++++++ .../RelationshipsContainerView.types.ts | 7 ++ .../user-container/UserContainerView.tsx | 2 +- 11 files changed, 163 insertions(+), 97 deletions(-) create mode 100644 src/views/user-profile/views/relationships-container/RelationshipsContainerView.scss create mode 100644 src/views/user-profile/views/relationships-container/RelationshipsContainerView.tsx create mode 100644 src/views/user-profile/views/relationships-container/RelationshipsContainerView.types.ts diff --git a/src/views/Styles.scss b/src/views/Styles.scss index 3538a563..53237ab7 100644 --- a/src/views/Styles.scss +++ b/src/views/Styles.scss @@ -17,3 +17,4 @@ @import './mod-tools/ModToolsView'; @import './achievements/AchievementsView'; @import './user-profile/UserProfileVew'; +@import './user-profile/views/relationships-container/RelationshipsContainerView'; diff --git a/src/views/room/widgets/infostand/views/user/InfoStandWidgetUserView.tsx b/src/views/room/widgets/infostand/views/user/InfoStandWidgetUserView.tsx index 5d8b3cb5..ea65abe3 100644 --- a/src/views/room/widgets/infostand/views/user/InfoStandWidgetUserView.tsx +++ b/src/views/room/widgets/infostand/views/user/InfoStandWidgetUserView.tsx @@ -1,9 +1,11 @@ -import { RoomSessionUserBadgesEvent } from '@nitrots/nitro-renderer'; +import { RelationshipStatusInfoEvent, RelationshipStatusInfoMessageParser, RoomSessionUserBadgesEvent, UserRelationshipsComposer } from '@nitrots/nitro-renderer'; import { FC, FocusEvent, KeyboardEvent, useCallback, useEffect, useState } from 'react'; +import { CreateMessageHook, SendMessageHook } from '../../../../../../hooks'; import { CreateEventDispatcherHook } from '../../../../../../hooks/events'; import { LocalizeText } from '../../../../../../utils/LocalizeText'; import { AvatarImageView } from '../../../../../shared/avatar-image/AvatarImageView'; import { BadgeImageView } from '../../../../../shared/badge-image/BadgeImageView'; +import { RelationshipsContainerView } from '../../../../../user-profile/views/relationships-container/RelationshipsContainerView'; import { useRoomContext } from '../../../../context/RoomContext'; import { RoomWidgetUpdateInfostandUserEvent } from '../../../../events/RoomWidgetUpdateInfostandUserEvent'; import { RoomWidgetChangeMottoMessage } from '../../../../messages'; @@ -16,6 +18,7 @@ export const InfoStandWidgetUserView: FC = props = const [ badges, setBadges ] = useState([]); const [ motto, setMotto ] = useState(null); const [ isEditingMotto, setIsEditingMotto ] = useState(false); + const [ userRelationships, setUserRelationships ] = useState(null); const saveMotto = useCallback((motto: string) => { @@ -50,11 +53,27 @@ export const InfoStandWidgetUserView: FC = props = CreateEventDispatcherHook(RoomSessionUserBadgesEvent.RSUBE_BADGES, eventDispatcher, onRoomSessionUserBadgesEvent); + const OnUserRelationshipsEvent = useCallback((event: RelationshipStatusInfoEvent) => + { + const parser = event.getParser(); + + if (userData && userData.webID === parser.userId) + setUserRelationships(parser); + }, [userData]); + + CreateMessageHook(RelationshipStatusInfoEvent, OnUserRelationshipsEvent); + useEffect(() => { setBadges(userData.badges); setIsEditingMotto(false); setMotto(userData.motto); + SendMessageHook(new UserRelationshipsComposer(userData.webID)); + + return () => { + setBadges([]); + setUserRelationships(null); + } }, [ userData ]); if(!userData) return null; @@ -122,7 +141,9 @@ export const InfoStandWidgetUserView: FC = props =
{ LocalizeText('infostand.text.handitem', [ 'item' ], [ LocalizeText('handitem' + userData.carryItem) ]) }
- } + + } + ); } diff --git a/src/views/user-profile/UserProfileVew.scss b/src/views/user-profile/UserProfileVew.scss index 86945fc4..49fd142f 100644 --- a/src/views/user-profile/UserProfileVew.scss +++ b/src/views/user-profile/UserProfileVew.scss @@ -24,11 +24,6 @@ border-radius: 5px; margin: 0px; margin-bottom: 2px; - - .badge-image { - margin-left: 2px; - margin-right: 2px; - } } .rooms-button-container @@ -49,39 +44,5 @@ .friends-container { height: 100%; - - .relationships-container { - - .relationship-container { - margin: 10px; - - .relationship - { - margin-left: 10px; - background-color: white; - padding: 5px; - border-radius: 5px; - display: inline-block; - text-decoration: underline; - width: 100%; - - .relationship-text - { - cursor: pointer; - } - - .avatar-image { - position: absolute; - width: 50px; - height: 80px; - right: 0; - margin-top: -60px; - margin-right: 10px; - } - } - } - - } - } } diff --git a/src/views/user-profile/UserProfileView.tsx b/src/views/user-profile/UserProfileView.tsx index 8c443849..2865137b 100644 --- a/src/views/user-profile/UserProfileView.tsx +++ b/src/views/user-profile/UserProfileView.tsx @@ -1,4 +1,4 @@ -import { UserCurrentBadgesComposer, UserCurrentBadgesEvent, UserProfileEvent, UserProfileParser, UserRelationshipsComposer, UserRelationshipsEvent, UserRelationshipsParser } from '@nitrots/nitro-renderer'; +import { RelationshipStatusInfoEvent, RelationshipStatusInfoMessageParser, UserCurrentBadgesComposer, UserCurrentBadgesEvent, UserProfileEvent, UserProfileParser, UserRelationshipsComposer } from '@nitrots/nitro-renderer'; import { FC, useCallback, useState } from 'react'; import { CreateMessageHook, SendMessageHook } from '../../hooks'; import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../layout'; @@ -11,7 +11,7 @@ export const UserProfileView: FC = props => { const [userProfile, setUserProfile] = useState(null); const [userBadges, setUserBadges] = useState([]); - const [userRelationships, setUserRelationships] = useState(null); + const [userRelationships, setUserRelationships] = useState(null); const OnClose = useCallback(() => { @@ -30,15 +30,15 @@ export const UserProfileView: FC = props => CreateMessageHook(UserCurrentBadgesEvent, OnUserCurrentBadgesEvent); - const OnUserRelationshipsEvent = useCallback((event: UserRelationshipsEvent) => + const OnUserRelationshipsEvent = useCallback((event: RelationshipStatusInfoEvent) => { const parser = event.getParser(); - if (userProfile && parser.id === userProfile.id) + if (userProfile && parser.userId === userProfile.id) setUserRelationships(parser); }, [userProfile, setUserRelationships]); - CreateMessageHook(UserRelationshipsEvent, OnUserRelationshipsEvent); + CreateMessageHook(RelationshipStatusInfoEvent, OnUserRelationshipsEvent); const OnUserProfileEvent = useCallback((event: UserProfileEvent) => { @@ -65,13 +65,13 @@ export const UserProfileView: FC = props =>
-
- +
+
-
+
{ - userRelationships && + userRelationships && }
diff --git a/src/views/user-profile/views/badges-container/BadgesContainerView.tsx b/src/views/user-profile/views/badges-container/BadgesContainerView.tsx index 246dac09..4e7eafb2 100644 --- a/src/views/user-profile/views/badges-container/BadgesContainerView.tsx +++ b/src/views/user-profile/views/badges-container/BadgesContainerView.tsx @@ -7,13 +7,19 @@ export const BadgesContainerView: FC = props => const {badges = null} = props; return ( -
-
+
+
+
{ badges.map( (badge, index) => { - return + return ( +
+ +
+ ) }) } +
); diff --git a/src/views/user-profile/views/friends-container/FriendsContainerView.tsx b/src/views/user-profile/views/friends-container/FriendsContainerView.tsx index 5593da4f..3bb06e9f 100644 --- a/src/views/user-profile/views/friends-container/FriendsContainerView.tsx +++ b/src/views/user-profile/views/friends-container/FriendsContainerView.tsx @@ -1,54 +1,17 @@ -import { UserProfileComposer, UserRelationshipDataParser } from '@nitrots/nitro-renderer'; -import { FC, useCallback } from 'react'; -import { SendMessageHook } from '../../../../hooks'; +import { FC } from 'react'; import { LocalizeText } from '../../../../utils'; -import { AvatarImageView } from '../../../shared/avatar-image/AvatarImageView'; +import { RelationshipsContainerView } from '../relationships-container/RelationshipsContainerView'; import { FriendsContainerViewProps } from './FriendsContainerView.types'; export const FriendsContainerView: FC = props => { const { relationships = null, friendsCount = null } = props; - const OnUserClick = useCallback((user: UserRelationshipDataParser) => - { - if(user) - SendMessageHook(new UserProfileComposer(user.userId)); - }, []); - - const RelationshipComponent = useCallback(({ type }) => - { - const randomUserIndex = (relationships && relationships.has(type) && relationships.get(type).length) ? - Math.floor(Math.random() * relationships.get(type).length) : -1; - - const randomUser = randomUserIndex > -1 ? relationships.get(type)[randomUserIndex] : null; - - return ( -
- - - OnUserClick(randomUser)}> - { - randomUser ? randomUser.username : LocalizeText('extendedprofile.add.friends') - } - - { - randomUser && - - } - -
- ); - }, [OnUserClick, relationships]); - return ( -
+
{LocalizeText('extendedprofile.relstatus')}
-
- - - -
+
) } diff --git a/src/views/user-profile/views/friends-container/FriendsContainerView.types.ts b/src/views/user-profile/views/friends-container/FriendsContainerView.types.ts index 7d215e2d..99ba31df 100644 --- a/src/views/user-profile/views/friends-container/FriendsContainerView.types.ts +++ b/src/views/user-profile/views/friends-container/FriendsContainerView.types.ts @@ -1,6 +1,6 @@ -import { UserRelationshipDataParser } from '@nitrots/nitro-renderer'; +import { RelationshipStatusInfoMessageParser } from '@nitrots/nitro-renderer'; export interface FriendsContainerViewProps { - relationships: Map; + relationships: RelationshipStatusInfoMessageParser; friendsCount: number; } diff --git a/src/views/user-profile/views/relationships-container/RelationshipsContainerView.scss b/src/views/user-profile/views/relationships-container/RelationshipsContainerView.scss new file mode 100644 index 00000000..cc722c8f --- /dev/null +++ b/src/views/user-profile/views/relationships-container/RelationshipsContainerView.scss @@ -0,0 +1,38 @@ +.relationships-container { + + .relationship-container { + //margin-bottom: 10px; + + .relationship + { + margin-left: 10px; + display: inline-block; + + &.advanced { + background-color: white; + padding: 5px; + border-radius: 5px; + } + + .relationship-text { + text-decoration: underline; + } + + .avatar-image { + position: absolute; + width: 50px; + height: 80px; + right: 0; + margin-top: -60px; + margin-right: 10px; + } + } + + .others-text { + margin-left: 20px; + height: 21px; + color: #939392; + } + } + +} diff --git a/src/views/user-profile/views/relationships-container/RelationshipsContainerView.tsx b/src/views/user-profile/views/relationships-container/RelationshipsContainerView.tsx new file mode 100644 index 00000000..be21d944 --- /dev/null +++ b/src/views/user-profile/views/relationships-container/RelationshipsContainerView.tsx @@ -0,0 +1,69 @@ +import { RelationshipStatusEnum, RelationshipStatusInfo, UserProfileComposer } from '@nitrots/nitro-renderer'; +import { FC, useCallback } from 'react'; +import { SendMessageHook } from '../../../../hooks'; +import { LocalizeText } from '../../../../utils'; +import { AvatarImageView } from '../../../shared/avatar-image/AvatarImageView'; +import { RelationshipsContainerViewProps } from './RelationshipsContainerView.types'; + +export const RelationshipsContainerView: FC = props => +{ + const { relationships = null, simple = false } = props; + + const OnUserClick = useCallback((user: RelationshipStatusInfo) => + { + if (user) + SendMessageHook(new UserProfileComposer(user.randomFriendId)); + }, []); + + const RelationshipComponent = useCallback(({ type }) => + { + const relationshipInfo = (relationships && relationships.relationshipStatusMap.hasKey(type)) ? relationships.relationshipStatusMap.getValue(type) : null; + + if (simple && !relationshipInfo) return null; + + const relationshipName = RelationshipStatusEnum.RELATIONSHIP_NAMES[type].toLocaleLowerCase(); + + return ( +
+ + + OnUserClick(relationshipInfo)}> + { + (relationshipInfo && relationshipInfo.friendCount > 0) ? relationshipInfo.randomFriendName : LocalizeText('extendedprofile.add.friends') + } + + { + (simple && relationshipInfo && relationshipInfo.friendCount > 1) && + + {' ' + LocalizeText(`extendedprofile.relstatus.others.${relationshipName}`, ['count'], [(relationshipInfo.friendCount - 1).toString()])} + + } + { + (!simple && relationshipInfo && relationshipInfo.friendCount > 0) && + + } + + + { + !simple &&
+ { + (relationshipInfo && relationshipInfo.friendCount > 1) ? LocalizeText(`extendedprofile.relstatus.others.${relationshipName}`, ['count'], [(relationshipInfo.friendCount - 1).toString()]) : '' + } + { + (relationshipInfo && relationshipInfo.friendCount < 1) ? LocalizeText('extendedprofile.no.friends.in.this.category') : '' + } +
+ } + +
+ ); + }, [OnUserClick, relationships, simple]); + + return ( +
+ + + +
+ ); +} diff --git a/src/views/user-profile/views/relationships-container/RelationshipsContainerView.types.ts b/src/views/user-profile/views/relationships-container/RelationshipsContainerView.types.ts new file mode 100644 index 00000000..2bf0d119 --- /dev/null +++ b/src/views/user-profile/views/relationships-container/RelationshipsContainerView.types.ts @@ -0,0 +1,7 @@ +import { RelationshipStatusInfoMessageParser } from '@nitrots/nitro-renderer'; + +export interface RelationshipsContainerViewProps +{ + relationships: RelationshipStatusInfoMessageParser; + simple?: boolean; +} diff --git a/src/views/user-profile/views/user-container/UserContainerView.tsx b/src/views/user-profile/views/user-container/UserContainerView.tsx index 28a5ad6b..5cd9393d 100644 --- a/src/views/user-profile/views/user-container/UserContainerView.tsx +++ b/src/views/user-profile/views/user-container/UserContainerView.tsx @@ -34,7 +34,7 @@ export const UserContainerView: FC = props =>
{username}
{motto}
-
+
{LocalizeText('extendedprofile.achievementscore')} {achievementScore}