From d43345d6fe6efd4ea8fee54c4d03bd536c9cd618 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 12 Sep 2023 09:48:42 +0300 Subject: [PATCH 1/2] fix created item selection --- src/pages/commonFeed/CommonFeed.tsx | 7 +++-- .../components/FeedLayout/FeedLayout.tsx | 28 +------------------ 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/src/pages/commonFeed/CommonFeed.tsx b/src/pages/commonFeed/CommonFeed.tsx index 682b14d731..0b84d4038d 100644 --- a/src/pages/commonFeed/CommonFeed.tsx +++ b/src/pages/commonFeed/CommonFeed.tsx @@ -253,8 +253,11 @@ const CommonFeedComponent: FC = (props) => { checkIsFeedItemFollowLayoutItem(firstItem) && recentStreamId === firstItem.feedItem.data.id ) { - feedLayoutRef?.setShouldAllowChatAutoOpen(true); - feedLayoutRef?.setExpandedFeedItemId(firstItem.feedItem.id); + feedLayoutRef?.setActiveItem({ + feedItemId: firstItem.feedItem.id, + circleVisibility: [], + }); + dispatch(commonActions.setRecentStreamId("")); } }, [feedLayoutRef, recentStreamId, firstItem]); diff --git a/src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx b/src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx index dc7cbb6ef0..806d5413ff 100644 --- a/src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx +++ b/src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx @@ -10,7 +10,7 @@ import React, { useRef, useState, } from "react"; -import { useDispatch, useSelector } from "react-redux"; +import { useSelector } from "react-redux"; import { useHistory } from "react-router-dom"; import { useWindowSize } from "react-use"; import classNames from "classnames"; @@ -66,7 +66,6 @@ import { getParamsFromOneOfRoutes, getUserName, } from "@/shared/utils"; -import { commonActions, selectRecentStreamId } from "@/store/states"; import { MIN_CHAT_WIDTH } from "../../constants"; import { DesktopChat, @@ -169,7 +168,6 @@ const FeedLayout: ForwardRefRenderFunction = ( outerStyles, settings, } = props; - const dispatch = useDispatch(); const { getCommonPagePath } = useRoutesContext(); const refsByItemId = useRef>({}); const { width: windowWidth } = useWindowSize(); @@ -177,7 +175,6 @@ const FeedLayout: ForwardRefRenderFunction = ( const queryParams = useQueryParams(); const isTabletView = useIsTabletView(); const user = useSelector(selectUser()); - const recentStreamId = useSelector(selectRecentStreamId); const userId = user?.uid; const [chatItem, setChatItem] = useState(); const [isShowFeedItemDetailsModal, setIsShowFeedItemDetailsModal] = @@ -270,19 +267,9 @@ const FeedLayout: ForwardRefRenderFunction = ( ) { return; } - if (recentStreamId) { - const foundItem = allFeedItems.find( - (item) => - checkIsFeedItemFollowLayoutItem(item) && - item.feedItem.data.id === recentStreamId, - ); - return foundItem?.itemId; - } - if (sharedFeedItemId) { return sharedFeedItemId; } - if (chatItem?.feedItemId) { return; } @@ -300,7 +287,6 @@ const FeedLayout: ForwardRefRenderFunction = ( chatChannelItemForProfile?.itemId, allFeedItems, chatItem?.feedItemId, - recentStreamId, sharedFeedItemId, userForProfile.userForProfileData, shouldAllowChatAutoOpen, @@ -633,18 +619,6 @@ const FeedLayout: ForwardRefRenderFunction = ( } }, [isTabletView, shouldAutoExpandItem, activeFeedItemId]); - useEffect(() => { - if (!recentStreamId || !selectedFeedItem) { - return; - } - if ( - !checkIsFeedItemFollowLayoutItem(selectedFeedItem) || - recentStreamId === selectedFeedItem?.feedItem.data.id - ) { - dispatch(commonActions.setRecentStreamId("")); - } - }, [recentStreamId, selectedFeedItem]); - useImperativeHandle( ref, () => ({ From 872ce688837aae8c3ffa2da08706f40de9ab5c71 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 12 Sep 2023 09:50:15 +0300 Subject: [PATCH 2/2] mark circleVisibility as nullable in ChatItem --- src/pages/common/components/ChatComponent/context.ts | 2 +- .../components/FeedTab/utils/checkHasAccessToChat.ts | 8 ++++---- src/pages/commonFeed/CommonFeed.tsx | 1 - src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx | 5 +---- .../components/DesktopProfile/DesktopProfile.tsx | 1 - .../FeedLayout/components/MobileProfile/MobileProfile.tsx | 1 - src/pages/inbox/BaseInbox.tsx | 1 - .../inbox/components/ChatChannelItem/ChatChannelItem.tsx | 1 - 8 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/pages/common/components/ChatComponent/context.ts b/src/pages/common/components/ChatComponent/context.ts index 518c6ba7b4..2db6aeda1d 100644 --- a/src/pages/common/components/ChatComponent/context.ts +++ b/src/pages/common/components/ChatComponent/context.ts @@ -11,7 +11,7 @@ export interface ChatItem { proposal?: Proposal; discussion?: Discussion; chatChannel?: ChatChannel; - circleVisibility: string[]; + circleVisibility?: string[]; lastSeenItem?: CommonFeedObjectUserUnique["lastSeen"]; lastSeenAt?: CommonFeedObjectUserUnique["lastSeenAt"]; seenOnce?: boolean; diff --git a/src/pages/common/components/CommonTabPanels/components/FeedTab/utils/checkHasAccessToChat.ts b/src/pages/common/components/CommonTabPanels/components/FeedTab/utils/checkHasAccessToChat.ts index 8394a90da2..f0fb06e2e1 100644 --- a/src/pages/common/components/CommonTabPanels/components/FeedTab/utils/checkHasAccessToChat.ts +++ b/src/pages/common/components/CommonTabPanels/components/FeedTab/utils/checkHasAccessToChat.ts @@ -8,10 +8,10 @@ export const checkHasAccessToChat = ( return false; } + const { circleVisibility = [] } = chatItem; + return ( - !chatItem.circleVisibility.length || - chatItem.circleVisibility.some((circleId) => - userCircleIds.includes(circleId), - ) + !circleVisibility.length || + circleVisibility.some((circleId) => userCircleIds.includes(circleId)) ); }; diff --git a/src/pages/commonFeed/CommonFeed.tsx b/src/pages/commonFeed/CommonFeed.tsx index 0b84d4038d..d19b4729b7 100644 --- a/src/pages/commonFeed/CommonFeed.tsx +++ b/src/pages/commonFeed/CommonFeed.tsx @@ -255,7 +255,6 @@ const CommonFeedComponent: FC = (props) => { ) { feedLayoutRef?.setActiveItem({ feedItemId: firstItem.feedItem.id, - circleVisibility: [], }); dispatch(commonActions.setRecentStreamId("")); } diff --git a/src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx b/src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx index 806d5413ff..c167b02997 100644 --- a/src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx +++ b/src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx @@ -492,10 +492,7 @@ const FeedLayout: ForwardRefRenderFunction = ( return; } - setActiveChatItem({ - feedItemId, - circleVisibility: [], - }); + setActiveChatItem({ feedItemId }); const itemExists = allFeedItems.some((item) => item.itemId === feedItemId); diff --git a/src/pages/commonFeed/components/FeedLayout/components/DesktopProfile/DesktopProfile.tsx b/src/pages/commonFeed/components/FeedLayout/components/DesktopProfile/DesktopProfile.tsx index e3fa9d7760..664bc238ab 100644 --- a/src/pages/commonFeed/components/FeedLayout/components/DesktopProfile/DesktopProfile.tsx +++ b/src/pages/commonFeed/components/FeedLayout/components/DesktopProfile/DesktopProfile.tsx @@ -46,7 +46,6 @@ const DesktopProfile: FC = (props) => { chatChannel: chatChannel, discussion: ChatChannelToDiscussionConverter.toTargetEntity(chatChannel), - circleVisibility: [], }} governanceCircles={governanceCircles} commonId={""} diff --git a/src/pages/commonFeed/components/FeedLayout/components/MobileProfile/MobileProfile.tsx b/src/pages/commonFeed/components/FeedLayout/components/MobileProfile/MobileProfile.tsx index b90b2cc010..b5f8871ebb 100644 --- a/src/pages/commonFeed/components/FeedLayout/components/MobileProfile/MobileProfile.tsx +++ b/src/pages/commonFeed/components/FeedLayout/components/MobileProfile/MobileProfile.tsx @@ -37,7 +37,6 @@ const MobileProfile: FC = (props) => { chatChannel: chatChannel, discussion: ChatChannelToDiscussionConverter.toTargetEntity(chatChannel), - circleVisibility: [], }} commonId={""} commonName={""} diff --git a/src/pages/inbox/BaseInbox.tsx b/src/pages/inbox/BaseInbox.tsx index 93221eaa16..a0f97b8667 100644 --- a/src/pages/inbox/BaseInbox.tsx +++ b/src/pages/inbox/BaseInbox.tsx @@ -199,7 +199,6 @@ const InboxPage: FC = (props) => { discussion: ChatChannelToDiscussionConverter.toTargetEntity( chatChannelItem.chatChannel, ), - circleVisibility: [], }); }, [nextChatChannelItemId, feedLayoutRef]); diff --git a/src/pages/inbox/components/ChatChannelItem/ChatChannelItem.tsx b/src/pages/inbox/components/ChatChannelItem/ChatChannelItem.tsx index 3ed0393b8f..8df21cc437 100644 --- a/src/pages/inbox/components/ChatChannelItem/ChatChannelItem.tsx +++ b/src/pages/inbox/components/ChatChannelItem/ChatChannelItem.tsx @@ -47,7 +47,6 @@ export const ChatChannelItem: FC = (props) => { feedItemId: chatChannel.id, discussion: ChatChannelToDiscussionConverter.toTargetEntity(chatChannel), chatChannel, - circleVisibility: [], lastSeenItem: chatChannelUserStatus?.lastSeenChatMessageId ? { type: LastSeenEntity.DiscussionMessage,