Skip to content

Commit

Permalink
Merge pull request #2063 from daostack/bugfix/CW-1990-select-created-…
Browse files Browse the repository at this point in the history
…item

when create a new discussion/proposal- the chat remains open with previews channel details #1990
  • Loading branch information
andreymikhadyuk authored Sep 12, 2023
2 parents ace6922 + 872ce68 commit 6e6f57e
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/pages/common/components/ChatComponent/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
};
6 changes: 4 additions & 2 deletions src/pages/commonFeed/CommonFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ const CommonFeedComponent: FC<CommonFeedProps> = (props) => {
checkIsFeedItemFollowLayoutItem(firstItem) &&
recentStreamId === firstItem.feedItem.data.id
) {
feedLayoutRef?.setShouldAllowChatAutoOpen(true);
feedLayoutRef?.setExpandedFeedItemId(firstItem.feedItem.id);
feedLayoutRef?.setActiveItem({
feedItemId: firstItem.feedItem.id,
});
dispatch(commonActions.setRecentStreamId(""));
}
}, [feedLayoutRef, recentStreamId, firstItem]);

Expand Down
33 changes: 2 additions & 31 deletions src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -66,7 +66,6 @@ import {
getParamsFromOneOfRoutes,
getUserName,
} from "@/shared/utils";
import { commonActions, selectRecentStreamId } from "@/store/states";
import { MIN_CHAT_WIDTH } from "../../constants";
import {
DesktopChat,
Expand Down Expand Up @@ -169,15 +168,13 @@ const FeedLayout: ForwardRefRenderFunction<FeedLayoutRef, FeedLayoutProps> = (
outerStyles,
settings,
} = props;
const dispatch = useDispatch();
const { getCommonPagePath } = useRoutesContext();
const refsByItemId = useRef<Record<string, FeedItemRef | null>>({});
const { width: windowWidth } = useWindowSize();
const history = useHistory();
const queryParams = useQueryParams();
const isTabletView = useIsTabletView();
const user = useSelector(selectUser());
const recentStreamId = useSelector(selectRecentStreamId);
const userId = user?.uid;
const [chatItem, setChatItem] = useState<ChatItem | null>();
const [isShowFeedItemDetailsModal, setIsShowFeedItemDetailsModal] =
Expand Down Expand Up @@ -270,19 +267,9 @@ const FeedLayout: ForwardRefRenderFunction<FeedLayoutRef, FeedLayoutProps> = (
) {
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;
}
Expand All @@ -300,7 +287,6 @@ const FeedLayout: ForwardRefRenderFunction<FeedLayoutRef, FeedLayoutProps> = (
chatChannelItemForProfile?.itemId,
allFeedItems,
chatItem?.feedItemId,
recentStreamId,
sharedFeedItemId,
userForProfile.userForProfileData,
shouldAllowChatAutoOpen,
Expand Down Expand Up @@ -506,10 +492,7 @@ const FeedLayout: ForwardRefRenderFunction<FeedLayoutRef, FeedLayoutProps> = (
return;
}

setActiveChatItem({
feedItemId,
circleVisibility: [],
});
setActiveChatItem({ feedItemId });

const itemExists = allFeedItems.some((item) => item.itemId === feedItemId);

Expand Down Expand Up @@ -633,18 +616,6 @@ const FeedLayout: ForwardRefRenderFunction<FeedLayoutRef, FeedLayoutProps> = (
}
}, [isTabletView, shouldAutoExpandItem, activeFeedItemId]);

useEffect(() => {
if (!recentStreamId || !selectedFeedItem) {
return;
}
if (
!checkIsFeedItemFollowLayoutItem(selectedFeedItem) ||
recentStreamId === selectedFeedItem?.feedItem.data.id
) {
dispatch(commonActions.setRecentStreamId(""));
}
}, [recentStreamId, selectedFeedItem]);

useImperativeHandle(
ref,
() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const DesktopProfile: FC<DesktopProfileProps> = (props) => {
chatChannel: chatChannel,
discussion:
ChatChannelToDiscussionConverter.toTargetEntity(chatChannel),
circleVisibility: [],
}}
governanceCircles={governanceCircles}
commonId={""}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const MobileProfile: FC<MobileProfileProps> = (props) => {
chatChannel: chatChannel,
discussion:
ChatChannelToDiscussionConverter.toTargetEntity(chatChannel),
circleVisibility: [],
}}
commonId={""}
commonName={""}
Expand Down
1 change: 0 additions & 1 deletion src/pages/inbox/BaseInbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ const InboxPage: FC<InboxPageProps> = (props) => {
discussion: ChatChannelToDiscussionConverter.toTargetEntity(
chatChannelItem.chatChannel,
),
circleVisibility: [],
});
}, [nextChatChannelItemId, feedLayoutRef]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const ChatChannelItem: FC<ChatChannelFeedLayoutItemProps> = (props) => {
feedItemId: chatChannel.id,
discussion: ChatChannelToDiscussionConverter.toTargetEntity(chatChannel),
chatChannel,
circleVisibility: [],
lastSeenItem: chatChannelUserStatus?.lastSeenChatMessageId
? {
type: LastSeenEntity.DiscussionMessage,
Expand Down

0 comments on commit 6e6f57e

Please sign in to comment.