Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e0e046c
CW-mobile-performance Added memoization for ProjectFeedItem
MeyerPV Aug 8, 2024
795445b
CW-mobile-performance Added memoization for FeedCard
MeyerPV Aug 8, 2024
66c84cf
CW-mobile-performance Added useMemo for lastMessages and menuItems
MeyerPV Aug 8, 2024
5c9a860
CW-mobile-performance Added memo for CommonFeed
MeyerPV Aug 8, 2024
c6cbf9d
CW-mobile-performance Fix type issue
MeyerPV Aug 8, 2024
5e0d1c5
CW-mobile-performance Optimize FeedLayout
MeyerPV Aug 8, 2024
c38e291
CW-mobile-performance Added memo for TreeItemTrigger and useMenuItems
MeyerPV Aug 8, 2024
a5d19af
CW-mobile-performance Fix TreeItemTrigger component
MeyerPV Aug 9, 2024
fb6414d
CW-mobile-performance Optimize components
MeyerPV Aug 9, 2024
51142e5
CW-mobile-perfromance Remove unnecessary libraries
MeyerPV Aug 12, 2024
d7792d4
CW-mobile-performance Fix jest config
MeyerPV Aug 12, 2024
d9aa6e8
CW-mobile-performance Fix words func call
MeyerPV Aug 12, 2024
9fecc76
CW-mobile-performance Fix eslint
MeyerPV Aug 12, 2024
8b4d4af
CW-mobile-performance Added lodash-es types
MeyerPV Aug 12, 2024
dbcf4b6
Revert "CW-mobile-performance Added lodash-es types"
MeyerPV Aug 12, 2024
218e362
Revert "CW-mobile-performance Fix eslint"
MeyerPV Aug 12, 2024
5813f1b
Revert "CW-mobile-performance Fix words func call"
MeyerPV Aug 12, 2024
9d245d0
Revert "CW-mobile-performance Fix jest config"
MeyerPV Aug 12, 2024
2be85e8
Revert "CW-mobile-perfromance Remove unnecessary libraries"
MeyerPV Aug 12, 2024
7afe4cd
CW-mobile-performance fixed new stream issue
MeyerPV Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/pages/common/components/ChatComponent/ChatComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,15 @@ export default function ChatComponent({
chatChannelId: chatChannel?.id || "",
participants: chatChannel?.participants,
});
const users = chatChannel ? chatUsers : discussionUsers;
const discussionMessages = chatChannel
? chatMessagesData.data
: discussionMessagesData.data || [];
const users = useMemo(
() => (chatChannel ? chatUsers : discussionUsers),
[chatUsers, discussionUsers, chatChannel],
);
const discussionMessages = useMemo(
() =>
chatChannel ? chatMessagesData.data : discussionMessagesData.data || [],
[chatChannel, chatMessagesData.data, discussionMessagesData.data],
);
const isFetchedDiscussionMessages =
discussionMessagesData.fetched || chatMessagesData.fetched;
const areInitialMessagesLoading = isChatChannel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,30 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
}
}, [item.data.lastMessage?.content]);

const lastMessage = useMemo(() => {
return getLastMessage({
commonFeedType: item.data.type,
lastMessage: item.data.lastMessage,
discussion,
currentUserId: userId,
feedItemCreatorName: getUserName(discussionCreator),
commonName,
isProject,
hasFiles: item.data.hasFiles,
hasImages: item.data.hasImages,
});
}, [
item.data.type,
item.data.lastMessage,
discussion,
userId,
discussionCreator,
commonName,
isProject,
item.data.hasFiles,
item.data.hasImages,
]);

