[Perf] Right Column: Optimize global selectors

This commit is contained in:
Alexander Zinchuk 2023-07-20 15:58:16 +02:00
parent d92f581999
commit 5ea7919e92
4 changed files with 13 additions and 50 deletions

View File

@ -27,7 +27,7 @@ export function selectCurrentManagement<T extends GlobalState>(
}
const currentManagement = selectTabState(global, tabId).management.byChatId[chatId];
if (!currentManagement || !currentManagement.isActive) {
if (!currentManagement?.isActive) {
return undefined;
}

View File

@ -846,30 +846,6 @@ export function selectFirstUnreadId<T extends GlobalState>(
return undefined;
}
export function selectIsPollResultsOpen<T extends GlobalState>(
global: T,
...[tabId = getCurrentTabId()]: TabArgs<T>
) {
const { pollResults } = selectTabState(global, tabId);
return Boolean(pollResults.messageId);
}
export function selectIsCreateTopicPanelOpen<T extends GlobalState>(
global: T,
...[tabId = getCurrentTabId()]: TabArgs<T>
) {
const { createTopicPanel } = selectTabState(global, tabId);
return Boolean(createTopicPanel);
}
export function selectIsEditTopicPanelOpen<T extends GlobalState>(
global: T,
...[tabId = getCurrentTabId()]: TabArgs<T>
) {
const { editTopicPanel } = selectTabState(global, tabId);
return Boolean(editTopicPanel);
}
export function selectIsForwardModalOpen<T extends GlobalState>(
global: T,
...[tabId = getCurrentTabId()]: TabArgs<T>

View File

@ -24,14 +24,3 @@ export function selectIsStatisticsShown<T extends GlobalState>(
return currentChatId ? selectChatFullInfo(global, currentChatId)?.canViewStatistics : undefined;
}
export function selectIsMessageStatisticsShown<T extends GlobalState>(
global: T,
...[tabId = getCurrentTabId()]: TabArgs<T>
) {
if (!selectTabState(global, tabId).isStatisticsShown) {
return false;
}
return Boolean(selectTabState(global, tabId).statistics.currentMessageId);
}

View File

@ -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<T extends GlobalState>(
isMobile?: boolean,
...[tabId = getCurrentTabId()]: TabArgs<T>
) {
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;
}