From 521b7e65059be0c3943d581996800da9c5d3ec3a Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 14 Dec 2021 22:40:52 +0400 Subject: [PATCH] [Perf] Forward Picker: Avoid redundant calculations --- src/components/main/ForwardPicker.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/main/ForwardPicker.tsx b/src/components/main/ForwardPicker.tsx index a8fa3d752..b4c293440 100644 --- a/src/components/main/ForwardPicker.tsx +++ b/src/components/main/ForwardPicker.tsx @@ -10,6 +10,7 @@ import { getCanPostInChat, getChatTitle, sortChatIds } from '../../modules/helpe import searchWords from '../../util/searchWords'; import { pick, unique } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; +import useCurrentOrPrev from '../../hooks/useCurrentOrPrev'; import ChatOrUserPicker from '../common/ChatOrUserPicker'; @@ -45,6 +46,10 @@ const ForwardPicker: FC = ({ const filterRef = useRef(null); const chatIds = useMemo(() => { + if (!isOpen) { + return undefined; + } + const listIds = [...(activeListIds || []), ...(archivedListIds || [])]; let priorityIds = pinnedIds || []; @@ -68,17 +73,19 @@ const ForwardPicker: FC = ({ return searchWords(getChatTitle(lang, chatsById[id], undefined, id === currentUserId), filter); }), chatsById, undefined, priorityIds); - }, [activeListIds, archivedListIds, chatsById, currentUserId, filter, lang, pinnedIds]); + }, [activeListIds, archivedListIds, chatsById, currentUserId, filter, isOpen, lang, pinnedIds]); const handleSelectUser = useCallback((userId: string) => { setForwardChatId({ id: userId }); }, [setForwardChatId]); + const renderingChatIds = useCurrentOrPrev(chatIds)!; + return (