From 5ea7919e92bec71084bd43a50445c3a1a1b85ec1 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Thu, 20 Jul 2023 15:58:16 +0200 Subject: [PATCH] [Perf] Right Column: Optimize global selectors --- src/global/selectors/management.ts | 2 +- src/global/selectors/messages.ts | 24 ------------------------ src/global/selectors/statistics.ts | 11 ----------- src/global/selectors/ui.ts | 26 ++++++++++++-------------- 4 files changed, 13 insertions(+), 50 deletions(-) diff --git a/src/global/selectors/management.ts b/src/global/selectors/management.ts index e2a7eb4c4..02acc540d 100644 --- a/src/global/selectors/management.ts +++ b/src/global/selectors/management.ts @@ -27,7 +27,7 @@ export function selectCurrentManagement( } const currentManagement = selectTabState(global, tabId).management.byChatId[chatId]; - if (!currentManagement || !currentManagement.isActive) { + if (!currentManagement?.isActive) { return undefined; } diff --git a/src/global/selectors/messages.ts b/src/global/selectors/messages.ts index 3f3f92b49..9676fea95 100644 --- a/src/global/selectors/messages.ts +++ b/src/global/selectors/messages.ts @@ -846,30 +846,6 @@ export function selectFirstUnreadId( return undefined; } -export function selectIsPollResultsOpen( - global: T, - ...[tabId = getCurrentTabId()]: TabArgs -) { - const { pollResults } = selectTabState(global, tabId); - return Boolean(pollResults.messageId); -} - -export function selectIsCreateTopicPanelOpen( - global: T, - ...[tabId = getCurrentTabId()]: TabArgs -) { - const { createTopicPanel } = selectTabState(global, tabId); - return Boolean(createTopicPanel); -} - -export function selectIsEditTopicPanelOpen( - global: T, - ...[tabId = getCurrentTabId()]: TabArgs -) { - const { editTopicPanel } = selectTabState(global, tabId); - return Boolean(editTopicPanel); -} - export function selectIsForwardModalOpen( global: T, ...[tabId = getCurrentTabId()]: TabArgs diff --git a/src/global/selectors/statistics.ts b/src/global/selectors/statistics.ts index afa9c72f3..cb84f432b 100644 --- a/src/global/selectors/statistics.ts +++ b/src/global/selectors/statistics.ts @@ -24,14 +24,3 @@ export function selectIsStatisticsShown( return currentChatId ? selectChatFullInfo(global, currentChatId)?.canViewStatistics : undefined; } - -export function selectIsMessageStatisticsShown( - global: T, - ...[tabId = getCurrentTabId()]: TabArgs -) { - if (!selectTabState(global, tabId).isStatisticsShown) { - return false; - } - - return Boolean(selectTabState(global, tabId).statistics.currentMessageId); -} diff --git a/src/global/selectors/ui.ts b/src/global/selectors/ui.ts index e765f4cd5..d8a3555c1 100644 --- a/src/global/selectors/ui.ts +++ b/src/global/selectors/ui.ts @@ -1,14 +1,10 @@ import type { GlobalState, TabArgs } from '../types'; import type { PerformanceTypeKey } from '../../types'; -import type { ApiMessage } from '../../api/types'; import { NewChatMembersProgress, RightColumnContent } from '../../types'; +import type { ApiMessage } from '../../api/types'; -import { - selectCurrentMessageList, selectIsCreateTopicPanelOpen, selectIsEditTopicPanelOpen, selectIsPollResultsOpen, -} from './messages'; import { selectCurrentTextSearch } from './localSearch'; -import { selectCurrentStickerSearch, selectCurrentGifSearch } from './symbols'; -import { selectIsStatisticsShown, selectIsMessageStatisticsShown } from './statistics'; +import { selectIsStatisticsShown } from './statistics'; import { selectCurrentManagement } from './management'; import { selectTabState } from './tabs'; import { getCurrentTabId } from '../../util/establishMultitabRole'; @@ -27,27 +23,29 @@ export function selectRightColumnContentKey( isMobile?: boolean, ...[tabId = getCurrentTabId()]: TabArgs ) { - return selectIsEditTopicPanelOpen(global, tabId) ? ( + const tabState = selectTabState(global, tabId); + + return tabState.editTopicPanel ? ( RightColumnContent.EditTopic - ) : selectIsCreateTopicPanelOpen(global, tabId) ? ( + ) : tabState.createTopicPanel ? ( RightColumnContent.CreateTopic - ) : selectIsPollResultsOpen(global, tabId) ? ( + ) : tabState.pollResults.messageId ? ( RightColumnContent.PollResults ) : !isMobile && selectCurrentTextSearch(global, tabId) ? ( RightColumnContent.Search ) : selectCurrentManagement(global, tabId) ? ( RightColumnContent.Management - ) : selectIsMessageStatisticsShown(global, tabId) ? ( + ) : tabState.isStatisticsShown && tabState.statistics.currentMessageId ? ( RightColumnContent.MessageStatistics ) : selectIsStatisticsShown(global, tabId) ? ( RightColumnContent.Statistics - ) : selectCurrentStickerSearch(global, tabId).query !== undefined ? ( + ) : tabState.stickerSearch.query !== undefined ? ( RightColumnContent.StickerSearch - ) : selectCurrentGifSearch(global, tabId).query !== undefined ? ( + ) : tabState.gifSearch.query !== undefined ? ( RightColumnContent.GifSearch - ) : selectTabState(global, tabId).newChatMembersProgress !== NewChatMembersProgress.Closed ? ( + ) : tabState.newChatMembersProgress !== NewChatMembersProgress.Closed ? ( RightColumnContent.AddingMembers - ) : selectTabState(global, tabId).isChatInfoShown && selectCurrentMessageList(global, tabId) ? ( + ) : tabState.isChatInfoShown && tabState.messageLists.length ? ( RightColumnContent.ChatInfo ) : undefined; }