Skip to content

Commit

Permalink
clicking on a user mention now opens the chat panel with the info ins…
Browse files Browse the repository at this point in the history
…tead of the profile popup ; eliminated unnecessary UserInfoPopup components calls
  • Loading branch information
roienatan committed Nov 30, 2023
1 parent 30edd7d commit 3c923d1
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export default function ChatComponent({
multipleEmojiText: styles.multipleEmojiText,
},
onFeedItemClick,
onUserClick,
});
const {
chatMessagesData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ interface Return {
}

export const useDiscussionChatAdapter = (options: Options): Return => {
const { hasPermissionToHide, textStyles, discussionId, onFeedItemClick } =
options;
const {
hasPermissionToHide,
textStyles,
discussionId,
onFeedItemClick,
onUserClick,
} = options;
const user = useSelector(selectUser());
const userId = user?.uid;
const { data: commonMembers, fetchCommonMembers } = useCommonMembers();
Expand All @@ -46,6 +51,7 @@ export const useDiscussionChatAdapter = (options: Options): Return => {
users,
textStyles,
onFeedItemClick,
onUserClick,
});
const { markFeedItemAsSeen } = useMarkFeedItemAsSeen();

Expand Down
1 change: 0 additions & 1 deletion src/pages/commonFeed/CommonFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import {
import {
cacheActions,
commonActions,
commonLayoutActions,
selectCommonAction,
selectRecentStreamId,
selectSharedFeedItem,
Expand Down
20 changes: 4 additions & 16 deletions src/shared/components/Chat/ChatMessage/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ import React, {
import classNames from "classnames";
import { useLongPress } from "use-long-press";
import { DiscussionMessageService } from "@/services";
import {
ElementDropdown,
UserAvatar,
UserInfoPopup,
} from "@/shared/components";
import { ElementDropdown, UserAvatar } from "@/shared/components";
import {
Orientation,
ChatType,
EntityTypes,
QueryParamKey,
} from "@/shared/constants";
import { Colors } from "@/shared/constants";
import { useModal } from "@/shared/hooks";
//import { useModal } from "@/shared/hooks";
import { useIsTabletView } from "@/shared/hooks/viewport";
import { ModerationFlags } from "@/shared/interfaces/Moderation";
import {
Expand Down Expand Up @@ -146,17 +142,9 @@ export default function ChatMessage({
(discussionMessage.editedAt?.seconds ?? 0) * 1000,
);

const {
isShowing: isShowingUserProfile,
onClose: onCloseUserProfile,
onOpen: onOpenUserProfile,
} = useModal(false);

const handleUserClick = () => {
if (onUserClick && discussionMessageUserId) {
onUserClick(discussionMessageUserId);
} else {
onOpenUserProfile();
}
};

Expand Down Expand Up @@ -414,7 +402,7 @@ export default function ChatMessage({
</>
)}
</div>
{isShowingUserProfile && isUserDiscussionMessage && (
{/* {isShowingUserProfile && isUserDiscussionMessage && (
<UserInfoPopup
commonId={discussionMessage.commonId}
userId={discussionMessage.ownerId}
Expand All @@ -423,7 +411,7 @@ export default function ChatMessage({
onClose={onCloseUserProfile}
directParent={directParent}
/>
)}
)} */}
</li>
);
}
19 changes: 3 additions & 16 deletions src/shared/components/Chat/ChatMessage/DMChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import React, {
import classNames from "classnames";
import { useLongPress } from "use-long-press";
import { Logger } from "@/services";
import {
ElementDropdown,
UserAvatar,
UserInfoPopup,
} from "@/shared/components";
import { ElementDropdown, UserAvatar } from "@/shared/components";
import {
Orientation,
ChatType,
Expand All @@ -21,7 +17,6 @@ import {
} from "@/shared/constants";
import { Colors } from "@/shared/constants";
import { useRoutesContext } from "@/shared/contexts";
import { useModal } from "@/shared/hooks";
import { useIsTabletView } from "@/shared/hooks/viewport";
import { ModerationFlags } from "@/shared/interfaces/Moderation";
import {
Expand Down Expand Up @@ -122,17 +117,9 @@ export default function DMChatMessage({
(discussionMessage.editedAt?.seconds ?? 0) * 1000,
);

const {
isShowing: isShowingUserProfile,
onClose: onCloseUserProfile,
onOpen: onOpenUserProfile,
} = useModal(false);

const handleUserClick = () => {
if (onUserClick && discussionMessageUserId) {
onUserClick(discussionMessageUserId);
} else {
onOpenUserProfile();
}
};

Expand Down Expand Up @@ -472,7 +459,7 @@ export default function DMChatMessage({
</>
)}
</div>
{isShowingUserProfile && isUserDiscussionMessage && (
{/* {isShowingUserProfile && isUserDiscussionMessage && (
<UserInfoPopup
commonId={discussionMessage.commonId}
userId={discussionMessage.ownerId}
Expand All @@ -481,7 +468,7 @@ export default function DMChatMessage({
onClose={onCloseUserProfile}
directParent={directParent}
/>
)}
)} */}
</li>
);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { FC } from "react";
import classNames from "classnames";
import { UserInfoPopup } from "@/shared/components";
import { useModal } from "@/shared/hooks";
import { DirectParent, User } from "@/shared/models";
import { User } from "@/shared/models";
import { getUserName } from "@/shared/utils";
import styles from "../../ChatMessage.module.scss";

Expand All @@ -11,26 +9,13 @@ interface UserMentionProps {
userId: string;
displayName: string;
mentionTextClassName?: string;
commonId?: string;
directParent?: DirectParent | null;
onUserClick?: (userId: string) => void;
}

const UserMention: FC<UserMentionProps> = (props) => {
const {
users,
userId,
displayName,
mentionTextClassName,
commonId,
directParent,
onUserClick,
} = props;
const {
isShowing: isShowingUserProfile,
onClose: onCloseUserProfile,
onOpen: onOpenUserProfile,
} = useModal(false);
const { users, userId, displayName, mentionTextClassName, onUserClick } =
props;

const user = users.find(({ uid }) => uid === userId);
const withSpace = displayName[displayName.length - 1] === " ";
const userName = user
Expand All @@ -40,8 +25,6 @@ const UserMention: FC<UserMentionProps> = (props) => {
const handleUserNameClick = () => {
if (onUserClick) {
onUserClick(userId);
} else {
onOpenUserProfile();
}
};

Expand All @@ -53,16 +36,6 @@ const UserMention: FC<UserMentionProps> = (props) => {
>
@{userName}
</span>
{!onUserClick && (
<UserInfoPopup
avatar={user?.photoURL}
isShowing={isShowingUserProfile}
onClose={onCloseUserProfile}
commonId={commonId}
userId={user?.uid}
directParent={directParent}
/>
)}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ const renderUserMention = (
userId={user.uid}
displayName={getUserName(user)}
mentionTextClassName={data.mentionTextClassName}
commonId={data.commonId}
directParent={data.directParent}
onUserClick={data.onUserClick}
/>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ const getTextFromDescendant = ({
userId={descendant.userId}
displayName={descendant.displayName}
mentionTextClassName={mentionTextClassName}
commonId={commonId}
directParent={directParent}
onUserClick={onUserClick}
/>
);
Expand Down

0 comments on commit 3c923d1

Please sign in to comment.