return (
<>
<FeedCard
Expand All @@ -361,17 +385,7 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
isExpanded={isExpanded}
onClick={handleOpenChat}
title={cardTitle}
lastMessage={getLastMessage({
commonFeedType: item.data.type,
lastMessage: item.data.lastMessage,
discussion,
currentUserId: userId,
feedItemCreatorName: getUserName(discussionCreator),
commonName,
isProject,
hasFiles: item.data.hasFiles,
hasImages: item.data.hasImages,
})}
lastMessage={lastMessage}
isPreviewMode={isPreviewMode}
isPinned={isPinned}
commonName={commonName}
Expand Down
141 changes: 91 additions & 50 deletions src/pages/common/components/FeedCard/FeedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import React, {
forwardRef,
useImperativeHandle,
PropsWithChildren,
useCallback,
useMemo,
} from "react";
import { useCollapse } from "react-collapsed";
import classNames from "classnames";
Expand Down Expand Up @@ -106,11 +108,11 @@ export const FeedCard = forwardRef<FeedCardRef, FeedCardProps>((props, ref) => {
});
const containerRef = useRef<HTMLDivElement>(null);

const toggleExpanding = () => {
const toggleExpanding = useCallback(() => {
if (setExpandedFeedItemId) {
setExpandedFeedItemId(isExpanded ? null : feedItemId);
}
};
}, [setExpandedFeedItemId, isExpanded, feedItemId]);

const scrollToTargetTop = (
headerOffset: number,
Expand Down Expand Up @@ -140,7 +142,7 @@ export const FeedCard = forwardRef<FeedCardRef, FeedCardProps>((props, ref) => {
}
};

const scrollToTargetAdjusted = () => {
const scrollToTargetAdjusted = useCallback(() => {
if (scrollTimeoutRef.current) {
clearTimeout(scrollTimeoutRef.current);
}
Expand Down Expand Up @@ -192,7 +194,7 @@ export const FeedCard = forwardRef<FeedCardRef, FeedCardProps>((props, ref) => {
});
}
}, COLLAPSE_DURATION + EXTRA_WAITING_TIME_FOR_TIMEOUT);
};
}, [isTabletView]);

useEffect(() => {
if (isExpanded && containerRef?.current) {
Expand All @@ -203,63 +205,102 @@ export const FeedCard = forwardRef<FeedCardRef, FeedCardProps>((props, ref) => {
clearTimeout(scrollTimeoutRef.current);
scrollTimeoutRef.current = null;
}
}, [isExpanded]);
}, [isExpanded, scrollToTargetAdjusted]);

const handleClick = () => {
const handleClick = useCallback(() => {
onClick?.();

if (!isTabletView && isActive) {
toggleExpanding();
}
};
}, [onClick, isTabletView, isActive, toggleExpanding]);

const handleExpand: MouseEventHandler = (event) => {
event.stopPropagation();
toggleExpanding();
};
const handleExpand: MouseEventHandler = useCallback(
(event) => {
event.stopPropagation();
toggleExpanding();
},
[toggleExpanding],
);

useImperativeHandle(
ref,
() => ({
itemId: feedItemId,
scrollToItem: scrollToTargetAdjusted,
}),
[feedItemId, scrollToTargetAdjusted],
);

useImperativeHandle(ref, () => ({
itemId: feedItemId,
scrollToItem: scrollToTargetAdjusted,
}));
const feedItemBaseContent = useMemo(() => {
return renderFeedItemBaseContent?.({
lastActivity,
unreadMessages,
isMobileView: isTabletView,
isActive,
isExpanded,
canBeExpanded,
onClick: handleClick,
onExpand: handleExpand,
title,
lastMessage: !isLoading ? lastMessage : undefined,
menuItems,
commonName,
commonId,
image,
imageAlt,
isProject,
isPinned,
isFollowing,
type,
seenOnce,
seen,
ownerId,
discussionPredefinedType,
hasFiles,
hasImages,
hasUnseenMention,
notion,
originalCommonIdForLinking,
linkedCommonIds,
});
}, [
lastActivity,
unreadMessages,
isTabletView,
isActive,
isExpanded,
canBeExpanded,
handleClick,
handleExpand,
title,
lastMessage,
isLoading,
menuItems,
commonName,
commonId,
image,
imageAlt,
isProject,
isPinned,
isFollowing,
type,
seenOnce,
seen,
ownerId,
discussionPredefinedType,
hasFiles,
hasImages,
hasUnseenMention,
notion,
originalCommonIdForLinking,
linkedCommonIds,
renderFeedItemBaseContent,
]);

return (
<div ref={containerRef}>
{!isPreviewMode && (
<div {...getToggleProps()}>
{renderFeedItemBaseContent?.({
lastActivity,
unreadMessages,
isMobileView: isTabletView,
isActive,
isExpanded,
canBeExpanded,
onClick: handleClick,
onExpand: handleExpand,
title,
lastMessage: !isLoading ? lastMessage : undefined,
menuItems,
commonName,
commonId,
image,
imageAlt,
isProject,
isPinned,
isFollowing,
type,
seenOnce,
seen,
ownerId,
discussionPredefinedType,
hasFiles,
hasImages,
hasUnseenMention,
notion,
originalCommonIdForLinking,
linkedCommonIds,
})}
</div>
)}
{!isPreviewMode && <div {...getToggleProps()}>{feedItemBaseContent}</div>}
<div {...getCollapseProps()}>
<CommonCard
className={classNames(
Expand Down
Loading