Skip to content

Commit

Permalink
CW-some-stream-disappear Optimized FeedItem component. FIxed conditio…
Browse files Browse the repository at this point in the history
…n in FeedLayout
  • Loading branch information
MeyerPV committed Aug 1, 2024
1 parent e5cfcff commit a6577d8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 41 deletions.
114 changes: 76 additions & 38 deletions src/pages/common/components/FeedItem/FeedItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import React, {
useMemo,
} from "react";
import { useFeedItemFollow } from "@/shared/hooks/useCases";
import {
FeedLayoutItemChangeData,
SpaceListVisibility,
} from "@/shared/interfaces";
import { FeedLayoutItemChangeData } from "@/shared/interfaces";
import {
Circles,
CirclesPermissions,
Expand All @@ -20,7 +17,7 @@ import {
CommonNotion,
DirectParent,
} from "@/shared/models";
import { checkIsItemVisibleForUser, InternalLinkData } from "@/shared/utils";
import { checkIsItemVisibleForUser } from "@/shared/utils";
import { useFeedItemSubscription } from "../../hooks";
import { DiscussionFeedCard } from "../DiscussionFeedCard";
import { ProposalFeedCard } from "../ProposalFeedCard";
Expand Down Expand Up @@ -113,14 +110,20 @@ const FeedItem = forwardRef<FeedItemRef, FeedItemProps>((props, ref) => {
const getNonAllowedItems =
outerGetNonAllowedItems || contextGetNonAllowedItems;

const handleUserClick = useMemo(
() => onUserSelect && ((userId: string) => onUserSelect(userId, commonId)),
const handleUserClick = useCallback(
(userId: string) => {
if (onUserSelect) {
onUserSelect(userId, commonId);
}
},
[onUserSelect, commonId],
);

const handleActiveItemDataChange = useCallback(
(data: FeedLayoutItemChangeData) => {
onActiveItemDataChange?.(data, commonId);
if (onActiveItemDataChange) {
onActiveItemDataChange(data, commonId);
}
},
[onActiveItemDataChange, commonId],
);
Expand All @@ -130,11 +133,15 @@ const FeedItem = forwardRef<FeedItemRef, FeedItemProps>((props, ref) => {
feedItemFollow.isUserFeedItemFollowDataFetched &&
!feedItemFollow.userFeedItemFollowData
) {
onFeedItemUnfollowed?.(item.id);
if (onFeedItemUnfollowed) {
onFeedItemUnfollowed(item.id);
}
}
}, [
feedItemFollow.isUserFeedItemFollowDataFetched,
feedItemFollow.userFeedItemFollowData,
item.id,
onFeedItemUnfollowed,
]);

if (
Expand All @@ -150,35 +157,66 @@ const FeedItem = forwardRef<FeedItemRef, FeedItemProps>((props, ref) => {
return null;
}

const generalProps = {
ref,
item,
commonId,
commonName,
commonImage,
commonNotion,
pinnedFeedItems,
isActive,
isExpanded,
isProject,
isPinned,
governanceCircles,
isPreviewMode,
getLastMessage,
commonMember,
getNonAllowedItems,
isMobileVersion,
onActiveItemDataChange: handleActiveItemDataChange,
directParent,
rootCommonId,
feedItemFollow,
onUserSelect,
shouldPreLoadMessages,
withoutMenu,
onUserClick: handleUserClick,
onFeedItemClick,
onInternalLinkClick,
};
const generalProps = useMemo(
() => ({
ref,
item,
commonId,
commonName,
commonImage,
commonNotion,
pinnedFeedItems,
isActive,
isExpanded,
isProject,
isPinned,
governanceCircles,
isPreviewMode,
getLastMessage,
commonMember,
getNonAllowedItems,
isMobileVersion,
onActiveItemDataChange: handleActiveItemDataChange,
directParent,
rootCommonId,
feedItemFollow,
onUserSelect,
shouldPreLoadMessages,
withoutMenu,
onUserClick: handleUserClick,
onFeedItemClick,
onInternalLinkClick,
}),
[
ref,
item,
commonId,
commonName,
commonImage,
commonNotion,
pinnedFeedItems,
isActive,
isExpanded,
isProject,
isPinned,
governanceCircles,
isPreviewMode,
getLastMessage,
commonMember,
getNonAllowedItems,
isMobileVersion,
handleActiveItemDataChange,
directParent,
rootCommonId,
feedItemFollow,
onUserSelect,
shouldPreLoadMessages,
withoutMenu,
handleUserClick,
onFeedItemClick,
onInternalLinkClick,
],
);

if (item.data.type === CommonFeedType.Discussion) {
return <DiscussionFeedCard {...generalProps} />;
Expand Down
7 changes: 4 additions & 3 deletions src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, {
CSSProperties,
forwardRef,
ForwardRefRenderFunction,
ReactNode,
useCallback,
useEffect,
useImperativeHandle,
useMemo,
useRef,
useState,
ReactNode,
ForwardRefRenderFunction,
} from "react";
import { useSelector } from "react-redux";
import { useHistory } from "react-router-dom";
Expand Down Expand Up @@ -221,8 +221,9 @@ const FeedLayout: ForwardRefRenderFunction<FeedLayoutRef, FeedLayoutProps> = (
fetchedCommonMember;
const userForProfile = useUserForProfile();
const governance = chatItem?.nestedItemData
? fetchedGovernance
? fetchedGovernance || outerGovernance
: outerGovernance || fetchedGovernance;

const [splitPaneRef, setSplitPaneRef] = useState<Element | null>(null);
const maxContentSize =
settings?.getSplitViewMaxSize?.(windowWidth) ??
Expand Down

0 comments on commit a6577d8

Please sign in to comment.