[Refactoring] Chat List: Fix redundant DOM operations

This commit is contained in:
Alexander Zinchuk 2022-05-30 15:40:34 +04:00
parent 706839953a
commit b2d4f78c65
2 changed files with 21 additions and 13 deletions

View File

@ -13,7 +13,7 @@ import {
} from '../../../config';
import { IS_MAC_OS, IS_PWA } from '../../../util/environment';
import { mapValues } from '../../../util/iteratees';
import { getPinnedChatsCount } from '../../../util/folderManager';
import { getPinnedChatsCount, getOrderKey } from '../../../util/folderManager';
import usePrevious from '../../../hooks/usePrevious';
import useInfiniteScroll from '../../../hooks/useInfiniteScroll';
import { useFolderManagerForOrderedIds } from '../../../hooks/useFolderManager';
@ -117,18 +117,22 @@ const ChatList: FC<OwnProps> = ({
const viewportOffset = orderedIds!.indexOf(viewportIds![0]);
const pinnedCount = getPinnedChatsCount(resolvedFolderId) || 0;
return viewportIds!.map((id, i) => (
<Chat
key={id}
teactOrderKey={i}
chatId={id}
isPinned={viewportOffset + i < pinnedCount}
folderId={folderId}
animationType={getAnimationType(id)}
orderDiff={orderDiffById[id]}
style={`top: ${(viewportOffset + i) * CHAT_HEIGHT_PX}px;`}
/>
));
return viewportIds!.map((id, i) => {
const isPinned = viewportOffset + i < pinnedCount;
return (
<Chat
key={id}
teactOrderKey={isPinned ? i : getOrderKey(id)}
chatId={id}
isPinned={isPinned}
folderId={folderId}
animationType={getAnimationType(id)}
orderDiff={orderDiffById[id]}
style={`top: ${(viewportOffset + i) * CHAT_HEIGHT_PX}px;`}
/>
);
});
}
return (

View File

@ -135,6 +135,10 @@ export function getAllNotificationsCount() {
return getUnreadCounters()[ALL_FOLDER_ID]?.notificationsCount || 0;
}
export function getOrderKey(chatId: string) {
return prepared.chatSummariesById.get(chatId)!.order;
}
/* Callback managers */
export function addOrderedIdsCallback(folderId: number, callback: (orderedIds: string[]) => void) {