From 3ef713662117acae6f382b2d95f840ff03aba373 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 31 Dec 2021 18:17:27 +0100 Subject: [PATCH] [Perf] TeactN: Get rid of redundant iterations for global actions --- src/App.tsx | 10 +-- src/components/auth/Auth.tsx | 14 ++-- src/components/auth/AuthCode.tsx | 23 ++---- src/components/auth/AuthPassword.tsx | 12 +-- src/components/auth/AuthPhoneNumber.tsx | 36 +++----- src/components/auth/AuthQrCode.tsx | 28 +++---- src/components/auth/AuthRegister.tsx | 12 +-- src/components/calls/ActiveCallHeader.tsx | 14 +--- src/components/calls/CallFallbackConfirm.tsx | 20 ++--- src/components/calls/group/GroupCall.tsx | 34 +++----- .../calls/group/GroupCallParticipantList.tsx | 20 ++--- .../calls/group/GroupCallParticipantMenu.tsx | 31 +++---- .../calls/group/GroupCallTopPane.tsx | 19 ++--- .../calls/group/MicrophoneButton.tsx | 23 ++---- src/components/common/ChatExtra.tsx | 37 ++++----- src/components/common/ChatLink.tsx | 18 ++-- src/components/common/DeleteChatModal.tsx | 25 +++--- src/components/common/DeleteMessageModal.tsx | 19 ++--- src/components/common/GroupCallLink.tsx | 17 ++-- src/components/common/GroupChatInfo.tsx | 29 +++---- src/components/common/MessageLink.tsx | 17 ++-- src/components/common/PinMessageModal.tsx | 13 +-- src/components/common/PrivateChatInfo.tsx | 33 ++++---- src/components/common/ProfileInfo.tsx | 35 ++++---- src/components/common/ReportMessageModal.tsx | 22 ++--- src/components/common/SeenByModal.tsx | 17 ++-- src/components/common/StickerSetModal.tsx | 22 ++--- src/components/common/UiLoader.tsx | 27 +++--- src/components/common/UserLink.tsx | 17 ++-- src/components/left/ChatFolderModal.tsx | 12 +-- src/components/left/LeftColumn.tsx | 34 +++----- src/components/left/main/Chat.tsx | 19 ++--- src/components/left/main/ChatFolders.tsx | 24 +++--- src/components/left/main/ChatList.tsx | 32 +++----- src/components/left/main/ContactList.tsx | 16 ++-- src/components/left/main/LeftMainHeader.tsx | 29 ++----- src/components/left/newChat/NewChatStep1.tsx | 17 ++-- src/components/left/newChat/NewChatStep2.tsx | 18 ++-- src/components/left/search/AudioResults.tsx | 22 ++--- src/components/left/search/ChatMessage.tsx | 14 +--- .../left/search/ChatMessageResults.tsx | 12 +-- src/components/left/search/ChatResults.tsx | 23 ++---- src/components/left/search/FileResults.tsx | 19 ++--- src/components/left/search/LeftSearch.tsx | 16 ++-- src/components/left/search/LinkResults.tsx | 19 ++--- src/components/left/search/MediaResults.tsx | 19 ++--- src/components/left/search/RecentContacts.tsx | 25 ++---- .../left/settings/BlockUserModal.tsx | 21 ++--- .../left/settings/SettingsDataStorage.tsx | 15 +--- .../left/settings/SettingsEditProfile.tsx | 24 ++---- .../left/settings/SettingsGeneral.tsx | 44 +++++----- .../settings/SettingsGeneralBackground.tsx | 22 ++--- .../SettingsGeneralBackgroundColor.tsx | 11 +-- .../left/settings/SettingsHeader.tsx | 20 ++--- .../left/settings/SettingsLanguage.tsx | 18 ++-- src/components/left/settings/SettingsMain.tsx | 12 +-- .../left/settings/SettingsNotifications.tsx | 82 ++++++++++--------- .../left/settings/SettingsPrivacy.tsx | 27 +++--- .../SettingsPrivacyActiveSessions.tsx | 22 ++--- .../settings/SettingsPrivacyBlockedUsers.tsx | 12 +-- .../settings/SettingsPrivacyVisibility.tsx | 29 +++---- ...SettingsPrivacyVisibilityExceptionList.tsx | 17 ++-- .../folders/SettingsFoldersChatFilters.tsx | 12 +-- .../settings/folders/SettingsFoldersEdit.tsx | 19 ++--- .../settings/folders/SettingsFoldersMain.tsx | 19 ++--- .../left/settings/twoFa/SettingsTwoFa.tsx | 31 +++---- src/components/main/Dialogs.tsx | 8 +- src/components/main/DownloadManager.tsx | 13 ++- src/components/main/ForwardPicker.tsx | 19 ++--- src/components/main/HistoryCalendar.tsx | 16 ++-- src/components/main/Main.tsx | 40 ++++----- src/components/main/Notifications.tsx | 8 +- src/components/main/SafeLinkModal.tsx | 14 +--- src/components/mediaViewer/MediaViewer.tsx | 22 ++--- .../mediaViewer/MediaViewerActions.tsx | 19 ++--- src/components/mediaViewer/SenderInfo.tsx | 16 ++-- src/components/middle/AudioPlayer.tsx | 31 +++---- src/components/middle/ContactGreeting.tsx | 20 ++--- .../middle/DeleteSelectedMessageModal.tsx | 23 ++---- src/components/middle/HeaderActions.tsx | 27 +++--- src/components/middle/HeaderMenuContainer.tsx | 43 ++++------ src/components/middle/MessageList.tsx | 21 ++--- src/components/middle/MessageListContent.tsx | 5 +- .../middle/MessageSelectToolbar.tsx | 23 ++---- src/components/middle/MiddleColumn.tsx | 39 ++++----- src/components/middle/MiddleHeader.tsx | 41 ++++------ src/components/middle/MobileSearch.tsx | 31 +++---- src/components/middle/ScrollDownButton.tsx | 13 ++- .../middle/composer/BotCommandMenu.tsx | 17 ++-- .../middle/composer/BotCommandTooltip.tsx | 12 +-- .../middle/composer/BotKeyboardMenu.tsx | 15 ++-- src/components/middle/composer/Composer.tsx | 63 +++++--------- .../composer/ComposerEmbeddedMessage.tsx | 25 ++---- src/components/middle/composer/GifPicker.tsx | 12 +-- .../middle/composer/InlineBotTooltip.tsx | 22 ++--- .../middle/composer/MessageInput.tsx | 16 ++-- .../middle/composer/StickerPicker.tsx | 34 +++----- .../middle/composer/StickerTooltip.tsx | 12 +-- .../middle/composer/WebPagePreview.tsx | 19 ++--- .../middle/composer/hooks/useDraft.ts | 6 +- .../middle/composer/hooks/useEditing.ts | 5 +- src/components/middle/message/Album.tsx | 15 ++-- .../middle/message/CommentButton.tsx | 7 +- src/components/middle/message/Contact.tsx | 17 ++-- .../middle/message/ContextMenuContainer.tsx | 58 +++++-------- src/components/middle/message/MentionLink.tsx | 16 ++-- src/components/middle/message/Message.tsx | 29 +++---- src/components/middle/message/Poll.tsx | 13 +-- .../middle/message/hocs/withSelectControl.tsx | 25 ++---- src/components/payment/PaymentModal.tsx | 43 ++++------ src/components/right/AddChatMembers.tsx | 14 ++-- src/components/right/DeleteMemberModal.tsx | 12 +-- src/components/right/GifSearch.tsx | 18 ++-- src/components/right/PollAnswerResults.tsx | 18 ++-- src/components/right/Profile.tsx | 50 ++++------- src/components/right/RightColumn.tsx | 44 ++++------ src/components/right/RightHeader.tsx | 36 +++----- src/components/right/RightSearch.tsx | 17 ++-- src/components/right/StickerSearch.tsx | 13 +-- src/components/right/StickerSetResult.tsx | 13 ++- .../right/management/ManageChannel.tsx | 28 +++---- .../management/ManageChatAdministrators.tsx | 1 - .../management/ManageChatPrivacyType.tsx | 26 +++--- .../right/management/ManageDiscussion.tsx | 25 +++--- .../right/management/ManageGroup.tsx | 32 +++----- .../management/ManageGroupAdminRights.tsx | 12 +-- .../right/management/ManageGroupMembers.tsx | 14 +--- .../management/ManageGroupPermissions.tsx | 12 +-- .../management/ManageGroupRemovedUsers.tsx | 12 +-- .../management/ManageGroupUserPermissions.tsx | 12 +-- .../right/management/ManageUser.tsx | 26 +++--- .../right/management/RemoveGroupUserModal.tsx | 16 ++-- src/lib/teact/teactn.tsx | 18 +--- 133 files changed, 1116 insertions(+), 1797 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8cff1ea31..3236e73a1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,7 @@ import { FC, useEffect } from './lib/teact/teact'; -import React, { withGlobal } from './lib/teact/teactn'; +import React, { getDispatch, withGlobal } from './lib/teact/teactn'; -import { GlobalActions, GlobalState } from './global/types'; +import { GlobalState } from './global/types'; import { INACTIVE_MARKER, PAGE_TITLE } from './config'; import { pick } from './util/iteratees'; @@ -17,9 +17,10 @@ import { hasStoredSession } from './util/sessions'; // import Test from './components/test/TestNoRedundancy'; type StateProps = Pick; -type DispatchProps = Pick; -const App: FC = ({ authState, disconnect }) => { +const App: FC = ({ authState }) => { + const { disconnect } = getDispatch(); + const [isInactive, markInactive] = useFlag(false); useEffect(() => { @@ -67,5 +68,4 @@ function renderMain() { export default withGlobal( (global): StateProps => pick(global, ['authState']), - (setGlobal, actions): DispatchProps => pick(actions, ['disconnect']), )(App); diff --git a/src/components/auth/Auth.tsx b/src/components/auth/Auth.tsx index 6a71dc428..ad0e40604 100644 --- a/src/components/auth/Auth.tsx +++ b/src/components/auth/Auth.tsx @@ -1,7 +1,7 @@ import React, { FC, useEffect, memo } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions, GlobalState } from '../../global/types'; +import { GlobalState } from '../../global/types'; import '../../modules/actions/initial'; import { pick } from '../../util/iteratees'; @@ -19,11 +19,14 @@ import AuthQrCode from './AuthQrCode'; import './Auth.scss'; type StateProps = Pick; -type DispatchProps = Pick; -const Auth: FC = ({ - authState, reset, initApi, returnToAuthPhoneNumber, goToAuthQrCode, +const Auth: FC = ({ + authState, }) => { + const { + reset, initApi, returnToAuthPhoneNumber, goToAuthQrCode, + } = getDispatch(); + useEffect(() => { reset(); initApi(); @@ -73,5 +76,4 @@ const Auth: FC = ({ export default memo(withGlobal( (global): StateProps => pick(global, ['authState']), - (global, actions): DispatchProps => pick(actions, ['reset', 'initApi', 'returnToAuthPhoneNumber', 'goToAuthQrCode']), )(Auth)); diff --git a/src/components/auth/AuthCode.tsx b/src/components/auth/AuthCode.tsx index dfc1ab6ec..40421ef10 100644 --- a/src/components/auth/AuthCode.tsx +++ b/src/components/auth/AuthCode.tsx @@ -2,8 +2,8 @@ import { FormEvent } from 'react'; import React, { FC, useState, useEffect, useCallback, memo, useRef, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; -import { GlobalState, GlobalActions } from '../../global/types'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; +import { GlobalState } from '../../global/types'; import { IS_TOUCH_ENV } from '../../util/environment'; import { pick } from '../../util/iteratees'; @@ -16,21 +16,21 @@ import Loading from '../ui/Loading'; import TrackingMonkey from '../common/TrackingMonkey'; type StateProps = Pick; -type DispatchProps = Pick; const CODE_LENGTH = 5; -const AuthCode: FC = ({ +const AuthCode: FC = ({ authPhoneNumber, authIsCodeViaApp, authIsLoading, authError, - setAuthCode, - returnToAuthPhoneNumber, - clearAuthError, }) => { + const { + setAuthCode, + returnToAuthPhoneNumber, + clearAuthError, + } = getDispatch(); + const lang = useLang(); // eslint-disable-next-line no-null/no-null const inputRef = useRef(null); @@ -120,9 +120,4 @@ const AuthCode: FC = ({ export default memo(withGlobal( (global): StateProps => pick(global, ['authPhoneNumber', 'authIsCodeViaApp', 'authIsLoading', 'authError']), - (setGlobal, actions): DispatchProps => pick(actions, [ - 'setAuthCode', - 'returnToAuthPhoneNumber', - 'clearAuthError', - ]), )(AuthCode)); diff --git a/src/components/auth/AuthPassword.tsx b/src/components/auth/AuthPassword.tsx index d6e4b4ffd..2287b79fc 100644 --- a/src/components/auth/AuthPassword.tsx +++ b/src/components/auth/AuthPassword.tsx @@ -1,9 +1,9 @@ import React, { FC, memo, useCallback, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalState, GlobalActions } from '../../global/types'; +import { GlobalState } from '../../global/types'; import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; @@ -12,11 +12,12 @@ import MonkeyPassword from '../common/PasswordMonkey'; import PasswordForm from '../common/PasswordForm'; type StateProps = Pick; -type DispatchProps = Pick; -const AuthPassword: FC = ({ - authIsLoading, authError, authHint, setAuthPassword, clearAuthError, +const AuthPassword: FC = ({ + authIsLoading, authError, authHint, }) => { + const { setAuthPassword, clearAuthError } = getDispatch(); + const lang = useLang(); const [showPassword, setShowPassword] = useState(false); @@ -50,5 +51,4 @@ const AuthPassword: FC = ({ export default memo(withGlobal( (global): StateProps => pick(global, ['authIsLoading', 'authError', 'authHint']), - (setGlobal, actions): DispatchProps => pick(actions, ['setAuthPassword', 'clearAuthError']), )(AuthPassword)); diff --git a/src/components/auth/AuthPhoneNumber.tsx b/src/components/auth/AuthPhoneNumber.tsx index 7901d692d..79d09733b 100644 --- a/src/components/auth/AuthPhoneNumber.tsx +++ b/src/components/auth/AuthPhoneNumber.tsx @@ -6,9 +6,9 @@ import monkeyPath from '../../assets/monkey.svg'; import React, { FC, memo, useCallback, useEffect, useLayoutEffect, useRef, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions, GlobalState } from '../../global/types'; +import { GlobalState } from '../../global/types'; import { LangCode } from '../../types'; import { ApiCountryCode } from '../../api/types'; @@ -38,16 +38,12 @@ type StateProps = Pick; const MIN_NUMBER_LENGTH = 7; let isPreloadInitiated = false; -const AuthPhoneNumber: FC = ({ +const AuthPhoneNumber: FC = ({ connectionState, authState, authPhoneNumber, @@ -58,14 +54,17 @@ const AuthPhoneNumber: FC = ({ authNearestCountry, phoneCodeList, language, - setAuthPhoneNumber, - setAuthRememberMe, - loadNearestCountry, - loadCountryList, - clearAuthError, - goToAuthQrCode, - setSettingOption, }) => { + const { + setAuthPhoneNumber, + setAuthRememberMe, + loadNearestCountry, + loadCountryList, + clearAuthError, + goToAuthQrCode, + setSettingOption, + } = getDispatch(); + const lang = useLang(); // eslint-disable-next-line no-null/no-null const inputRef = useRef(null); @@ -278,13 +277,4 @@ export default memo(withGlobal( phoneCodeList, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'setAuthPhoneNumber', - 'setAuthRememberMe', - 'clearAuthError', - 'loadNearestCountry', - 'loadCountryList', - 'goToAuthQrCode', - 'setSettingOption', - ]), )(AuthPhoneNumber)); diff --git a/src/components/auth/AuthQrCode.tsx b/src/components/auth/AuthQrCode.tsx index da8ec129e..267128323 100644 --- a/src/components/auth/AuthQrCode.tsx +++ b/src/components/auth/AuthQrCode.tsx @@ -2,13 +2,12 @@ import QrCreator from 'qr-creator'; import React, { FC, useEffect, useRef, memo, useCallback, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalState, GlobalActions } from '../../global/types'; +import { GlobalState } from '../../global/types'; import { LangCode } from '../../types'; import { DEFAULT_LANG_CODE } from '../../config'; -import { pick } from '../../util/iteratees'; import { setLanguage } from '../../util/langProvider'; import renderText from '../common/helpers/renderText'; import useLangString from '../../hooks/useLangString'; @@ -19,23 +18,25 @@ import { getSuggestedLanguage } from './helpers/getSuggestedLanguage'; import Loading from '../ui/Loading'; import Button from '../ui/Button'; -type StateProps = Pick & { - language?: LangCode; -}; -type DispatchProps = Pick; +type StateProps = + Pick + & { + language?: LangCode; + }; const DATA_PREFIX = 'tg://login?token='; -const AuthCode: FC = ({ +const AuthCode: FC = ({ connectionState, authState, authQrCode, language, - returnToAuthPhoneNumber, - setSettingOption, }) => { + const { + returnToAuthPhoneNumber, + setSettingOption, + } = getDispatch(); + const suggestedLanguage = getSuggestedLanguage(); const lang = useLang(); // eslint-disable-next-line no-null/no-null @@ -118,7 +119,4 @@ export default memo(withGlobal( language, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'returnToAuthPhoneNumber', 'setSettingOption', - ]), )(AuthCode)); diff --git a/src/components/auth/AuthRegister.tsx b/src/components/auth/AuthRegister.tsx index 3a39d802e..86b3f6d85 100644 --- a/src/components/auth/AuthRegister.tsx +++ b/src/components/auth/AuthRegister.tsx @@ -1,8 +1,8 @@ import { ChangeEvent } from 'react'; import React, { FC, useState, memo } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalState, GlobalActions } from '../../global/types'; +import { GlobalState } from '../../global/types'; import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; @@ -12,11 +12,12 @@ import InputText from '../ui/InputText'; import AvatarEditable from '../ui/AvatarEditable'; type StateProps = Pick; -type DispatchProps = Pick; -const AuthRegister: FC = ({ - authIsLoading, authError, signUp, clearAuthError, uploadProfilePhoto, +const AuthRegister: FC = ({ + authIsLoading, authError, }) => { + const { signUp, clearAuthError, uploadProfilePhoto } = getDispatch(); + const lang = useLang(); const [isButtonShown, setIsButtonShown] = useState(false); const [croppedFile, setCroppedFile] = useState(); @@ -83,5 +84,4 @@ const AuthRegister: FC = ({ export default memo(withGlobal( (global): StateProps => pick(global, ['authIsLoading', 'authError']), - (setGlobal, actions): DispatchProps => pick(actions, ['signUp', 'clearAuthError', 'uploadProfilePhoto']), )(AuthRegister)); diff --git a/src/components/calls/ActiveCallHeader.tsx b/src/components/calls/ActiveCallHeader.tsx index 8c29966e1..e9f04961e 100644 --- a/src/components/calls/ActiveCallHeader.tsx +++ b/src/components/calls/ActiveCallHeader.tsx @@ -2,13 +2,11 @@ import { GroupCallParticipant } from '../../lib/secret-sauce'; import React, { FC, memo, useEffect, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiGroupCall } from '../../api/types'; import { selectActiveGroupCall, selectGroupCallParticipant } from '../../modules/selectors/calls'; -import { pick } from '../../util/iteratees'; import buildClassName from '../../util/buildClassName'; import useLang from '../../hooks/useLang'; @@ -20,14 +18,13 @@ type StateProps = { groupCall?: ApiGroupCall; }; -type DispatchProps = Pick; - -const ActiveCallHeader: FC = ({ +const ActiveCallHeader: FC = ({ groupCall, meParticipant, isGroupCallPanelHidden, - toggleGroupCallPanel, }) => { + const { toggleGroupCallPanel } = getDispatch(); + const lang = useLang(); useEffect(() => { @@ -61,7 +58,4 @@ export default memo(withGlobal( meParticipant: selectGroupCallParticipant(global, global.groupCalls.activeGroupCallId!, global.currentUserId!), }; }, - (setGlobal, actions) => pick(actions, [ - 'toggleGroupCallPanel', - ]), )(ActiveCallHeader)); diff --git a/src/components/calls/CallFallbackConfirm.tsx b/src/components/calls/CallFallbackConfirm.tsx index 18e2c5f9a..ac7b058ee 100644 --- a/src/components/calls/CallFallbackConfirm.tsx +++ b/src/components/calls/CallFallbackConfirm.tsx @@ -1,9 +1,5 @@ import React, { FC, memo, useState } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; - -import { GlobalActions } from '../../global/types'; - -import { pick } from '../../util/iteratees'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import ConfirmDialog from '../ui/ConfirmDialog'; import Checkbox from '../ui/Checkbox'; @@ -21,15 +17,16 @@ interface StateProps { channelTitle: string; } -type DispatchProps = Pick; - -const CallFallbackConfirm: FC = ({ +const CallFallbackConfirm: FC = ({ isOpen, channelTitle, userFullName, - closeCallFallbackConfirm, - inviteToCallFallback, }) => { + const { + closeCallFallbackConfirm, + inviteToCallFallback, + } = getDispatch(); + const [shouldRemove, setShouldRemove] = useState(true); const renderingUserFullName = useCurrentOrPrev(userFullName, true); @@ -62,7 +59,4 @@ export default memo(withGlobal( channelTitle: selectCallFallbackChannelTitle(global), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'closeCallFallbackConfirm', 'inviteToCallFallback', - ]), )(CallFallbackConfirm)); diff --git a/src/components/calls/group/GroupCall.tsx b/src/components/calls/group/GroupCall.tsx index f2f3afe79..5d7aa18cb 100644 --- a/src/components/calls/group/GroupCall.tsx +++ b/src/components/calls/group/GroupCall.tsx @@ -5,10 +5,9 @@ import { import React, { FC, memo, useCallback, useEffect, useMemo, useRef, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import '../../../modules/actions/calls'; -import { GlobalActions } from '../../../global/types'; import { IAnchorPosition } from '../../../types'; import { @@ -17,7 +16,6 @@ import { IS_REQUEST_FULLSCREEN_SUPPORTED, IS_SINGLE_COLUMN_LAYOUT, } from '../../../util/environment'; -import { pick } from '../../../util/iteratees'; import buildClassName from '../../../util/buildClassName'; import { selectGroupCall, @@ -59,12 +57,7 @@ type StateProps = { participants: Record; }; -type DispatchProps = Pick; - -const GroupCall: FC = ({ +const GroupCall: FC = ({ groupCallId, isGroupCallPanelHidden, connectionState, @@ -74,13 +67,16 @@ const GroupCall: FC = ({ isAdmin, participants, - toggleGroupCallVideo, - toggleGroupCallPresentation, - leaveGroupCall, - toggleGroupCallPanel, - connectToActiveGroupCall, - playGroupCallSound, }) => { + const { + toggleGroupCallVideo, + toggleGroupCallPresentation, + leaveGroupCall, + toggleGroupCallPanel, + connectToActiveGroupCall, + playGroupCallSound, + } = getDispatch(); + const lang = useLang(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); @@ -411,12 +407,4 @@ export default memo(withGlobal( participants, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'toggleGroupCallVideo', - 'leaveGroupCall', - 'toggleGroupCallPresentation', - 'toggleGroupCallPanel', - 'connectToActiveGroupCall', - 'playGroupCallSound', - ]), )(GroupCall)); diff --git a/src/components/calls/group/GroupCallParticipantList.tsx b/src/components/calls/group/GroupCallParticipantList.tsx index 00b587582..bd3359c59 100644 --- a/src/components/calls/group/GroupCallParticipantList.tsx +++ b/src/components/calls/group/GroupCallParticipantList.tsx @@ -1,10 +1,7 @@ import { GroupCallParticipant as TypeGroupCallParticipant } from '../../../lib/secret-sauce'; import React, { FC, memo, useMemo } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; - -import { pick } from '../../../util/iteratees'; import useLang from '../../../hooks/useLang'; import { selectActiveGroupCall } from '../../../modules/selectors/calls'; import useInfiniteScroll from '../../../hooks/useInfiniteScroll'; @@ -22,15 +19,16 @@ type StateProps = { canInvite?: boolean; }; -type DispatchProps = Pick; - -const GroupCallParticipantList: FC = ({ - createGroupCallInviteLink, - loadMoreGroupCallParticipants, +const GroupCallParticipantList: FC = ({ participants, participantsCount, openParticipantMenu, }) => { + const { + createGroupCallInviteLink, + loadMoreGroupCallParticipants, + } = getDispatch(); + const lang = useLang(); const participantsIds = useMemo(() => { @@ -82,8 +80,4 @@ export default memo(withGlobal( participantsCount: participantsCount || 0, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'createGroupCallInviteLink', - 'loadMoreGroupCallParticipants', - ]), )(GroupCallParticipantList)); diff --git a/src/components/calls/group/GroupCallParticipantMenu.tsx b/src/components/calls/group/GroupCallParticipantMenu.tsx index b75186d26..d42a06e9e 100644 --- a/src/components/calls/group/GroupCallParticipantMenu.tsx +++ b/src/components/calls/group/GroupCallParticipantMenu.tsx @@ -2,17 +2,15 @@ import { GroupCallParticipant } from '../../../lib/secret-sauce'; import React, { FC, memo, useCallback, useEffect, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { IAnchorPosition } from '../../../types'; -import { GlobalActions } from '../../../global/types'; import buildClassName from '../../../util/buildClassName'; import useThrottle from '../../../hooks/useThrottle'; import useFlag from '../../../hooks/useFlag'; import useLang from '../../../hooks/useLang'; import { selectIsAdminInActiveGroupCall } from '../../../modules/selectors/calls'; -import { pick } from '../../../util/iteratees'; import { GROUP_CALL_DEFAULT_VOLUME, GROUP_CALL_VOLUME_MULTIPLIER } from '../../../config'; import Menu from '../../ui/Menu'; @@ -36,10 +34,6 @@ type StateProps = { isAdmin: boolean; }; -type DispatchProps = Pick; - const VOLUME_ZERO = 0; const VOLUME_LOW = 50; const VOLUME_MEDIUM = 100; @@ -49,19 +43,21 @@ const VOLUME_CHANGE_THROTTLE = 500; const SPEAKER_ICON_SIZE = 24; -const GroupCallParticipantMenu: FC = ({ +const GroupCallParticipantMenu: FC = ({ participant, closeDropdown, isDropdownOpen, anchor, - isAdmin, - toggleGroupCallMute, - setGroupCallParticipantVolume, - toggleGroupCallPanel, - openChat, - requestToSpeak, }) => { + const { + toggleGroupCallMute, + setGroupCallParticipantVolume, + toggleGroupCallPanel, + openChat, + requestToSpeak, + } = getDispatch(); + const lang = useLang(); const [isDeleteUserModalOpen, openDeleteUserModal, closeDeleteUserModal] = useFlag(); @@ -229,11 +225,4 @@ export default memo(withGlobal( isAdmin: selectIsAdminInActiveGroupCall(global), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'setGroupCallParticipantVolume', - 'toggleGroupCallMute', - 'openChat', - 'toggleGroupCallPanel', - 'requestToSpeak', - ]), )(GroupCallParticipantMenu)); diff --git a/src/components/calls/group/GroupCallTopPane.tsx b/src/components/calls/group/GroupCallTopPane.tsx index e345ca802..31c609deb 100644 --- a/src/components/calls/group/GroupCallTopPane.tsx +++ b/src/components/calls/group/GroupCallTopPane.tsx @@ -1,12 +1,10 @@ import React, { FC, memo, useCallback, useEffect, useMemo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiChat, ApiGroupCall, ApiUser } from '../../../api/types'; -import { pick } from '../../../util/iteratees'; import { selectChatGroupCall } from '../../../modules/selectors/calls'; import buildClassName from '../../../util/buildClassName'; import { selectChat } from '../../../modules/selectors'; @@ -29,18 +27,19 @@ type StateProps = { chatsById: Record; }; -type DispatchProps = Pick; - -const GroupCallTopPane: FC = ({ +const GroupCallTopPane: FC = ({ chatId, isActive, groupCall, hasPinnedOffset, - joinGroupCall, - subscribeToGroupCallUpdates, usersById, chatsById, }) => { + const { + joinGroupCall, + subscribeToGroupCallUpdates, + } = getDispatch(); + const lang = useLang(); const handleJoinGroupCall = useCallback(() => { @@ -132,8 +131,4 @@ export default memo(withGlobal( && (global.groupCalls.activeGroupCallId !== groupCall?.id), }; }, - (setGlobal, actions) => pick(actions, [ - 'joinGroupCall', - 'subscribeToGroupCallUpdates', - ]), )(GroupCallTopPane)); diff --git a/src/components/calls/group/MicrophoneButton.tsx b/src/components/calls/group/MicrophoneButton.tsx index c9e6d20c6..475dfd1fd 100644 --- a/src/components/calls/group/MicrophoneButton.tsx +++ b/src/components/calls/group/MicrophoneButton.tsx @@ -2,13 +2,10 @@ import { GroupCallConnectionState } from '../../../lib/secret-sauce'; import React, { FC, memo, useEffect, useMemo, useRef, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; - -import { GlobalActions } from '../../../global/types'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import buildClassName from '../../../util/buildClassName'; import { vibrateShort } from '../../../util/vibrate'; -import { pick } from '../../../util/iteratees'; import usePrevious from '../../../hooks/usePrevious'; import { selectActiveGroupCall, selectGroupCallParticipant } from '../../../modules/selectors/calls'; import useLang from '../../../hooks/useLang'; @@ -27,22 +24,23 @@ type StateProps = { noAudioStream: boolean; }; -type DispatchProps = Pick; - const REQUEST_TO_SPEAK_THROTTLE = 3000; const HOLD_TO_SPEAK_TIME = 200; const ICON_SIZE = 48; -const MicrophoneButton: FC = ({ +const MicrophoneButton: FC = ({ noAudioStream, canSelfUnmute, isMuted, hasRequestedToSpeak, connectionState, - toggleGroupCallMute, - requestToSpeak, - playGroupCallSound, }) => { + const { + toggleGroupCallMute, + requestToSpeak, + playGroupCallSound, + } = getDispatch(); + const lang = useLang(); const muteMouseDownState = useRef('up'); @@ -179,9 +177,4 @@ export default memo(withGlobal( isMuted, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'toggleGroupCallMute', - 'requestToSpeak', - 'playGroupCallSound', - ]), )(MicrophoneButton)); diff --git a/src/components/common/ChatExtra.tsx b/src/components/common/ChatExtra.tsx index e7458ea63..af20bd796 100644 --- a/src/components/common/ChatExtra.tsx +++ b/src/components/common/ChatExtra.tsx @@ -1,9 +1,9 @@ import React, { FC, memo, useCallback, useEffect, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions, GlobalState } from '../../global/types'; +import { GlobalState } from '../../global/types'; import { ApiChat, ApiCountryCode, ApiUser } from '../../api/types'; import { @@ -13,7 +13,6 @@ import { getChatDescription, getChatLink, getHasAdminRight, isChatChannel, isUserId, isUserRightBanned, selectIsChatMuted, } from '../../modules/helpers'; import renderText from './helpers/renderText'; -import { pick } from '../../util/iteratees'; import { copyTextToClipboard } from '../../util/clipboard'; import { formatPhoneNumberWithCode } from '../../util/phoneNumber'; import useLang from '../../hooks/useLang'; @@ -26,17 +25,17 @@ type OwnProps = { forceShowSelf?: boolean; }; -type StateProps = { - user?: ApiUser; - chat?: ApiChat; - canInviteUsers?: boolean; - isMuted?: boolean; - phoneCodeList: ApiCountryCode[]; -} & Pick; +type StateProps = + { + user?: ApiUser; + chat?: ApiChat; + canInviteUsers?: boolean; + isMuted?: boolean; + phoneCodeList: ApiCountryCode[]; + } + & Pick; -type DispatchProps = Pick; - -const ChatExtra: FC = ({ +const ChatExtra: FC = ({ lastSyncTime, user, chat, @@ -44,10 +43,13 @@ const ChatExtra: FC = ({ canInviteUsers, isMuted, phoneCodeList, - loadFullUser, - showNotification, - updateChatMutedState, }) => { + const { + loadFullUser, + showNotification, + updateChatMutedState, + } = getDispatch(); + const { id: userId, fullInfo, @@ -152,7 +154,4 @@ export default memo(withGlobal( lastSyncTime, phoneCodeList, chat, user, canInviteUsers, isMuted, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadFullUser', 'updateChatMutedState', 'showNotification', - ]), )(ChatExtra)); diff --git a/src/components/common/ChatLink.tsx b/src/components/common/ChatLink.tsx index d8ce8b04a..f45dfe135 100644 --- a/src/components/common/ChatLink.tsx +++ b/src/components/common/ChatLink.tsx @@ -1,9 +1,6 @@ import React, { FC, useCallback } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; - -import { pick } from '../../util/iteratees'; import buildClassName from '../../util/buildClassName'; import Link from '../ui/Link'; @@ -14,11 +11,11 @@ type OwnProps = { children: any; }; -type DispatchProps = Pick; - -const ChatLink: FC = ({ - className, chatId, openChat, children, +const ChatLink: FC = ({ + className, chatId, children, }) => { + const { openChat } = getDispatch(); + const handleClick = useCallback(() => { if (chatId) { openChat({ id: chatId }); @@ -34,7 +31,4 @@ const ChatLink: FC = ({ ); }; -export default withGlobal( - undefined, - (setGlobal, actions): DispatchProps => pick(actions, ['openChat']), -)(ChatLink); +export default ChatLink; diff --git a/src/components/common/DeleteChatModal.tsx b/src/components/common/DeleteChatModal.tsx index 622106099..0fb478e93 100644 --- a/src/components/common/DeleteChatModal.tsx +++ b/src/components/common/DeleteChatModal.tsx @@ -1,8 +1,7 @@ import React, { FC, useCallback, memo } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { ApiChat } from '../../api/types'; -import { GlobalActions } from '../../global/types'; import { selectIsChatWithSelf, selectUser } from '../../modules/selectors'; import { @@ -15,7 +14,6 @@ import { isChatChannel, getChatTitle, } from '../../modules/helpers'; -import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import renderText from './helpers/renderText'; @@ -44,11 +42,7 @@ type StateProps = { contactName?: string; }; -type DispatchProps = Pick; - -const DeleteChatModal: FC = ({ +const DeleteChatModal: FC = ({ isOpen, chat, isChannel, @@ -62,12 +56,15 @@ const DeleteChatModal: FC = ({ contactName, onClose, onCloseAnimationEnd, - leaveChannel, - deleteHistory, - deleteChannel, - deleteChatUser, - blockContact, }) => { + const { + leaveChannel, + deleteHistory, + deleteChannel, + deleteChatUser, + blockContact, + } = getDispatch(); + const lang = useLang(); const chatTitle = getChatTitle(lang, chat); @@ -217,6 +214,4 @@ export default memo(withGlobal( contactName, }; }, - (setGlobal, actions): DispatchProps => pick(actions, - ['leaveChannel', 'deleteHistory', 'deleteChannel', 'deleteChatUser', 'blockContact']), )(DeleteChatModal)); diff --git a/src/components/common/DeleteMessageModal.tsx b/src/components/common/DeleteMessageModal.tsx index aa6bc396f..d4f40d6d7 100644 --- a/src/components/common/DeleteMessageModal.tsx +++ b/src/components/common/DeleteMessageModal.tsx @@ -1,11 +1,9 @@ import React, { FC, useCallback, memo } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { ApiMessage } from '../../api/types'; import { IAlbum } from '../../types'; -import { GlobalActions } from '../../global/types'; - import { selectAllowedMessageActions, selectChat, @@ -20,7 +18,6 @@ import { isChatSuperGroup, } from '../../modules/helpers'; import renderText from './helpers/renderText'; -import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import Modal from '../ui/Modal'; @@ -41,9 +38,7 @@ type StateProps = { willDeleteForAll?: boolean; }; -type DispatchProps = Pick; - -const DeleteMessageModal: FC = ({ +const DeleteMessageModal: FC = ({ isOpen, isSchedule, message, @@ -53,9 +48,12 @@ const DeleteMessageModal: FC = ({ willDeleteForCurrentUserOnly, willDeleteForAll, onClose, - deleteMessages, - deleteScheduledMessages, }) => { + const { + deleteMessages, + deleteScheduledMessages, + } = getDispatch(); + const handleDeleteMessageForAll = useCallback(() => { const messageIds = album?.messages ? album.messages.map(({ id }) => id) @@ -129,7 +127,4 @@ export default memo(withGlobal( willDeleteForAll, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'deleteMessages', 'deleteScheduledMessages', - ]), )(DeleteMessageModal)); diff --git a/src/components/common/GroupCallLink.tsx b/src/components/common/GroupCallLink.tsx index 9eeac9354..b11f77b60 100644 --- a/src/components/common/GroupCallLink.tsx +++ b/src/components/common/GroupCallLink.tsx @@ -1,13 +1,11 @@ import React, { FC, useCallback } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiGroupCall } from '../../api/types'; -import { pick } from '../../util/iteratees'; import buildClassName from '../../util/buildClassName'; import Link from '../ui/Link'; +import { getDispatch } from '../../lib/teact/teactn'; type OwnProps = { className?: string; @@ -15,11 +13,11 @@ type OwnProps = { children: any; }; -type DispatchProps = Pick; - -const GroupCallLink: FC = ({ - className, groupCall, joinGroupCall, children, +const GroupCallLink: FC = ({ + className, groupCall, children, }) => { + const { joinGroupCall } = getDispatch(); + const handleClick = useCallback(() => { if (groupCall) { joinGroupCall({ id: groupCall.id, accessHash: groupCall.accessHash }); @@ -35,7 +33,4 @@ const GroupCallLink: FC = ({ ); }; -export default withGlobal( - undefined, - (setGlobal, actions): DispatchProps => pick(actions, ['joinGroupCall']), -)(GroupCallLink); +export default GroupCallLink; diff --git a/src/components/common/GroupChatInfo.tsx b/src/components/common/GroupChatInfo.tsx index fde76670b..2af078305 100644 --- a/src/components/common/GroupChatInfo.tsx +++ b/src/components/common/GroupChatInfo.tsx @@ -2,10 +2,10 @@ import { MouseEvent as ReactMouseEvent } from 'react'; import React, { FC, useEffect, useCallback, memo, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { ApiChat, ApiTypingStatus } from '../../api/types'; -import { GlobalActions, GlobalState } from '../../global/types'; +import { GlobalState } from '../../global/types'; import { MediaViewerOrigin } from '../../types'; import { @@ -15,7 +15,6 @@ import { } from '../../modules/helpers'; import { selectChat, selectChatMessages, selectChatOnlineCount } from '../../modules/selectors'; import renderText from './helpers/renderText'; -import { pick } from '../../util/iteratees'; import useLang, { LangFn } from '../../hooks/useLang'; import Avatar from './Avatar'; @@ -34,15 +33,15 @@ type OwnProps = { noRtl?: boolean; }; -type StateProps = { - chat?: ApiChat; - onlineCount?: number; - areMessagesLoaded: boolean; -} & Pick; +type StateProps = + { + chat?: ApiChat; + onlineCount?: number; + areMessagesLoaded: boolean; + } + & Pick; -type DispatchProps = Pick; - -const GroupChatInfo: FC = ({ +const GroupChatInfo: FC = ({ typingStatus, avatarSize = 'medium', withMediaViewer, @@ -55,9 +54,12 @@ const GroupChatInfo: FC = ({ onlineCount, areMessagesLoaded, lastSyncTime, - loadFullChat, - openMediaViewer, }) => { + const { + loadFullChat, + openMediaViewer, + } = getDispatch(); + const isSuperGroup = chat && isChatSuperGroup(chat); const { id: chatId, isMin, isRestricted } = chat || {}; @@ -164,5 +166,4 @@ export default memo(withGlobal( lastSyncTime, chat, onlineCount, areMessagesLoaded, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadFullChat', 'openMediaViewer']), )(GroupChatInfo)); diff --git a/src/components/common/MessageLink.tsx b/src/components/common/MessageLink.tsx index 658a9ff18..f105e8549 100644 --- a/src/components/common/MessageLink.tsx +++ b/src/components/common/MessageLink.tsx @@ -1,10 +1,8 @@ import React, { FC, useCallback } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiMessage } from '../../api/types'; -import { pick } from '../../util/iteratees'; import buildClassName from '../../util/buildClassName'; import Link from '../ui/Link'; @@ -15,11 +13,11 @@ type OwnProps = { children: any; }; -type DispatchProps = Pick; - -const MessageLink: FC = ({ - className, message, children, focusMessage, +const MessageLink: FC = ({ + className, message, children, }) => { + const { focusMessage } = getDispatch(); + const handleMessageClick = useCallback((): void => { if (message) { focusMessage({ chatId: message.chatId, messageId: message.id }); @@ -35,7 +33,4 @@ const MessageLink: FC = ({ ); }; -export default withGlobal( - undefined, - (setGlobal, actions): DispatchProps => pick(actions, ['focusMessage']), -)(MessageLink); +export default MessageLink; diff --git a/src/components/common/PinMessageModal.tsx b/src/components/common/PinMessageModal.tsx index ca28b6eae..dd646060f 100644 --- a/src/components/common/PinMessageModal.tsx +++ b/src/components/common/PinMessageModal.tsx @@ -1,7 +1,5 @@ import React, { FC, useCallback, memo } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; - -import { GlobalActions } from '../../global/types'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { selectChat, selectIsChatWithSelf, selectUser } from '../../modules/selectors'; import { @@ -12,7 +10,6 @@ import { isChatSuperGroup, isChatChannel, } from '../../modules/helpers'; -import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import renderText from './helpers/renderText'; @@ -36,9 +33,7 @@ type StateProps = { contactName?: string; }; -type DispatchProps = Pick; - -const PinMessageModal: FC = ({ +const PinMessageModal: FC = ({ isOpen, messageId, chatId, @@ -48,8 +43,9 @@ const PinMessageModal: FC = ({ canPinForAll, contactName, onClose, - pinMessage, }) => { + const { pinMessage } = getDispatch(); + const handlePinMessageForAll = useCallback(() => { pinMessage({ chatId, messageId, isUnpin: false, @@ -124,5 +120,4 @@ export default memo(withGlobal( contactName, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['pinMessage']), )(PinMessageModal)); diff --git a/src/components/common/PrivateChatInfo.tsx b/src/components/common/PrivateChatInfo.tsx index b1f172006..3e10d5974 100644 --- a/src/components/common/PrivateChatInfo.tsx +++ b/src/components/common/PrivateChatInfo.tsx @@ -2,16 +2,15 @@ import { MouseEvent as ReactMouseEvent } from 'react'; import React, { FC, useEffect, useCallback, memo, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { ApiUser, ApiTypingStatus, ApiUserStatus } from '../../api/types'; -import { GlobalActions, GlobalState } from '../../global/types'; +import { GlobalState } from '../../global/types'; import { MediaViewerOrigin } from '../../types'; import { selectChatMessages, selectUser, selectUserStatus } from '../../modules/selectors'; import { getUserFullName, getUserStatus, isUserOnline } from '../../modules/helpers'; import renderText from './helpers/renderText'; -import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import Avatar from './Avatar'; @@ -32,17 +31,17 @@ type OwnProps = { noRtl?: boolean; }; -type StateProps = { - user?: ApiUser; - userStatus?: ApiUserStatus; - isSavedMessages?: boolean; - areMessagesLoaded: boolean; - serverTimeOffset: number; -} & Pick; +type StateProps = + { + user?: ApiUser; + userStatus?: ApiUserStatus; + isSavedMessages?: boolean; + areMessagesLoaded: boolean; + serverTimeOffset: number; + } + & Pick; -type DispatchProps = Pick; - -const PrivateChatInfo: FC = ({ +const PrivateChatInfo: FC = ({ typingStatus, avatarSize = 'medium', status, @@ -58,9 +57,12 @@ const PrivateChatInfo: FC = ({ areMessagesLoaded, lastSyncTime, serverTimeOffset, - loadFullUser, - openMediaViewer, }) => { + const { + loadFullUser, + openMediaViewer, + } = getDispatch(); + const { id: userId } = user || {}; const fullName = getUserFullName(user); @@ -153,5 +155,4 @@ export default memo(withGlobal( lastSyncTime, user, userStatus, isSavedMessages, areMessagesLoaded, serverTimeOffset, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadFullUser', 'openMediaViewer']), )(PrivateChatInfo)); diff --git a/src/components/common/ProfileInfo.tsx b/src/components/common/ProfileInfo.tsx index adbd99cbe..916267795 100644 --- a/src/components/common/ProfileInfo.tsx +++ b/src/components/common/ProfileInfo.tsx @@ -1,10 +1,10 @@ import React, { FC, useEffect, useCallback, memo, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { ApiUser, ApiChat, ApiUserStatus } from '../../api/types'; -import { GlobalActions, GlobalState } from '../../global/types'; +import { GlobalState } from '../../global/types'; import { MediaViewerOrigin } from '../../types'; import { IS_TOUCH_ENV } from '../../util/environment'; @@ -13,7 +13,6 @@ import { getUserFullName, getUserStatus, isChatChannel, isUserOnline, } from '../../modules/helpers'; import renderText from './helpers/renderText'; -import { pick } from '../../util/iteratees'; import { captureEvents, SwipeDirection } from '../../util/captureEvents'; import buildClassName from '../../util/buildClassName'; import usePhotosPreload from './hooks/usePhotosPreload'; @@ -30,18 +29,18 @@ type OwnProps = { forceShowSelf?: boolean; }; -type StateProps = { - user?: ApiUser; - userStatus?: ApiUserStatus; - chat?: ApiChat; - isSavedMessages?: boolean; - animationLevel: 0 | 1 | 2; - serverTimeOffset: number; -} & Pick; +type StateProps = + { + user?: ApiUser; + userStatus?: ApiUserStatus; + chat?: ApiChat; + isSavedMessages?: boolean; + animationLevel: 0 | 1 | 2; + serverTimeOffset: number; + } + & Pick; -type DispatchProps = Pick; - -const ProfileInfo: FC = ({ +const ProfileInfo: FC = ({ forceShowSelf, user, userStatus, @@ -50,9 +49,12 @@ const ProfileInfo: FC = ({ connectionState, animationLevel, serverTimeOffset, - loadFullUser, - openMediaViewer, }) => { + const { + loadFullUser, + openMediaViewer, + } = getDispatch(); + const lang = useLang(); const { id: userId } = user || {}; @@ -246,5 +248,4 @@ export default memo(withGlobal( serverTimeOffset, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadFullUser', 'openMediaViewer']), )(ProfileInfo)); diff --git a/src/components/common/ReportMessageModal.tsx b/src/components/common/ReportMessageModal.tsx index bd1e5fda8..ebff72f8b 100644 --- a/src/components/common/ReportMessageModal.tsx +++ b/src/components/common/ReportMessageModal.tsx @@ -3,13 +3,10 @@ import { ChangeEvent } from 'react'; import React, { FC, memo, useCallback, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch } from '../../lib/teact/teactn'; import { ApiReportReason } from '../../api/types'; -import { GlobalActions } from '../../global/types'; - -import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import Modal from '../ui/Modal'; @@ -23,15 +20,16 @@ export type OwnProps = { onClose: () => void; }; -type DispatchProps = Pick; - -const ReportMessageModal: FC = ({ +const ReportMessageModal: FC = ({ isOpen, messageIds, - reportMessages, - exitMessageSelectMode, onClose, }) => { + const { + reportMessages, + exitMessageSelectMode, + } = getDispatch(); + const [selectedReason, setSelectedReason] = useState('spam'); const [description, setDescription] = useState(''); @@ -91,8 +89,4 @@ const ReportMessageModal: FC = ({ ); }; -export default memo(withGlobal( - undefined, (setGlobal, actions): DispatchProps => pick(actions, [ - 'reportMessages', 'exitMessageSelectMode', - ]), -)(ReportMessageModal)); +export default memo(ReportMessageModal); diff --git a/src/components/common/SeenByModal.tsx b/src/components/common/SeenByModal.tsx index 22b3d2e5b..892c4837d 100644 --- a/src/components/common/SeenByModal.tsx +++ b/src/components/common/SeenByModal.tsx @@ -1,9 +1,6 @@ import React, { FC, useCallback, memo } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; - -import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import { selectChatMessage } from '../../modules/selectors'; import useCurrentOrPrev from '../../hooks/useCurrentOrPrev'; @@ -21,16 +18,17 @@ export type StateProps = { memberIds?: string[]; }; -type DispatchProps = Pick; - const CLOSE_ANIMATION_DURATION = 100; -const SeenByModal: FC = ({ +const SeenByModal: FC = ({ isOpen, memberIds, - openChat, - closeSeenByModal, }) => { + const { + openChat, + closeSeenByModal, + } = getDispatch(); + const lang = useLang(); const handleClick = useCallback((userId: string) => { @@ -83,5 +81,4 @@ export default memo(withGlobal( memberIds: selectChatMessage(global, chatId, messageId)?.seenByUserIds, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['openChat', 'closeSeenByModal']), )(SeenByModal)); diff --git a/src/components/common/StickerSetModal.tsx b/src/components/common/StickerSetModal.tsx index ddcad5370..6b792a7a2 100644 --- a/src/components/common/StickerSetModal.tsx +++ b/src/components/common/StickerSetModal.tsx @@ -1,13 +1,11 @@ import React, { FC, memo, useCallback, useEffect, useRef, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { ApiSticker, ApiStickerSet } from '../../api/types'; -import { GlobalActions } from '../../global/types'; import { STICKER_SIZE_MODAL } from '../../config'; -import { pick } from '../../util/iteratees'; import { selectChat, selectCurrentMessageList, selectStickerSet, selectStickerSetByShortName, } from '../../modules/selectors'; @@ -35,21 +33,22 @@ type StateProps = { stickerSet?: ApiStickerSet; }; -type DispatchProps = Pick; - const INTERSECTION_THROTTLE = 200; -const StickerSetModal: FC = ({ +const StickerSetModal: FC = ({ isOpen, fromSticker, stickerSetShortName, stickerSet, canSendStickers, onClose, - loadStickers, - toggleStickerSet, - sendMessage, }) => { + const { + loadStickers, + toggleStickerSet, + sendMessage, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); const lang = useLang(); @@ -153,9 +152,4 @@ export default memo(withGlobal( : undefined, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadStickers', - 'toggleStickerSet', - 'sendMessage', - ]), )(StickerSetModal)); diff --git a/src/components/common/UiLoader.tsx b/src/components/common/UiLoader.tsx index b34dc2896..cd81ca5cb 100644 --- a/src/components/common/UiLoader.tsx +++ b/src/components/common/UiLoader.tsx @@ -1,8 +1,8 @@ import React, { FC, useEffect } from '../../lib/teact/teact'; -import { getGlobal, withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, getGlobal, withGlobal } from '../../lib/teact/teactn'; import { ApiMediaFormat } from '../../api/types'; -import { GlobalActions, GlobalState } from '../../global/types'; +import { GlobalState } from '../../global/types'; import { getChatAvatarHash } from '../../modules/helpers/chats'; // Direct import for better module splitting import useFlag from '../../hooks/useFlag'; @@ -12,7 +12,6 @@ import { preloadImage } from '../../util/files'; import preloadFonts from '../../util/fonts'; import * as mediaLoader from '../../util/mediaLoader'; import { Bundles, loadModule } from '../../util/moduleLoader'; -import { pick } from '../../util/iteratees'; import buildClassName from '../../util/buildClassName'; import './UiLoader.scss'; @@ -28,14 +27,14 @@ type OwnProps = { children: any; }; -type StateProps = Pick & { - hasCustomBackground?: boolean; - hasCustomBackgroundColor: boolean; - isRightColumnShown?: boolean; - leftColumnWidth?: number; -}; - -type DispatchProps = Pick; +type StateProps = + Pick + & { + hasCustomBackground?: boolean; + hasCustomBackgroundColor: boolean; + isRightColumnShown?: boolean; + leftColumnWidth?: number; + }; const MAX_PRELOAD_DELAY = 700; const SECOND_STATE_DELAY = 1000; @@ -77,7 +76,7 @@ const preloadTasks = { authQrCode: preloadFonts, }; -const UiLoader: FC = ({ +const UiLoader: FC = ({ page, children, hasCustomBackground, @@ -85,8 +84,9 @@ const UiLoader: FC = ({ isRightColumnShown, shouldSkipHistoryAnimations, leftColumnWidth, - setIsUiReady, }) => { + const { setIsUiReady } = getDispatch(); + const [isReady, markReady] = useFlag(); const { shouldRender: shouldRenderMask, transitionClassNames, @@ -171,5 +171,4 @@ export default withGlobal( leftColumnWidth: global.leftColumnWidth, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['setIsUiReady']), )(UiLoader); diff --git a/src/components/common/UserLink.tsx b/src/components/common/UserLink.tsx index 5cf5bbee3..3064bc4ab 100644 --- a/src/components/common/UserLink.tsx +++ b/src/components/common/UserLink.tsx @@ -1,13 +1,11 @@ import React, { FC, useCallback } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiChat, ApiUser } from '../../api/types'; -import { pick } from '../../util/iteratees'; import buildClassName from '../../util/buildClassName'; import Link from '../ui/Link'; +import { getDispatch } from '../../lib/teact/teactn'; type OwnProps = { className?: string; @@ -15,11 +13,11 @@ type OwnProps = { children: any; }; -type DispatchProps = Pick; - -const UserLink: FC = ({ - className, sender, openUserInfo, children, +const UserLink: FC = ({ + className, sender, children, }) => { + const { openUserInfo } = getDispatch(); + const handleClick = useCallback(() => { if (sender) { openUserInfo({ id: sender.id }); @@ -35,7 +33,4 @@ const UserLink: FC = ({ ); }; -export default withGlobal( - undefined, - (setGlobal, actions): DispatchProps => pick(actions, ['openUserInfo']), -)(UserLink); +export default UserLink; diff --git a/src/components/left/ChatFolderModal.tsx b/src/components/left/ChatFolderModal.tsx index ff9d43670..ff80f58da 100644 --- a/src/components/left/ChatFolderModal.tsx +++ b/src/components/left/ChatFolderModal.tsx @@ -1,12 +1,10 @@ import React, { FC, useCallback, memo, useMemo, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiChatFolder } from '../../api/types'; -import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import Modal from '../ui/Modal'; @@ -25,17 +23,16 @@ type StateProps = { folderOrderedIds?: number[]; }; -type DispatchProps = Pick; - -const ChatFolderModal: FC = ({ +const ChatFolderModal: FC = ({ isOpen, chatId, foldersById, folderOrderedIds, onClose, onCloseAnimationEnd, - editChatFolders, }) => { + const { editChatFolders } = getDispatch(); + const lang = useLang(); const initialSelectedFolderIds = useMemo(() => { @@ -106,5 +103,4 @@ export default memo(withGlobal( folderOrderedIds, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['editChatFolders']), )(ChatFolderModal)); diff --git a/src/components/left/LeftColumn.tsx b/src/components/left/LeftColumn.tsx index 898af7a95..77b805be4 100644 --- a/src/components/left/LeftColumn.tsx +++ b/src/components/left/LeftColumn.tsx @@ -1,14 +1,12 @@ import React, { FC, memo, useCallback, useEffect, useRef, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { LeftColumnContent, SettingsScreens } from '../../types'; import { LAYERS_ANIMATION_NAME } from '../../util/environment'; import captureEscKeyListener from '../../util/captureEscKeyListener'; -import { pick } from '../../util/iteratees'; import useFoldersReducer from '../../hooks/reducers/useFoldersReducer'; import { useResize } from '../../hooks/useResize'; @@ -28,11 +26,6 @@ type StateProps = { leftColumnWidth?: number; }; -type DispatchProps = Pick; - enum ContentType { Main, // eslint-disable-next-line @typescript-eslint/no-shadow @@ -47,21 +40,24 @@ enum ContentType { const RENDER_COUNT = Object.keys(ContentType).length / 2; const RESET_TRANSITION_DELAY_MS = 250; -const LeftColumn: FC = ({ +const LeftColumn: FC = ({ searchQuery, searchDate, activeChatFolder, shouldSkipHistoryAnimations, leftColumnWidth, - setGlobalSearchQuery, - setGlobalSearchChatId, - resetChatCreation, - setGlobalSearchDate, - loadPasswordInfo, - clearTwoFaError, - setLeftColumnWidth, - resetLeftColumnWidth, }) => { + const { + setGlobalSearchQuery, + setGlobalSearchChatId, + resetChatCreation, + setGlobalSearchDate, + loadPasswordInfo, + clearTwoFaError, + setLeftColumnWidth, + resetLeftColumnWidth, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const resizeRef = useRef(null); const [content, setContent] = useState(LeftColumnContent.ChatList); @@ -374,8 +370,4 @@ export default memo(withGlobal( searchQuery: query, searchDate: date, activeChatFolder, shouldSkipHistoryAnimations, leftColumnWidth, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'setGlobalSearchQuery', 'setGlobalSearchChatId', 'resetChatCreation', 'setGlobalSearchDate', - 'loadPasswordInfo', 'clearTwoFaError', 'setLeftColumnWidth', 'resetLeftColumnWidth', - ]), )(LeftColumn)); diff --git a/src/components/left/main/Chat.tsx b/src/components/left/main/Chat.tsx index 73130157d..6de75589a 100644 --- a/src/components/left/main/Chat.tsx +++ b/src/components/left/main/Chat.tsx @@ -1,11 +1,10 @@ import React, { FC, memo, useCallback, useLayoutEffect, useMemo, useRef, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import useLang, { LangFn } from '../../../hooks/useLang'; -import { GlobalActions } from '../../../global/types'; import { ApiChat, ApiUser, ApiMessage, ApiMessageOutgoingStatus, ApiFormattedText, MAIN_THREAD_ID, ApiUserStatus, } from '../../../api/types'; @@ -36,7 +35,6 @@ import { renderActionMessageText } from '../../common/helpers/renderActionMessag import renderText from '../../common/helpers/renderText'; import { fastRaf } from '../../../util/schedulers'; import buildClassName from '../../../util/buildClassName'; -import { pick } from '../../../util/iteratees'; import useEnsureMessage from '../../../hooks/useEnsureMessage'; import useChatContextActions from '../../../hooks/useChatContextActions'; import useFlag from '../../../hooks/useFlag'; @@ -83,11 +81,9 @@ type StateProps = { lastSyncTime?: number; }; -type DispatchProps = Pick; - const ANIMATION_DURATION = 200; -const Chat: FC = ({ +const Chat: FC = ({ style, chatId, folderId, @@ -110,9 +106,12 @@ const Chat: FC = ({ canScrollDown, canChangeFolder, lastSyncTime, - openChat, - focusLastMessage, }) => { + const { + openChat, + focusLastMessage, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const ref = useRef(null); @@ -390,8 +389,4 @@ export default memo(withGlobal( ...(actionTargetUserIds && { usersById }), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'openChat', - 'focusLastMessage', - ]), )(Chat)); diff --git a/src/components/left/main/ChatFolders.tsx b/src/components/left/main/ChatFolders.tsx index 91dca7041..2f2472ac8 100644 --- a/src/components/left/main/ChatFolders.tsx +++ b/src/components/left/main/ChatFolders.tsx @@ -1,15 +1,15 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useRef, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ApiChat, ApiChatFolder, ApiUser } from '../../../api/types'; -import { GlobalActions, GlobalState } from '../../../global/types'; +import { GlobalState } from '../../../global/types'; import { NotifyException, NotifySettings, SettingsScreens } from '../../../types'; import { FolderEditDispatch } from '../../../hooks/reducers/useFoldersReducer'; import { IS_TOUCH_ENV } from '../../../util/environment'; -import { buildCollectionByKey, pick } from '../../../util/iteratees'; +import { buildCollectionByKey } from '../../../util/iteratees'; import { captureEvents, SwipeDirection } from '../../../util/captureEvents'; import { getFolderUnreadDialogs } from '../../../modules/helpers'; import { selectNotifyExceptions, selectNotifySettings } from '../../../modules/selectors'; @@ -43,12 +43,10 @@ type StateProps = { shouldSkipHistoryAnimations?: boolean; }; -type DispatchProps = Pick; - const INFO_THROTTLE = 3000; const SAVED_MESSAGES_HOTKEY = '0'; -const ChatFolders: FC = ({ +const ChatFolders: FC = ({ allListIds, chatsById, usersById, @@ -62,10 +60,13 @@ const ChatFolders: FC = ({ shouldSkipHistoryAnimations, foldersDispatch, onScreenSelect, - loadChatFolders, - setActiveChatFolder, - openChat, }) => { + const { + loadChatFolders, + setActiveChatFolder, + openChat, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const transitionRef = useRef(null); @@ -267,9 +268,4 @@ export default memo(withGlobal( shouldSkipHistoryAnimations, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadChatFolders', - 'setActiveChatFolder', - 'openChat', - ]), )(ChatFolders)); diff --git a/src/components/left/main/ChatList.tsx b/src/components/left/main/ChatList.tsx index f4fac0027..42576f502 100644 --- a/src/components/left/main/ChatList.tsx +++ b/src/components/left/main/ChatList.tsx @@ -1,9 +1,9 @@ import React, { FC, memo, useMemo, useCallback, useEffect, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions, GlobalState } from '../../../global/types'; +import { GlobalState } from '../../../global/types'; import { ApiChat, ApiChatFolder, ApiUser, } from '../../../api/types'; @@ -13,7 +13,7 @@ import { FolderEditDispatch } from '../../../hooks/reducers/useFoldersReducer'; import { ALL_CHATS_PRELOAD_DISABLED, CHAT_HEIGHT_PX, CHAT_LIST_SLICE } from '../../../config'; import { IS_ANDROID, IS_MAC_OS, IS_PWA } from '../../../util/environment'; import usePrevious from '../../../hooks/usePrevious'; -import { mapValues, pick } from '../../../util/iteratees'; +import { mapValues } from '../../../util/iteratees'; import { getChatOrder, prepareChatList, prepareFolderListIds, reduceChatList, } from '../../../modules/helpers'; @@ -48,16 +48,12 @@ type StateProps = { notifyExceptions?: Record; }; -type DispatchProps = Pick; - enum FolderTypeToListType { 'all' = 'active', 'archived' = 'archived', } -const ChatList: FC = ({ +const ChatList: FC = ({ folderType, folderId, isActive, @@ -72,12 +68,15 @@ const ChatList: FC = ({ notifyExceptions, foldersDispatch, onScreenSelect, - loadMoreChats, - preloadTopChatMessages, - preloadArchivedChats, - openChat, - openNextChat, }) => { + const { + loadMoreChats, + preloadTopChatMessages, + preloadArchivedChats, + openChat, + openNextChat, + } = getDispatch(); + const [currentListIds, currentPinnedIds] = useMemo(() => { return folderType === 'folder' && chatFolder ? prepareFolderListIds(allListIds, chatsById, usersById, chatFolder, notifySettings, notifyExceptions) @@ -273,11 +272,4 @@ export default memo(withGlobal( }), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadMoreChats', - 'preloadTopChatMessages', - 'preloadArchivedChats', - 'openChat', - 'openNextChat', - ]), )(ChatList)); diff --git a/src/components/left/main/ContactList.tsx b/src/components/left/main/ContactList.tsx index 448df0085..c84cdaa83 100644 --- a/src/components/left/main/ContactList.tsx +++ b/src/components/left/main/ContactList.tsx @@ -1,14 +1,12 @@ import React, { FC, useEffect, useCallback, useMemo, memo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiUser, ApiUserStatus } from '../../../api/types'; import { IS_SINGLE_COLUMN_LAYOUT } from '../../../util/environment'; import { throttle } from '../../../util/schedulers'; -import { pick } from '../../../util/iteratees'; import { filterUsersByName, sortUserIds } from '../../../modules/helpers'; import useInfiniteScroll from '../../../hooks/useInfiniteScroll'; import useHistoryBack from '../../../hooks/useHistoryBack'; @@ -31,11 +29,9 @@ type StateProps = { serverTimeOffset: number; }; -type DispatchProps = Pick; - const runThrottled = throttle((cb) => cb(), 60000, true); -const ContactList: FC = ({ +const ContactList: FC = ({ isActive, filter, usersById, @@ -43,9 +39,12 @@ const ContactList: FC = ({ contactIds, serverTimeOffset, onReset, - loadContactList, - openChat, }) => { + const { + loadContactList, + openChat, + } = getDispatch(); + // Due to the parent Transition, this component never gets unmounted, // that's why we use throttled API call on every update. useEffect(() => { @@ -108,5 +107,4 @@ export default memo(withGlobal( serverTimeOffset: global.serverTimeOffset, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadContactList', 'openChat']), )(ContactList)); diff --git a/src/components/left/main/LeftMainHeader.tsx b/src/components/left/main/LeftMainHeader.tsx index c83dabd80..d9c9aa219 100644 --- a/src/components/left/main/LeftMainHeader.tsx +++ b/src/components/left/main/LeftMainHeader.tsx @@ -1,9 +1,8 @@ import React, { FC, useCallback, useMemo, memo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { LeftColumnContent, ISettings } from '../../../types'; import { ApiChat } from '../../../api/types'; @@ -12,7 +11,6 @@ import { } from '../../../config'; import { IS_SINGLE_COLUMN_LAYOUT } from '../../../util/environment'; import buildClassName from '../../../util/buildClassName'; -import { pick } from '../../../util/iteratees'; import { isChatArchived } from '../../../modules/helpers'; import { formatDateToString } from '../../../util/dateFormat'; import { selectTheme } from '../../../modules/selectors'; @@ -51,10 +49,6 @@ type StateProps = { chatsById?: Record; }; -type DispatchProps = Pick; - const ANIMATION_LEVEL_OPTIONS = [0, 1, 2]; const PRODUCTION_HOSTNAME = 'web.telegram.org'; @@ -62,14 +56,13 @@ const LEGACY_VERSION_URL = 'https://web.telegram.org/?legacy=1'; const WEBK_VERSION_URL = 'https://web.telegram.org/k/'; const PERMANENT_VERSION_KEY = 'kz_version'; -const LeftMainHeader: FC = ({ +const LeftMainHeader: FC = ({ content, contactsFilter, onSearchQuery, onSelectSettings, onSelectContacts, onSelectArchived, - setGlobalSearchChatId, onReset, searchQuery, isLoading, @@ -80,11 +73,14 @@ const LeftMainHeader: FC = ({ theme, animationLevel, chatsById, - openChat, - openTipsChat, - setGlobalSearchDate, - setSettingOption, }) => { + const { + openChat, + openTipsChat, + setGlobalSearchDate, + setSettingOption, setGlobalSearchChatId, + } = getDispatch(); + const lang = useLang(); const hasMenu = content === LeftColumnContent.ChatList; const clearedDateSearchParam = { date: undefined }; @@ -327,11 +323,4 @@ export default memo(withGlobal( animationLevel, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'openChat', - 'openTipsChat', - 'setGlobalSearchDate', - 'setGlobalSearchChatId', - 'setSettingOption', - ]), )(LeftMainHeader)); diff --git a/src/components/left/newChat/NewChatStep1.tsx b/src/components/left/newChat/NewChatStep1.tsx index 094ea53b2..8201e79e6 100644 --- a/src/components/left/newChat/NewChatStep1.tsx +++ b/src/components/left/newChat/NewChatStep1.tsx @@ -1,12 +1,11 @@ import React, { FC, useCallback, useEffect, useMemo, memo, } from '../../../lib/teact/teact'; -import { getGlobal, withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, getGlobal, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiChat } from '../../../api/types'; -import { pick, unique } from '../../../util/iteratees'; +import { unique } from '../../../util/iteratees'; import { throttle } from '../../../util/schedulers'; import { filterUsersByName, isUserBot, sortChatIds } from '../../../modules/helpers'; import useLang from '../../../hooks/useLang'; @@ -34,11 +33,9 @@ type StateProps = { globalUserIds?: string[]; }; -type DispatchProps = Pick; - const runThrottled = throttle((cb) => cb(), 60000, true); -const NewChatStep1: FC = ({ +const NewChatStep1: FC = ({ isChannel, isActive, selectedMemberIds, @@ -51,9 +48,12 @@ const NewChatStep1: FC = ({ isSearching, localUserIds, globalUserIds, - loadContactList, - setGlobalSearchQuery, }) => { + const { + loadContactList, + setGlobalSearchQuery, + } = getDispatch(); + // Due to the parent Transition, this component never gets unmounted, // that's why we use throttled API call on every update. useEffect(() => { @@ -162,5 +162,4 @@ export default memo(withGlobal( localUserIds, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadContactList', 'setGlobalSearchQuery']), )(NewChatStep1)); diff --git a/src/components/left/newChat/NewChatStep2.tsx b/src/components/left/newChat/NewChatStep2.tsx index e5a4a7478..2f2c448ce 100644 --- a/src/components/left/newChat/NewChatStep2.tsx +++ b/src/components/left/newChat/NewChatStep2.tsx @@ -1,12 +1,10 @@ import React, { FC, useState, useCallback, useEffect, memo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ChatCreationProgress } from '../../../types'; -import { pick } from '../../../util/iteratees'; import useLang from '../../../hooks/useLang'; import useHistoryBack from '../../../hooks/useHistoryBack'; @@ -30,21 +28,22 @@ type StateProps = { creationError?: string; }; -type DispatchProps = Pick; - // TODO @implement const MAX_USERS_FOR_LEGACY_CHAT = 199; // Accounting for current user -const NewChatStep2: FC = ({ +const NewChatStep2: FC = ({ isChannel, isActive, memberIds, onReset, creationProgress, creationError, - createGroupChat, - createChannel, }) => { + const { + createGroupChat, + createChannel, + } = getDispatch(); + const lang = useLang(); useHistoryBack(isActive, onReset); @@ -202,7 +201,4 @@ export default memo(withGlobal( creationError, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'createGroupChat', 'createChannel', - ]), )(NewChatStep2)); diff --git a/src/components/left/search/AudioResults.tsx b/src/components/left/search/AudioResults.tsx index 5cdb442e4..bc9ec4e59 100644 --- a/src/components/left/search/AudioResults.tsx +++ b/src/components/left/search/AudioResults.tsx @@ -1,15 +1,13 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { AudioOrigin, LoadMoreDirection } from '../../../types'; import { SLIDE_TRANSITION_DURATION } from '../../../config'; import { MEMO_EMPTY_ARRAY } from '../../../util/memo'; import { createMapStateToProps, StateProps } from './helpers/createMapStateToProps'; -import { pick } from '../../../util/iteratees'; import { formatMonthAndYear, toYearMonth } from '../../../util/dateFormat'; import { getSenderName } from './helpers/getSenderName'; import { throttle } from '../../../util/schedulers'; @@ -26,11 +24,9 @@ export type OwnProps = { searchQuery?: string; }; -type DispatchProps = Pick; - const runThrottled = throttle((cb) => cb(), 500, true); -const AudioResults: FC = ({ +const AudioResults: FC = ({ theme, isVoice, searchQuery, @@ -42,10 +38,13 @@ const AudioResults: FC = ({ foundIds, lastSyncTime, activeDownloads, - searchMessagesGlobal, - focusMessage, - openAudioPlayer, }) => { + const { + searchMessagesGlobal, + focusMessage, + openAudioPlayer, + } = getDispatch(); + const lang = useLang(); const currentType = isVoice ? 'voice' : 'audio'; const handleLoadMore = useCallback(({ direction }: { direction: LoadMoreDirection }) => { @@ -137,9 +136,4 @@ const AudioResults: FC = ({ export default memo(withGlobal( createMapStateToProps('audio'), - (setGlobal, actions): DispatchProps => pick(actions, [ - 'searchMessagesGlobal', - 'focusMessage', - 'openAudioPlayer', - ]), )(AudioResults)); diff --git a/src/components/left/search/ChatMessage.tsx b/src/components/left/search/ChatMessage.tsx index 331d089ac..fddd582f3 100644 --- a/src/components/left/search/ChatMessage.tsx +++ b/src/components/left/search/ChatMessage.tsx @@ -1,9 +1,8 @@ import React, { FC, memo, useCallback, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiChat, ApiUser, ApiMessage, ApiMessageOutgoingStatus, } from '../../../api/types'; @@ -20,7 +19,6 @@ import { } from '../../../modules/helpers'; import { selectChat, selectUser } from '../../../modules/selectors'; import renderText from '../../common/helpers/renderText'; -import { pick } from '../../../util/iteratees'; import useMedia from '../../../hooks/useMedia'; import { formatPastTimeShort } from '../../../util/dateFormat'; import useLang, { LangFn } from '../../../hooks/useLang'; @@ -46,17 +44,16 @@ type StateProps = { lastSyncTime?: number; }; -type DispatchProps = Pick; - -const ChatMessage: FC = ({ +const ChatMessage: FC = ({ message, searchQuery, chatId, chat, privateChatUser, - focusMessage, lastSyncTime, }) => { + const { focusMessage } = getDispatch(); + const mediaThumbnail = getMessageMediaThumbDataUri(message); const mediaBlobUrl = useMedia(getMessageMediaHash(message, 'micro')); const isRoundVideo = Boolean(getMessageRoundVideo(message)); @@ -140,7 +137,4 @@ export default memo(withGlobal( ...(privateChatUserId && { privateChatUser: selectUser(global, privateChatUserId) }), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'focusMessage', - ]), )(ChatMessage)); diff --git a/src/components/left/search/ChatMessageResults.tsx b/src/components/left/search/ChatMessageResults.tsx index ee9bd0c41..65a736bae 100644 --- a/src/components/left/search/ChatMessageResults.tsx +++ b/src/components/left/search/ChatMessageResults.tsx @@ -1,13 +1,11 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ApiChat, ApiMessage } from '../../../api/types'; -import { GlobalActions } from '../../../global/types'; import { LoadMoreDirection } from '../../../types'; -import { pick } from '../../../util/iteratees'; import { getMessageSummaryText } from '../../../modules/helpers'; import { MEMO_EMPTY_ARRAY } from '../../../util/memo'; import { throttle } from '../../../util/schedulers'; @@ -34,11 +32,9 @@ type StateProps = { lastSyncTime?: number; }; -type DispatchProps = Pick; - const runThrottled = throttle((cb) => cb(), 500, true); -const ChatMessageResults: FC = ({ +const ChatMessageResults: FC = ({ searchQuery, currentUserId, dateSearchQuery, @@ -47,9 +43,10 @@ const ChatMessageResults: FC = ({ chatsById, fetchingStatus, lastSyncTime, - searchMessagesGlobal, onSearchDateSelect, }) => { + const { searchMessagesGlobal } = getDispatch(); + const lang = useLang(); const handleLoadMore = useCallback(({ direction }: { direction: LoadMoreDirection }) => { if (lastSyncTime && direction === LoadMoreDirection.Backwards) { @@ -142,5 +139,4 @@ export default memo(withGlobal( lastSyncTime, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['searchMessagesGlobal']), )(ChatMessageResults)); diff --git a/src/components/left/search/ChatResults.tsx b/src/components/left/search/ChatResults.tsx index b56270aba..021ef032d 100644 --- a/src/components/left/search/ChatResults.tsx +++ b/src/components/left/search/ChatResults.tsx @@ -1,14 +1,13 @@ import React, { FC, memo, useCallback, useMemo, useState, } from '../../../lib/teact/teact'; -import { getGlobal, withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, getGlobal, withGlobal } from '../../../lib/teact/teactn'; import { ApiChat, ApiMessage } from '../../../api/types'; -import { GlobalActions } from '../../../global/types'; import { LoadMoreDirection } from '../../../types'; import { IS_SINGLE_COLUMN_LAYOUT } from '../../../util/environment'; -import { unique, pick } from '../../../util/iteratees'; +import { unique } from '../../../util/iteratees'; import { getMessageSummaryText, sortChatIds, filterUsersByName } from '../../../modules/helpers'; import { MEMO_EMPTY_ARRAY } from '../../../util/memo'; import { throttle } from '../../../util/schedulers'; @@ -45,21 +44,21 @@ type StateProps = { lastSyncTime?: number; }; -type DispatchProps = Pick; - const MIN_QUERY_LENGTH_FOR_GLOBAL_SEARCH = 4; const LESS_LIST_ITEMS_AMOUNT = 5; const runThrottled = throttle((cb) => cb(), 500, true); -const ChatResults: FC = ({ +const ChatResults: FC = ({ searchQuery, searchDate, dateSearchQuery, currentUserId, localContactIds, localChatIds, localUserIds, globalChatIds, globalUserIds, foundIds, globalMessagesByChatId, chatsById, fetchingStatus, lastSyncTime, - onReset, onSearchDateSelect, openChat, addRecentlyFoundChatId, searchMessagesGlobal, setGlobalSearchChatId, + onReset, onSearchDateSelect, }) => { + const { + openChat, addRecentlyFoundChatId, searchMessagesGlobal, setGlobalSearchChatId, + } = getDispatch(); + const lang = useLang(); const [shouldShowMoreLocal, setShouldShowMoreLocal] = useState(false); @@ -306,10 +305,4 @@ export default memo(withGlobal( lastSyncTime, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'openChat', - 'addRecentlyFoundChatId', - 'searchMessagesGlobal', - 'setGlobalSearchChatId', - ]), )(ChatResults)); diff --git a/src/components/left/search/FileResults.tsx b/src/components/left/search/FileResults.tsx index e77a7f5d3..ff751e63a 100644 --- a/src/components/left/search/FileResults.tsx +++ b/src/components/left/search/FileResults.tsx @@ -1,16 +1,14 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ApiMessage } from '../../../api/types'; -import { GlobalActions } from '../../../global/types'; import { LoadMoreDirection } from '../../../types'; import { SLIDE_TRANSITION_DURATION } from '../../../config'; import { MEMO_EMPTY_ARRAY } from '../../../util/memo'; import { createMapStateToProps, StateProps } from './helpers/createMapStateToProps'; -import { pick } from '../../../util/iteratees'; import { formatMonthAndYear, toYearMonth } from '../../../util/dateFormat'; import { getSenderName } from './helpers/getSenderName'; import { throttle } from '../../../util/schedulers'; @@ -27,12 +25,10 @@ export type OwnProps = { searchQuery?: string; }; -type DispatchProps = Pick; - const CURRENT_TYPE = 'documents'; const runThrottled = throttle((cb) => cb(), 500, true); -const FileResults: FC = ({ +const FileResults: FC = ({ searchQuery, searchChatId, isLoading, @@ -42,9 +38,12 @@ const FileResults: FC = ({ foundIds, activeDownloads, lastSyncTime, - searchMessagesGlobal, - focusMessage, }) => { + const { + searchMessagesGlobal, + focusMessage, + } = getDispatch(); + const lang = useLang(); const handleLoadMore = useCallback(({ direction }: { direction: LoadMoreDirection }) => { if (lastSyncTime && direction === LoadMoreDirection.Backwards) { @@ -127,8 +126,4 @@ const FileResults: FC = ({ export default memo(withGlobal( createMapStateToProps(CURRENT_TYPE), - (setGlobal, actions): DispatchProps => pick(actions, [ - 'searchMessagesGlobal', - 'focusMessage', - ]), )(FileResults)); diff --git a/src/components/left/search/LeftSearch.tsx b/src/components/left/search/LeftSearch.tsx index 155ff83a6..724dd31b7 100644 --- a/src/components/left/search/LeftSearch.tsx +++ b/src/components/left/search/LeftSearch.tsx @@ -1,12 +1,10 @@ import React, { FC, memo, useCallback, useState, useMemo, useRef, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { GlobalSearchContent } from '../../../types'; -import { pick } from '../../../util/iteratees'; import { parseDateString } from '../../../util/dateFormat'; import useKeyboardListNavigation from '../../../hooks/useKeyboardListNavigation'; import useLang from '../../../hooks/useLang'; @@ -35,8 +33,6 @@ type StateProps = { chatId?: string; }; -type DispatchProps = Pick; - const TABS = [ { type: GlobalSearchContent.ChatList, title: 'SearchAllChatsShort' }, { type: GlobalSearchContent.Media, title: 'SharedMediaTab2' }, @@ -53,16 +49,19 @@ const CHAT_TABS = [ const TRANSITION_RENDER_COUNT = Object.keys(GlobalSearchContent).length / 2; -const LeftSearch: FC = ({ +const LeftSearch: FC = ({ searchQuery, searchDate, isActive, currentContent = GlobalSearchContent.ChatList, chatId, - setGlobalSearchContent, - setGlobalSearchDate, onReset, }) => { + const { + setGlobalSearchContent, + setGlobalSearchDate, + } = getDispatch(); + const lang = useLang(); const [activeTab, setActiveTab] = useState(currentContent); const dateSearchQuery = useMemo(() => parseDateString(searchQuery), [searchQuery]); @@ -149,5 +148,4 @@ export default memo(withGlobal( return { currentContent, chatId }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['setGlobalSearchContent', 'setGlobalSearchDate']), )(LeftSearch)); diff --git a/src/components/left/search/LinkResults.tsx b/src/components/left/search/LinkResults.tsx index 258d5fcd7..189bca0c4 100644 --- a/src/components/left/search/LinkResults.tsx +++ b/src/components/left/search/LinkResults.tsx @@ -1,15 +1,13 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { LoadMoreDirection } from '../../../types'; import { SLIDE_TRANSITION_DURATION } from '../../../config'; import { MEMO_EMPTY_ARRAY } from '../../../util/memo'; import { createMapStateToProps, StateProps } from './helpers/createMapStateToProps'; -import { pick } from '../../../util/iteratees'; import { formatMonthAndYear, toYearMonth } from '../../../util/dateFormat'; import { getSenderName } from './helpers/getSenderName'; import { throttle } from '../../../util/schedulers'; @@ -25,12 +23,10 @@ export type OwnProps = { searchQuery?: string; }; -type DispatchProps = Pick; - const CURRENT_TYPE = 'links'; const runThrottled = throttle((cb) => cb(), 500, true); -const LinkResults: FC = ({ +const LinkResults: FC = ({ searchQuery, searchChatId, isLoading, @@ -39,9 +35,12 @@ const LinkResults: FC = ({ globalMessagesByChatId, foundIds, lastSyncTime, - searchMessagesGlobal, - focusMessage, }) => { + const { + searchMessagesGlobal, + focusMessage, + } = getDispatch(); + const lang = useLang(); const handleLoadMore = useCallback(({ direction }: { direction: LoadMoreDirection }) => { if (lastSyncTime && direction === LoadMoreDirection.Backwards) { @@ -122,8 +121,4 @@ const LinkResults: FC = ({ export default memo(withGlobal( createMapStateToProps(CURRENT_TYPE), - (setGlobal, actions): DispatchProps => pick(actions, [ - 'searchMessagesGlobal', - 'focusMessage', - ]), )(LinkResults)); diff --git a/src/components/left/search/MediaResults.tsx b/src/components/left/search/MediaResults.tsx index 2862ef807..97055481b 100644 --- a/src/components/left/search/MediaResults.tsx +++ b/src/components/left/search/MediaResults.tsx @@ -1,15 +1,13 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { LoadMoreDirection, MediaViewerOrigin } from '../../../types'; import { MEMO_EMPTY_ARRAY } from '../../../util/memo'; import { SLIDE_TRANSITION_DURATION } from '../../../config'; import { createMapStateToProps, StateProps } from './helpers/createMapStateToProps'; -import { pick } from '../../../util/iteratees'; import buildClassName from '../../../util/buildClassName'; import { throttle } from '../../../util/schedulers'; import useLang from '../../../hooks/useLang'; @@ -25,21 +23,22 @@ export type OwnProps = { searchQuery?: string; }; -type DispatchProps = Pick; - const CURRENT_TYPE = 'media'; const runThrottled = throttle((cb) => cb(), 500, true); -const MediaResults: FC = ({ +const MediaResults: FC = ({ searchQuery, searchChatId, isLoading, globalMessagesByChatId, foundIds, lastSyncTime, - searchMessagesGlobal, - openMediaViewer, }) => { + const { + searchMessagesGlobal, + openMediaViewer, + } = getDispatch(); + const lang = useLang(); const handleLoadMore = useCallback(({ direction }: { direction: LoadMoreDirection }) => { @@ -133,8 +132,4 @@ const MediaResults: FC = ({ export default memo(withGlobal( createMapStateToProps(CURRENT_TYPE), - (setGlobal, actions): DispatchProps => pick(actions, [ - 'searchMessagesGlobal', - 'openMediaViewer', - ]), )(MediaResults)); diff --git a/src/components/left/search/RecentContacts.tsx b/src/components/left/search/RecentContacts.tsx index 51d8bb784..f939c5577 100644 --- a/src/components/left/search/RecentContacts.tsx +++ b/src/components/left/search/RecentContacts.tsx @@ -1,15 +1,13 @@ import React, { FC, useEffect, useCallback, useRef, memo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiUser } from '../../../api/types'; import { getUserFirstOrLastName } from '../../../modules/helpers'; import renderText from '../../common/helpers/renderText'; import { throttle } from '../../../util/schedulers'; -import { pick } from '../../../util/iteratees'; import useHorizontalScroll from '../../../hooks/useHorizontalScroll'; import useLang from '../../../hooks/useLang'; @@ -29,20 +27,20 @@ type StateProps = { recentlyFoundChatIds?: string[]; }; -type DispatchProps = Pick; - const SEARCH_CLOSE_TIMEOUT_MS = 250; const NBSP = '\u00A0'; const runThrottled = throttle((cb) => cb(), 60000, true); -const RecentContacts: FC = ({ +const RecentContacts: FC = ({ topUserIds, usersById, recentlyFoundChatIds, - onReset, loadTopUsers, loadContactList, openChat, - addRecentlyFoundChatId, clearRecentlyFoundChats, + onReset, }) => { + const { + loadTopUsers, loadContactList, openChat, + addRecentlyFoundChatId, clearRecentlyFoundChats, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const topUsersRef = useRef(null); @@ -122,11 +120,4 @@ export default memo(withGlobal( recentlyFoundChatIds, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadTopUsers', - 'loadContactList', - 'openChat', - 'addRecentlyFoundChatId', - 'clearRecentlyFoundChats', - ]), )(RecentContacts)); diff --git a/src/components/left/settings/BlockUserModal.tsx b/src/components/left/settings/BlockUserModal.tsx index 77312535c..62117e6cd 100644 --- a/src/components/left/settings/BlockUserModal.tsx +++ b/src/components/left/settings/BlockUserModal.tsx @@ -1,13 +1,12 @@ import React, { FC, useMemo, useState, memo, useRef, useCallback, useEffect, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiUser } from '../../../api/types'; import { filterUsersByName, getUserFullName } from '../../../modules/helpers'; -import { pick, unique } from '../../../util/iteratees'; +import { unique } from '../../../util/iteratees'; import useLang from '../../../hooks/useLang'; import ChatOrUserPicker from '../../common/ChatOrUserPicker'; @@ -25,9 +24,7 @@ type StateProps = { currentUserId?: string; }; -type DispatchProps = Pick; - -const BlockUserModal: FC = ({ +const BlockUserModal: FC = ({ usersById, blockedIds, contactIds, @@ -35,10 +32,13 @@ const BlockUserModal: FC = ({ currentUserId, isOpen, onClose, - loadContactList, - setUserSearchQuery, - blockContact, }) => { + const { + loadContactList, + setUserSearchQuery, + blockContact, + } = getDispatch(); + const lang = useLang(); const [filter, setFilter] = useState(''); // eslint-disable-next-line no-null/no-null @@ -110,7 +110,4 @@ export default memo(withGlobal( currentUserId, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadContactList', 'setUserSearchQuery', 'blockContact', - ]), )(BlockUserModal)); diff --git a/src/components/left/settings/SettingsDataStorage.tsx b/src/components/left/settings/SettingsDataStorage.tsx index d03d8f18c..a2e1f4765 100644 --- a/src/components/left/settings/SettingsDataStorage.tsx +++ b/src/components/left/settings/SettingsDataStorage.tsx @@ -1,7 +1,6 @@ import React, { FC, memo, useCallback } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { SettingsScreens, ISettings } from '../../../types'; import { AUTODOWNLOAD_FILESIZE_MB_LIMITS } from '../../../config'; @@ -36,11 +35,7 @@ type StateProps = Pick; -type DispatchProps = Pick; - -const SettingsDataStorage: FC = ({ +const SettingsDataStorage: FC = ({ isActive, onScreenSelect, onReset, @@ -59,8 +54,9 @@ const SettingsDataStorage: FC = ({ canAutoPlayGifs, canAutoPlayVideos, autoLoadFileMaxSizeMb, - setSettingOption, }) => { + const { setSettingOption } = getDispatch(); + const lang = useLang(); useHistoryBack(isActive, onReset, onScreenSelect, SettingsScreens.General); @@ -193,7 +189,4 @@ export default memo(withGlobal( 'autoLoadFileMaxSizeMb', ]); }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'setSettingOption', - ]), )(SettingsDataStorage)); diff --git a/src/components/left/settings/SettingsEditProfile.tsx b/src/components/left/settings/SettingsEditProfile.tsx index d253aec6c..3622906cc 100644 --- a/src/components/left/settings/SettingsEditProfile.tsx +++ b/src/components/left/settings/SettingsEditProfile.tsx @@ -2,14 +2,12 @@ import { ChangeEvent } from 'react'; import React, { FC, useState, useCallback, memo, useEffect, useMemo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ApiMediaFormat } from '../../../api/types'; -import { GlobalActions } from '../../../global/types'; import { ProfileEditProgress, SettingsScreens } from '../../../types'; import { throttle } from '../../../util/schedulers'; -import { pick } from '../../../util/iteratees'; import { selectUser } from '../../../modules/selectors'; import { getChatAvatarHash } from '../../../modules/helpers'; import useMedia from '../../../hooks/useMedia'; @@ -39,10 +37,6 @@ type StateProps = { isUsernameAvailable?: boolean; }; -type DispatchProps = Pick; - const runThrottled = throttle((cb) => cb(), 60000, true); const MAX_BIO_LENGTH = 70; @@ -50,7 +44,7 @@ const MAX_BIO_LENGTH = 70; const ERROR_FIRST_NAME_MISSING = 'Please provide your first name'; const ERROR_BIO_TOO_LONG = 'Bio can\' be longer than 70 characters'; -const SettingsEditProfile: FC = ({ +const SettingsEditProfile: FC = ({ isActive, onScreenSelect, onReset, @@ -61,10 +55,13 @@ const SettingsEditProfile: FC = ({ currentUsername, progress, isUsernameAvailable, - loadCurrentUser, - updateProfile, - checkUsername, }) => { + const { + loadCurrentUser, + updateProfile, + checkUsername, + } = getDispatch(); + const lang = useLang(); const [isUsernameTouched, setIsUsernameTouched] = useState(false); @@ -286,9 +283,4 @@ export default memo(withGlobal( isUsernameAvailable, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadCurrentUser', - 'updateProfile', - 'checkUsername', - ]), )(SettingsEditProfile)); diff --git a/src/components/left/settings/SettingsGeneral.tsx b/src/components/left/settings/SettingsGeneral.tsx index 7eae1c80c..3208b3555 100644 --- a/src/components/left/settings/SettingsGeneral.tsx +++ b/src/components/left/settings/SettingsGeneral.tsx @@ -1,9 +1,8 @@ import React, { FC, useCallback, memo, useEffect, useRef, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { SettingsScreens, ISettings, TimeFormat } from '../../../types'; import { ApiSticker, ApiStickerSet } from '../../../api/types'; @@ -28,21 +27,18 @@ type OwnProps = { onReset: () => void; }; -type StateProps = Pick & { - stickerSetIds?: string[]; - stickerSetsById?: Record; -}; - -type DispatchProps = Pick; +type StateProps = + Pick & { + stickerSetIds?: string[]; + stickerSetsById?: Record; + }; const ANIMATION_LEVEL_OPTIONS = [ 'Solid and Steady', @@ -58,7 +54,7 @@ const TIME_FORMAT_OPTIONS: IRadioOption[] = [{ value: '24h', }]; -const SettingsGeneral: FC = ({ +const SettingsGeneral: FC = ({ isActive, onScreenSelect, onReset, @@ -70,10 +66,13 @@ const SettingsGeneral: FC = ({ shouldSuggestStickers, shouldLoopStickers, timeFormat, - setSettingOption, - loadStickerSets, - loadAddedStickers, }) => { + const { + setSettingOption, + loadStickerSets, + loadAddedStickers, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const stickerSettingsRef = useRef(null); const { observe: observeIntersectionForCovers } = useIntersectionObserver({ rootRef: stickerSettingsRef }); @@ -252,7 +251,4 @@ export default memo(withGlobal( stickerSetsById: global.stickers.setsById, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'setSettingOption', 'loadStickerSets', 'loadAddedStickers', - ]), )(SettingsGeneral)); diff --git a/src/components/left/settings/SettingsGeneralBackground.tsx b/src/components/left/settings/SettingsGeneralBackground.tsx index 85d252384..d0b949b75 100644 --- a/src/components/left/settings/SettingsGeneralBackground.tsx +++ b/src/components/left/settings/SettingsGeneralBackground.tsx @@ -1,14 +1,12 @@ import React, { FC, memo, useEffect, useCallback, useRef, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { SettingsScreens, ThemeKey, UPLOADING_WALLPAPER_SLUG } from '../../../types'; import { ApiWallpaper } from '../../../api/types'; import { DARK_THEME_PATTERN_COLOR, DEFAULT_PATTERN_COLOR } from '../../../config'; -import { pick } from '../../../util/iteratees'; import { throttle } from '../../../util/schedulers'; import { openSystemFilesDialog } from '../../../util/systemFilesDialog'; import { getAverageColor, getPatternColor, rgb2hex } from '../../../util/colors'; @@ -36,15 +34,11 @@ type StateProps = { theme: ThemeKey; }; -type DispatchProps = Pick; - const SUPPORTED_TYPES = 'image/jpeg'; const runThrottled = throttle((cb) => cb(), 60000, true); -const SettingsGeneralBackground: FC = ({ +const SettingsGeneralBackground: FC = ({ isActive, onScreenSelect, onReset, @@ -52,10 +46,13 @@ const SettingsGeneralBackground: FC = ({ isBlurred, loadedWallpapers, theme, - loadWallpapers, - uploadWallpaper, - setThemeSettings, }) => { + const { + loadWallpapers, + uploadWallpaper, + setThemeSettings, + } = getDispatch(); + const themeRef = useRef(); themeRef.current = theme; // Due to the parent Transition, this component never gets unmounted, @@ -177,7 +174,4 @@ export default memo(withGlobal( theme, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadWallpapers', 'uploadWallpaper', 'setThemeSettings', - ]), )(SettingsGeneralBackground)); diff --git a/src/components/left/settings/SettingsGeneralBackgroundColor.tsx b/src/components/left/settings/SettingsGeneralBackgroundColor.tsx index 0add05840..8e9f90da5 100644 --- a/src/components/left/settings/SettingsGeneralBackgroundColor.tsx +++ b/src/components/left/settings/SettingsGeneralBackgroundColor.tsx @@ -2,9 +2,8 @@ import { ChangeEvent, MutableRefObject, RefObject } from 'react'; import React, { FC, memo, useCallback, useEffect, useRef, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { SettingsScreens, ThemeKey } from '../../../types'; import { pick } from '../../../util/iteratees'; @@ -32,8 +31,6 @@ type StateProps = { theme: ThemeKey; }; -type DispatchProps = Pick; - interface CanvasRects { colorRect: { offsetLeft: number; @@ -53,14 +50,15 @@ const PREDEFINED_COLORS = [ '#ccd0af', '#a6a997', '#7a7072', '#fdd7af', '#fdb76e', '#dd8851', ]; -const SettingsGeneralBackground: FC = ({ +const SettingsGeneralBackground: FC = ({ isActive, onScreenSelect, onReset, theme, backgroundColor, - setThemeSettings, }) => { + const { setThemeSettings } = getDispatch(); + const themeRef = useRef(); themeRef.current = theme; // eslint-disable-next-line no-null/no-null @@ -358,5 +356,4 @@ export default memo(withGlobal( theme, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['setThemeSettings']), )(SettingsGeneralBackground)); diff --git a/src/components/left/settings/SettingsHeader.tsx b/src/components/left/settings/SettingsHeader.tsx index 7bf993411..fbcc028ba 100644 --- a/src/components/left/settings/SettingsHeader.tsx +++ b/src/components/left/settings/SettingsHeader.tsx @@ -1,13 +1,11 @@ import React, { FC, memo, useCallback, useMemo, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { SettingsScreens } from '../../../types'; import { IS_SINGLE_COLUMN_LAYOUT } from '../../../util/environment'; -import { pick } from '../../../util/iteratees'; import useLang from '../../../hooks/useLang'; import DropdownMenu from '../../ui/DropdownMenu'; @@ -23,17 +21,18 @@ type OwnProps = { onScreenSelect: (screen: SettingsScreens) => void; }; -type DispatchProps = Pick; - -const SettingsHeader: FC = ({ +const SettingsHeader: FC = ({ currentScreen, editedFolderId, onReset, onSaveFilter, - signOut, - deleteChatFolder, onScreenSelect, }) => { + const { + signOut, + deleteChatFolder, + } = getDispatch(); + const [isSignOutDialogOpen, setIsSignOutDialogOpen] = useState(false); const [isDeleteFolderDialogOpen, setIsDeleteFolderDialogOpen] = useState(false); @@ -263,7 +262,4 @@ const SettingsHeader: FC = ({ ); }; -export default memo(withGlobal( - undefined, - (setGlobal, actions): DispatchProps => pick(actions, ['signOut', 'deleteChatFolder']), -)(SettingsHeader)); +export default memo(SettingsHeader); diff --git a/src/components/left/settings/SettingsLanguage.tsx b/src/components/left/settings/SettingsLanguage.tsx index 9ab4a682b..c9923c09b 100644 --- a/src/components/left/settings/SettingsLanguage.tsx +++ b/src/components/left/settings/SettingsLanguage.tsx @@ -1,14 +1,12 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ISettings, LangCode, SettingsScreens } from '../../../types'; import { ApiLanguage } from '../../../api/types'; import { setLanguage } from '../../../util/langProvider'; -import { pick } from '../../../util/iteratees'; import RadioGroup from '../../ui/RadioGroup'; import Loading from '../../ui/Loading'; @@ -23,17 +21,18 @@ type OwnProps = { type StateProps = Pick; -type DispatchProps = Pick; - -const SettingsLanguage: FC = ({ +const SettingsLanguage: FC = ({ isActive, onScreenSelect, onReset, languages, language, - loadLanguages, - setSettingOption, }) => { + const { + loadLanguages, + setSettingOption, + } = getDispatch(); + const [selectedLanguage, setSelectedLanguage] = useState(language); const [isLoading, markIsLoading, unmarkIsLoading] = useFlag(); @@ -96,7 +95,4 @@ export default memo(withGlobal( language: global.settings.byKey.language, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadLanguages', 'setSettingOption', - ]), )(SettingsLanguage)); diff --git a/src/components/left/settings/SettingsMain.tsx b/src/components/left/settings/SettingsMain.tsx index 89bb04782..53b1e2ad9 100644 --- a/src/components/left/settings/SettingsMain.tsx +++ b/src/components/left/settings/SettingsMain.tsx @@ -1,12 +1,10 @@ import React, { FC, memo, useEffect } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { SettingsScreens } from '../../../types'; import { ApiUser } from '../../../api/types'; import { selectUser } from '../../../modules/selectors'; -import { pick } from '../../../util/iteratees'; import useLang from '../../../hooks/useLang'; import useHistoryBack from '../../../hooks/useHistoryBack'; @@ -25,16 +23,15 @@ type StateProps = { lastSyncTime?: number; }; -type DispatchProps = Pick; - -const SettingsMain: FC = ({ +const SettingsMain: FC = ({ isActive, onScreenSelect, onReset, - loadProfilePhotos, currentUser, lastSyncTime, }) => { + const { loadProfilePhotos } = getDispatch(); + const lang = useLang(); const profileId = currentUser?.id; @@ -111,5 +108,4 @@ export default memo(withGlobal( lastSyncTime, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadProfilePhotos']), )(SettingsMain)); diff --git a/src/components/left/settings/SettingsNotifications.tsx b/src/components/left/settings/SettingsNotifications.tsx index fc0635946..3eade46bf 100644 --- a/src/components/left/settings/SettingsNotifications.tsx +++ b/src/components/left/settings/SettingsNotifications.tsx @@ -3,12 +3,10 @@ import useDebounce from '../../../hooks/useDebounce'; import React, { FC, memo, useCallback, useEffect, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { SettingsScreens } from '../../../types'; -import { pick } from '../../../util/iteratees'; import useLang from '../../../hooks/useLang'; import useHistoryBack from '../../../hooks/useHistoryBack'; import { playNotifySound } from '../../../util/notifications'; @@ -35,12 +33,7 @@ type StateProps = { notificationSoundVolume: number; }; -type DispatchProps = Pick; - -const SettingsNotifications: FC = ({ +const SettingsNotifications: FC = ({ isActive, onScreenSelect, onReset, @@ -54,11 +47,14 @@ const SettingsNotifications: FC = ({ hasPushNotifications, hasWebNotifications, notificationSoundVolume, - loadNotificationSettings, - updateContactSignUpNotification, - updateNotificationSettings, - updateWebNotificationSettings, }) => { + const { + loadNotificationSettings, + updateContactSignUpNotification, + updateNotificationSettings, + updateWebNotificationSettings, + } = getDispatch(); + useEffect(() => { loadNotificationSettings(); }, [loadNotificationSettings]); @@ -147,7 +143,9 @@ const SettingsNotifications: FC = ({ // eslint-disable-next-line max-len subLabel={lang(hasPrivateChatsNotifications ? 'UserInfo.NotificationsEnabled' : 'UserInfo.NotificationsDisabled')} checked={hasPrivateChatsNotifications} - onChange={(e) => { handleSettingsChange(e, 'contact', 'silent'); }} + onChange={(e) => { + handleSettingsChange(e, 'contact', 'silent'); + }} /> = ({ // eslint-disable-next-line max-len subLabel={lang(hasPrivateChatsMessagePreview ? 'UserInfo.NotificationsEnabled' : 'UserInfo.NotificationsDisabled')} checked={hasPrivateChatsMessagePreview} - onChange={(e) => { handleSettingsChange(e, 'contact', 'showPreviews'); }} + onChange={(e) => { + handleSettingsChange(e, 'contact', 'showPreviews'); + }} /> @@ -166,14 +166,18 @@ const SettingsNotifications: FC = ({ label={lang('NotificationsForGroups')} subLabel={lang(hasGroupNotifications ? 'UserInfo.NotificationsEnabled' : 'UserInfo.NotificationsDisabled')} checked={hasGroupNotifications} - onChange={(e) => { handleSettingsChange(e, 'group', 'silent'); }} + onChange={(e) => { + handleSettingsChange(e, 'group', 'silent'); + }} /> { handleSettingsChange(e, 'group', 'showPreviews'); }} + onChange={(e) => { + handleSettingsChange(e, 'group', 'showPreviews'); + }} /> @@ -185,7 +189,9 @@ const SettingsNotifications: FC = ({ // eslint-disable-next-line max-len subLabel={lang(hasBroadcastNotifications ? 'UserInfo.NotificationsEnabled' : 'UserInfo.NotificationsDisabled')} checked={hasBroadcastNotifications} - onChange={(e) => { handleSettingsChange(e, 'broadcast', 'silent'); }} + onChange={(e) => { + handleSettingsChange(e, 'broadcast', 'silent'); + }} /> = ({ // eslint-disable-next-line max-len subLabel={lang(hasBroadcastMessagePreview ? 'UserInfo.NotificationsEnabled' : 'UserInfo.NotificationsDisabled')} checked={hasBroadcastMessagePreview} - onChange={(e) => { handleSettingsChange(e, 'broadcast', 'showPreviews'); }} + onChange={(e) => { + handleSettingsChange(e, 'broadcast', 'showPreviews'); + }} /> @@ -210,23 +218,19 @@ const SettingsNotifications: FC = ({ ); }; -export default memo(withGlobal((global): StateProps => { - return { - hasPrivateChatsNotifications: Boolean(global.settings.byKey.hasPrivateChatsNotifications), - hasPrivateChatsMessagePreview: Boolean(global.settings.byKey.hasPrivateChatsMessagePreview), - hasGroupNotifications: Boolean(global.settings.byKey.hasGroupNotifications), - hasGroupMessagePreview: Boolean(global.settings.byKey.hasGroupMessagePreview), - hasBroadcastNotifications: Boolean(global.settings.byKey.hasBroadcastNotifications), - hasBroadcastMessagePreview: Boolean(global.settings.byKey.hasBroadcastMessagePreview), - hasContactJoinedNotifications: Boolean(global.settings.byKey.hasContactJoinedNotifications), - hasWebNotifications: global.settings.byKey.hasWebNotifications, - hasPushNotifications: global.settings.byKey.hasPushNotifications, - notificationSoundVolume: global.settings.byKey.notificationSoundVolume, - }; -}, -(setGlobal, actions): DispatchProps => pick(actions, [ - 'loadNotificationSettings', - 'updateContactSignUpNotification', - 'updateNotificationSettings', - 'updateWebNotificationSettings', -]))(SettingsNotifications)); +export default memo(withGlobal( + (global): StateProps => { + return { + hasPrivateChatsNotifications: Boolean(global.settings.byKey.hasPrivateChatsNotifications), + hasPrivateChatsMessagePreview: Boolean(global.settings.byKey.hasPrivateChatsMessagePreview), + hasGroupNotifications: Boolean(global.settings.byKey.hasGroupNotifications), + hasGroupMessagePreview: Boolean(global.settings.byKey.hasGroupMessagePreview), + hasBroadcastNotifications: Boolean(global.settings.byKey.hasBroadcastNotifications), + hasBroadcastMessagePreview: Boolean(global.settings.byKey.hasBroadcastMessagePreview), + hasContactJoinedNotifications: Boolean(global.settings.byKey.hasContactJoinedNotifications), + hasWebNotifications: global.settings.byKey.hasWebNotifications, + hasPushNotifications: global.settings.byKey.hasPushNotifications, + notificationSoundVolume: global.settings.byKey.notificationSoundVolume, + }; + }, +)(SettingsNotifications)); diff --git a/src/components/left/settings/SettingsPrivacy.tsx b/src/components/left/settings/SettingsPrivacy.tsx index d3a77f760..633b98a81 100644 --- a/src/components/left/settings/SettingsPrivacy.tsx +++ b/src/components/left/settings/SettingsPrivacy.tsx @@ -1,10 +1,8 @@ import React, { FC, memo, useEffect } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { PrivacyVisibility, SettingsScreens } from '../../../types'; -import { pick } from '../../../util/iteratees'; import useLang from '../../../hooks/useLang'; import useHistoryBack from '../../../hooks/useHistoryBack'; @@ -30,11 +28,7 @@ type StateProps = { visibilityPrivacyGroupChats?: PrivacyVisibility; }; -type DispatchProps = Pick; - -const SettingsPrivacy: FC = ({ +const SettingsPrivacy: FC = ({ isActive, onScreenSelect, onReset, @@ -48,12 +42,16 @@ const SettingsPrivacy: FC = ({ visibilityPrivacyProfilePhoto, visibilityPrivacyForwarding, visibilityPrivacyGroupChats, - loadPrivacySettings, - loadBlockedContacts, - loadAuthorizations, - loadContentSettings, - updateContentSettings, + }) => { + const { + loadPrivacySettings, + loadBlockedContacts, + loadAuthorizations, + loadContentSettings, + updateContentSettings, + } = getDispatch(); + useEffect(() => { loadBlockedContacts(); loadAuthorizations(); @@ -234,7 +232,4 @@ export default memo(withGlobal( visibilityPrivacyGroupChats: privacy.chatInvite?.visibility, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadBlockedContacts', 'loadAuthorizations', 'loadPrivacySettings', 'loadContentSettings', 'updateContentSettings', - ]), )(SettingsPrivacy)); diff --git a/src/components/left/settings/SettingsPrivacyActiveSessions.tsx b/src/components/left/settings/SettingsPrivacyActiveSessions.tsx index c2ad06448..dfcb6c7a4 100644 --- a/src/components/left/settings/SettingsPrivacyActiveSessions.tsx +++ b/src/components/left/settings/SettingsPrivacyActiveSessions.tsx @@ -1,13 +1,11 @@ import React, { FC, memo, useCallback, useEffect, useMemo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiSession } from '../../../api/types'; import { SettingsScreens } from '../../../types'; -import { pick } from '../../../util/iteratees'; import { formatPastTimeShort } from '../../../util/dateFormat'; import useFlag from '../../../hooks/useFlag'; import useLang from '../../../hooks/useLang'; @@ -26,19 +24,18 @@ type StateProps = { activeSessions: ApiSession[]; }; -type DispatchProps = Pick; - -const SettingsPrivacyActiveSessions: FC = ({ +const SettingsPrivacyActiveSessions: FC = ({ isActive, onScreenSelect, onReset, activeSessions, - loadAuthorizations, - terminateAuthorization, - terminateAllAuthorizations, }) => { + const { + loadAuthorizations, + terminateAuthorization, + terminateAllAuthorizations, + } = getDispatch(); + const [isConfirmTerminateAllDialogOpen, openConfirmTerminateAllDialog, closeConfirmTerminateAllDialog] = useFlag(); useEffect(() => { loadAuthorizations(); @@ -162,7 +159,4 @@ export default memo(withGlobal( activeSessions: global.activeSessions, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadAuthorizations', 'terminateAuthorization', 'terminateAllAuthorizations', - ]), )(SettingsPrivacyActiveSessions)); diff --git a/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx b/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx index 22138f354..644986a48 100644 --- a/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx +++ b/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx @@ -1,15 +1,13 @@ import React, { FC, memo, useCallback, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiChat, ApiCountryCode, ApiUser } from '../../../api/types'; import { SettingsScreens } from '../../../types'; import { CHAT_HEIGHT_PX } from '../../../config'; import { formatPhoneNumberWithCode } from '../../../util/phoneNumber'; -import { pick } from '../../../util/iteratees'; import { getChatTitle, getUserFullName, isUserId, } from '../../../modules/helpers'; @@ -38,9 +36,7 @@ type StateProps = { phoneCodeList: ApiCountryCode[]; }; -type DispatchProps = Pick; - -const SettingsPrivacyBlockedUsers: FC = ({ +const SettingsPrivacyBlockedUsers: FC = ({ isActive, onScreenSelect, onReset, @@ -48,8 +44,9 @@ const SettingsPrivacyBlockedUsers: FC = ( usersByIds, blockedIds, phoneCodeList, - unblockContact, }) => { + const { unblockContact } = getDispatch(); + const lang = useLang(); const [isBlockUserModalOpen, openBlockUserModal, closeBlockUserModal] = useFlag(); const handleUnblockClick = useCallback((contactId: string) => { @@ -158,5 +155,4 @@ export default memo(withGlobal( phoneCodeList, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['unblockContact']), )(SettingsPrivacyBlockedUsers)); diff --git a/src/components/left/settings/SettingsPrivacyVisibility.tsx b/src/components/left/settings/SettingsPrivacyVisibility.tsx index 162f3d312..e3f675996 100644 --- a/src/components/left/settings/SettingsPrivacyVisibility.tsx +++ b/src/components/left/settings/SettingsPrivacyVisibility.tsx @@ -1,14 +1,12 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiChat, ApiUser } from '../../../api/types'; import { ApiPrivacySettings, SettingsScreens } from '../../../types'; import useLang from '../../../hooks/useLang'; -import { pick } from '../../../util/iteratees'; import useHistoryBack from '../../../hooks/useHistoryBack'; import ListItem from '../../ui/ListItem'; @@ -22,14 +20,13 @@ type OwnProps = { onReset: () => void; }; -type StateProps = Partial & { - chatsById?: Record; - usersById?: Record; -}; +type StateProps = + Partial & { + chatsById?: Record; + usersById?: Record; + }; -type DispatchProps = Pick; - -const SettingsPrivacyVisibility: FC = ({ +const SettingsPrivacyVisibility: FC = ({ screen, isActive, onScreenSelect, @@ -40,8 +37,9 @@ const SettingsPrivacyVisibility: FC = ({ blockUserIds, blockChatIds, chatsById, - setPrivacyVisibility, }) => { + const { setPrivacyVisibility } = getDispatch(); + const lang = useLang(); const visibilityOptions = useMemo(() => { @@ -178,7 +176,9 @@ const SettingsPrivacyVisibility: FC = ({ { onScreenSelect(allowedContactsScreen); }} + onClick={() => { + onScreenSelect(allowedContactsScreen); + }} >
{allowedCount > 0 && +{allowedCount}} @@ -191,7 +191,9 @@ const SettingsPrivacyVisibility: FC = ({ { onScreenSelect(deniedContactsScreen); }} + onClick={() => { + onScreenSelect(deniedContactsScreen); + }} >
{blockCount > 0 && −{blockCount}} @@ -245,5 +247,4 @@ export default memo(withGlobal( chatsById, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['setPrivacyVisibility']), )(SettingsPrivacyVisibility)); diff --git a/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx b/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx index bae3cafc5..974ed4a15 100644 --- a/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx +++ b/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx @@ -1,14 +1,13 @@ import React, { FC, memo, useCallback, useMemo, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions, GlobalState } from '../../../global/types'; +import { GlobalState } from '../../../global/types'; import { ApiChat } from '../../../api/types'; import { ApiPrivacySettings, SettingsScreens } from '../../../types'; import useLang from '../../../hooks/useLang'; -import { pick } from '../../../util/iteratees'; import searchWords from '../../../util/searchWords'; import { getPrivacyKey } from './helper/privacy'; import { @@ -37,9 +36,7 @@ type StateProps = { settings?: ApiPrivacySettings; }; -type DispatchProps = Pick; - -const SettingsPrivacyVisibilityExceptionList: FC = ({ +const SettingsPrivacyVisibilityExceptionList: FC = ({ currentUserId, isAllowList, screen, @@ -49,11 +46,12 @@ const SettingsPrivacyVisibilityExceptionList: FC { + const { setPrivacySettings } = getDispatch(); + const lang = useLang(); const selectedContactIds = useMemo(() => { @@ -105,8 +103,8 @@ const SettingsPrivacyVisibilityExceptionList: FC id); @@ -196,5 +194,4 @@ export default memo(withGlobal( settings: getCurrentPrivacySettings(global, screen), }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['setPrivacySettings']), )(SettingsPrivacyVisibilityExceptionList)); diff --git a/src/components/left/settings/folders/SettingsFoldersChatFilters.tsx b/src/components/left/settings/folders/SettingsFoldersChatFilters.tsx index addc9a7b1..3585614d0 100644 --- a/src/components/left/settings/folders/SettingsFoldersChatFilters.tsx +++ b/src/components/left/settings/folders/SettingsFoldersChatFilters.tsx @@ -1,14 +1,12 @@ import React, { FC, memo, useMemo, useCallback, } from '../../../../lib/teact/teact'; -import { withGlobal } from '../../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../../lib/teact/teactn'; -import { GlobalActions } from '../../../../global/types'; import { ApiChat } from '../../../../api/types'; import { SettingsScreens } from '../../../../types'; import useLang from '../../../../hooks/useLang'; -import { pick } from '../../../../util/iteratees'; import searchWords from '../../../../util/searchWords'; import { prepareChatList, getChatTitle } from '../../../../modules/helpers'; import { @@ -39,9 +37,7 @@ type StateProps = { archivedPinnedIds?: string[]; }; -type DispatchProps = Pick; - -const SettingsFoldersChatFilters: FC = ({ +const SettingsFoldersChatFilters: FC = ({ isActive, onScreenSelect, onReset, @@ -53,8 +49,9 @@ const SettingsFoldersChatFilters: FC = ({ orderedPinnedIds, archivedListIds, archivedPinnedIds, - loadMoreChats, }) => { + const { loadMoreChats } = getDispatch(); + const { chatFilter } = state; const { selectedChatIds, selectedChatTypes } = selectChatFilters(state, mode, true); @@ -180,5 +177,4 @@ export default memo(withGlobal( archivedListIds: listIds.archived, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadMoreChats']), )(SettingsFoldersChatFilters)); diff --git a/src/components/left/settings/folders/SettingsFoldersEdit.tsx b/src/components/left/settings/folders/SettingsFoldersEdit.tsx index f7acde910..c87ca4546 100644 --- a/src/components/left/settings/folders/SettingsFoldersEdit.tsx +++ b/src/components/left/settings/folders/SettingsFoldersEdit.tsx @@ -1,13 +1,12 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../../lib/teact/teact'; -import { withGlobal } from '../../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../../lib/teact/teactn'; -import { GlobalActions } from '../../../../global/types'; import { SettingsScreens } from '../../../../types'; import { STICKER_SIZE_FOLDER_SETTINGS } from '../../../../config'; -import { findIntersectionWithSet, pick } from '../../../../util/iteratees'; +import { findIntersectionWithSet } from '../../../../util/iteratees'; import { isUserId } from '../../../../modules/helpers'; import getAnimationData from '../../../common/helpers/animatedAssets'; import { @@ -45,8 +44,6 @@ type StateProps = { loadedArchivedChatIds?: string[]; }; -type DispatchProps = Pick; - const SUBMIT_TIMEOUT = 500; const INITIAL_CHATS_LIMIT = 5; @@ -54,7 +51,7 @@ const INITIAL_CHATS_LIMIT = 5; const ERROR_NO_TITLE = 'Please provide a title for this folder.'; const ERROR_NO_CHATS = 'ChatList.Filter.Error.Empty'; -const SettingsFoldersEdit: FC = ({ +const SettingsFoldersEdit: FC = ({ state, dispatch, onAddIncludedChats, @@ -65,10 +62,13 @@ const SettingsFoldersEdit: FC = ({ onBack, loadedActiveChatIds, loadedArchivedChatIds, - editChatFolder, - addChatFolder, - loadMoreChats, }) => { + const { + editChatFolder, + addChatFolder, + loadMoreChats, + } = getDispatch(); + const [animationData, setAnimationData] = useState>(); const [isAnimationLoaded, setIsAnimationLoaded] = useState(false); const handleAnimationLoad = useCallback(() => setIsAnimationLoaded(true), []); @@ -322,5 +322,4 @@ export default memo(withGlobal( loadedArchivedChatIds: listIds.archived, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['editChatFolder', 'addChatFolder', 'loadMoreChats']), )(SettingsFoldersEdit)); diff --git a/src/components/left/settings/folders/SettingsFoldersMain.tsx b/src/components/left/settings/folders/SettingsFoldersMain.tsx index 5562d26f6..18b49d1aa 100644 --- a/src/components/left/settings/folders/SettingsFoldersMain.tsx +++ b/src/components/left/settings/folders/SettingsFoldersMain.tsx @@ -1,14 +1,13 @@ import React, { FC, memo, useMemo, useCallback, useState, useEffect, } from '../../../../lib/teact/teact'; -import { withGlobal } from '../../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../../lib/teact/teactn'; -import { GlobalActions, GlobalState } from '../../../../global/types'; +import { GlobalState } from '../../../../global/types'; import { ApiChatFolder, ApiChat, ApiUser } from '../../../../api/types'; import { NotifyException, NotifySettings, SettingsScreens } from '../../../../types'; import { STICKER_SIZE_FOLDER_SETTINGS } from '../../../../config'; -import { pick } from '../../../../util/iteratees'; import { selectNotifyExceptions, selectNotifySettings } from '../../../../modules/selectors'; import { throttle } from '../../../../util/schedulers'; import getAnimationData from '../../../common/helpers/animatedAssets'; @@ -40,13 +39,11 @@ type StateProps = { notifyExceptions?: Record; }; -type DispatchProps = Pick; - const runThrottledForLoadRecommended = throttle((cb) => cb(), 60000, true); const MAX_ALLOWED_FOLDERS = 10; -const SettingsFoldersMain: FC = ({ +const SettingsFoldersMain: FC = ({ isActive, allListIds, chatsById, @@ -60,10 +57,13 @@ const SettingsFoldersMain: FC = ({ onEditFolder, onScreenSelect, onReset, - loadRecommendedChatFolders, - addChatFolder, - showDialog, }) => { + const { + loadRecommendedChatFolders, + addChatFolder, + showDialog, + } = getDispatch(); + const [animationData, setAnimationData] = useState>(); const [isAnimationLoaded, setIsAnimationLoaded] = useState(false); const handleAnimationLoad = useCallback(() => setIsAnimationLoaded(true), []); @@ -250,5 +250,4 @@ export default memo(withGlobal( notifyExceptions: selectNotifyExceptions(global), }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadRecommendedChatFolders', 'addChatFolder', 'showDialog']), )(SettingsFoldersMain)); diff --git a/src/components/left/settings/twoFa/SettingsTwoFa.tsx b/src/components/left/settings/twoFa/SettingsTwoFa.tsx index 7b5d8c232..f7b7491b8 100644 --- a/src/components/left/settings/twoFa/SettingsTwoFa.tsx +++ b/src/components/left/settings/twoFa/SettingsTwoFa.tsx @@ -1,12 +1,11 @@ import React, { FC, memo, useCallback, useEffect, } from '../../../../lib/teact/teact'; -import { withGlobal } from '../../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../../lib/teact/teactn'; -import { GlobalActions, GlobalState } from '../../../../global/types'; +import { GlobalState } from '../../../../global/types'; import { SettingsScreens } from '../../../../types'; -import { pick } from '../../../../util/iteratees'; import { TwoFaDispatch, TwoFaState } from '../../../../hooks/reducers/useTwoFaReducer'; import useLang from '../../../../hooks/useLang'; @@ -29,12 +28,7 @@ export type OwnProps = { type StateProps = GlobalState['twoFaSettings']; -type DispatchProps = Pick; - -const SettingsTwoFa: FC = ({ +const SettingsTwoFa: FC = ({ currentScreen, shownScreen, state, @@ -46,13 +40,16 @@ const SettingsTwoFa: FC = ({ isActive, onScreenSelect, onReset, - updatePassword, - checkPassword, - clearTwoFaError, - updateRecoveryEmail, - provideTwoFaEmailCode, - clearPassword, }) => { + const { + updatePassword, + checkPassword, + clearTwoFaError, + updateRecoveryEmail, + provideTwoFaEmailCode, + clearPassword, + } = getDispatch(); + useEffect(() => { if (waitingEmailCodeLength) { if (currentScreen === SettingsScreens.TwoFaNewPasswordEmail) { @@ -435,8 +432,4 @@ const SettingsTwoFa: FC = ({ export default memo(withGlobal( (global): StateProps => ({ ...global.twoFaSettings }), - (setGlobal, actions): DispatchProps => pick(actions, [ - 'updatePassword', 'updateRecoveryEmail', 'clearPassword', 'provideTwoFaEmailCode', - 'checkPassword', 'clearTwoFaError', - ]), )(SettingsTwoFa)); diff --git a/src/components/main/Dialogs.tsx b/src/components/main/Dialogs.tsx index 80ff54c5d..90f9d8c3c 100644 --- a/src/components/main/Dialogs.tsx +++ b/src/components/main/Dialogs.tsx @@ -1,7 +1,6 @@ import React, { FC, memo } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiError, ApiInviteInfo } from '../../api/types'; import getReadableErrorText from '../../util/getReadableErrorText'; @@ -18,9 +17,9 @@ type StateProps = { dialogs: (ApiError | ApiInviteInfo)[]; }; -type DispatchProps = Pick; +const Dialogs: FC = ({ dialogs }) => { + const { dismissDialog, acceptInviteConfirmation } = getDispatch(); -const Dialogs: FC = ({ dialogs, dismissDialog, acceptInviteConfirmation }) => { const lang = useLang(); if (!dialogs.length) { @@ -104,5 +103,4 @@ function getErrorHeader(error: ApiError) { export default memo(withGlobal( (global): StateProps => pick(global, ['dialogs']), - (setGlobal, actions): DispatchProps => pick(actions, ['dismissDialog', 'acceptInviteConfirmation']), )(Dialogs)); diff --git a/src/components/main/DownloadManager.tsx b/src/components/main/DownloadManager.tsx index 84ca6614b..4f0a3b364 100644 --- a/src/components/main/DownloadManager.tsx +++ b/src/components/main/DownloadManager.tsx @@ -1,7 +1,7 @@ import { FC, memo, useEffect } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions, Thread } from '../../global/types'; +import { Thread } from '../../global/types'; import { ApiMediaFormat, ApiMessage } from '../../api/types'; import * as mediaLoader from '../../util/mediaLoader'; @@ -9,7 +9,6 @@ import download from '../../util/download'; import { getMessageContentFilename, getMessageMediaHash, } from '../../modules/helpers'; -import { pick } from '../../util/iteratees'; type StateProps = { activeDownloads: Record; @@ -19,15 +18,14 @@ type StateProps = { }>; }; -type DispatchProps = Pick; - const startedDownloads = new Set(); -const DownloadManager: FC = ({ +const DownloadManager: FC = ({ activeDownloads, messages, - cancelMessageMediaDownload, }) => { + const { cancelMessageMediaDownload } = getDispatch(); + useEffect(() => { Object.entries(activeDownloads).forEach(([chatId, messageIds]) => { const activeMessages = messageIds.map((id) => messages[Number(chatId)].byId[id]); @@ -77,5 +75,4 @@ export default memo(withGlobal( messages, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['cancelMessageMediaDownload']), )(DownloadManager)); diff --git a/src/components/main/ForwardPicker.tsx b/src/components/main/ForwardPicker.tsx index 2fb129f28..a38226ce3 100644 --- a/src/components/main/ForwardPicker.tsx +++ b/src/components/main/ForwardPicker.tsx @@ -1,9 +1,8 @@ import React, { FC, useMemo, useState, memo, useRef, useCallback, } from '../../lib/teact/teact'; -import { getGlobal, withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, getGlobal, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiChat, MAIN_THREAD_ID } from '../../api/types'; import { @@ -12,7 +11,7 @@ import { getCanPostInChat, sortChatIds, } from '../../modules/helpers'; -import { pick, unique } from '../../util/iteratees'; +import { unique } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import useCurrentOrPrev from '../../hooks/useCurrentOrPrev'; @@ -31,9 +30,7 @@ type StateProps = { currentUserId?: string; }; -type DispatchProps = Pick; - -const ForwardPicker: FC = ({ +const ForwardPicker: FC = ({ chatsById, activeListIds, archivedListIds, @@ -41,10 +38,13 @@ const ForwardPicker: FC = ({ contactIds, currentUserId, isOpen, - setForwardChatId, - exitForwardMode, - loadMoreChats, }) => { + const { + setForwardChatId, + exitForwardMode, + loadMoreChats, + } = getDispatch(); + const lang = useLang(); const [filter, setFilter] = useState(''); // eslint-disable-next-line no-null/no-null @@ -120,5 +120,4 @@ export default memo(withGlobal( currentUserId, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['setForwardChatId', 'exitForwardMode', 'loadMoreChats']), )(ForwardPicker)); diff --git a/src/components/main/HistoryCalendar.tsx b/src/components/main/HistoryCalendar.tsx index 1927453ae..5821ef46e 100644 --- a/src/components/main/HistoryCalendar.tsx +++ b/src/components/main/HistoryCalendar.tsx @@ -1,9 +1,6 @@ import React, { FC, memo, useCallback } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; - -import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import CalendarModal from '../common/CalendarModal'; @@ -16,11 +13,11 @@ type StateProps = { selectedAt?: number; }; -type DispatchProps = Pick; - -const HistoryCalendar: FC = ({ - isOpen, selectedAt, searchMessagesByDate, closeHistoryCalendar, +const HistoryCalendar: FC = ({ + isOpen, selectedAt, }) => { + const { searchMessagesByDate, closeHistoryCalendar } = getDispatch(); + const handleJumpToDate = useCallback((date: Date) => { searchMessagesByDate({ timestamp: date.valueOf() / 1000 }); closeHistoryCalendar(); @@ -44,7 +41,4 @@ export default memo(withGlobal( (global): StateProps => { return { selectedAt: global.historyCalendarSelectedAt }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'searchMessagesByDate', 'closeHistoryCalendar', - ]), )(HistoryCalendar)); diff --git a/src/components/main/Main.tsx b/src/components/main/Main.tsx index f1322d6ff..4a85cb177 100644 --- a/src/components/main/Main.tsx +++ b/src/components/main/Main.tsx @@ -1,17 +1,15 @@ import React, { FC, useEffect, memo, useCallback, } from '../../lib/teact/teact'; -import { getGlobal, withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, getGlobal, withGlobal } from '../../lib/teact/teactn'; import { LangCode } from '../../types'; -import { GlobalActions } from '../../global/types'; import { ApiMessage } from '../../api/types'; import '../../modules/actions/all'; import { BASE_EMOJI_KEYWORD_LANG, DEBUG, INACTIVE_MARKER, PAGE_TITLE, } from '../../config'; -import { pick } from '../../util/iteratees'; import { selectChatMessage, selectCountNotMutedUnread, @@ -72,12 +70,6 @@ type StateProps = { isCallFallbackConfirmOpen: boolean; }; -type DispatchProps = Pick; - const NOTIFICATION_INTERVAL = 1000; let notificationInterval: number | undefined; @@ -85,7 +77,7 @@ let notificationInterval: number | undefined; // eslint-disable-next-line @typescript-eslint/naming-convention let DEBUG_isLogged = false; -const Main: FC = ({ +const Main: FC = ({ lastSyncTime, isLeftColumnShown, isRightColumnShown, @@ -104,17 +96,20 @@ const Main: FC = ({ language, wasTimeFormatSetManually, isCallFallbackConfirmOpen, - loadAnimatedEmojis, - loadNotificationSettings, - loadNotificationExceptions, - updateIsOnline, - loadTopInlineBots, - loadEmojiKeywords, - loadCountryList, - ensureTimeFormat, - openStickerSetShortName, - checkVersionNotification, }) => { + const { + loadAnimatedEmojis, + loadNotificationSettings, + loadNotificationExceptions, + updateIsOnline, + loadTopInlineBots, + loadEmojiKeywords, + loadCountryList, + ensureTimeFormat, + openStickerSetShortName, + checkVersionNotification, + } = getDispatch(); + if (DEBUG && !DEBUG_isLogged) { DEBUG_isLogged = true; // eslint-disable-next-line no-console @@ -362,9 +357,4 @@ export default memo(withGlobal( isCallFallbackConfirmOpen: Boolean(global.groupCalls.isFallbackConfirmOpen), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadAnimatedEmojis', 'loadNotificationSettings', 'loadNotificationExceptions', 'updateIsOnline', - 'loadTopInlineBots', 'loadEmojiKeywords', 'openStickerSetShortName', 'loadCountryList', 'ensureTimeFormat', - 'checkVersionNotification', - ]), )(Main)); diff --git a/src/components/main/Notifications.tsx b/src/components/main/Notifications.tsx index 048a1d584..fed02bc10 100644 --- a/src/components/main/Notifications.tsx +++ b/src/components/main/Notifications.tsx @@ -1,7 +1,6 @@ import React, { FC, memo } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiNotification } from '../../api/types'; import { pick } from '../../util/iteratees'; @@ -13,9 +12,9 @@ type StateProps = { notifications: ApiNotification[]; }; -type DispatchProps = Pick; +const Notifications: FC = ({ notifications }) => { + const { dismissNotification } = getDispatch(); -const Notifications: FC = ({ notifications, dismissNotification }) => { if (!notifications.length) { return undefined; } @@ -34,5 +33,4 @@ const Notifications: FC = ({ notifications, dismissN export default memo(withGlobal( (global): StateProps => pick(global, ['notifications']), - (setGlobal, actions): DispatchProps => pick(actions, ['dismissNotification']), )(Notifications)); diff --git a/src/components/main/SafeLinkModal.tsx b/src/components/main/SafeLinkModal.tsx index 0e7094f90..26d210838 100644 --- a/src/components/main/SafeLinkModal.tsx +++ b/src/components/main/SafeLinkModal.tsx @@ -1,9 +1,6 @@ import React, { FC, memo, useCallback } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; - -import { pick } from '../../util/iteratees'; import { ensureProtocol } from '../../util/ensureProtocol'; import renderText from '../common/helpers/renderText'; import useLang from '../../hooks/useLang'; @@ -15,9 +12,9 @@ export type OwnProps = { url?: string; }; -type DispatchProps = Pick; +const SafeLinkModal: FC = ({ url }) => { + const { toggleSafeLinkModal } = getDispatch(); -const SafeLinkModal: FC = ({ url, toggleSafeLinkModal }) => { const lang = useLang(); const handleOpen = useCallback(() => { @@ -43,7 +40,4 @@ const SafeLinkModal: FC = ({ url, toggleSafeLinkModal ); }; -export default memo(withGlobal( - undefined, - (setGlobal, actions): DispatchProps => pick(actions, ['toggleSafeLinkModal']), -)(SafeLinkModal)); +export default memo(SafeLinkModal); diff --git a/src/components/mediaViewer/MediaViewer.tsx b/src/components/mediaViewer/MediaViewer.tsx index 6022e3522..6bfa13dcd 100644 --- a/src/components/mediaViewer/MediaViewer.tsx +++ b/src/components/mediaViewer/MediaViewer.tsx @@ -1,9 +1,8 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useRef, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiChat, ApiDimensions, ApiMediaFormat, ApiMessage, ApiUser, } from '../../api/types'; @@ -51,7 +50,6 @@ import { stopCurrentAudio } from '../../util/audioPlayer'; import captureEscKeyListener from '../../util/captureEscKeyListener'; import { captureEvents } from '../../util/captureEvents'; import { IS_IOS, IS_SINGLE_COLUMN_LAYOUT, IS_TOUCH_ENV } from '../../util/environment'; -import { pick } from '../../util/iteratees'; import windowSize from '../../util/windowSize'; import { AVATAR_FULL_DIMENSIONS, MEDIA_VIEWER_MEDIA_QUERY } from '../common/helpers/mediaDimensions'; import { renderMessageText } from '../common/helpers/renderMessageText'; @@ -83,11 +81,9 @@ type StateProps = { animationLevel: 0 | 1 | 2; }; -type DispatchProps = Pick; - const ANIMATION_DURATION = 350; -const MediaViewer: FC = ({ +const MediaViewer: FC = ({ chatId, threadId, messageId, @@ -98,12 +94,15 @@ const MediaViewer: FC = ({ message, chatMessages, collectionIds, - openMediaViewer, - closeMediaViewer, - openForwardMenu, - focusMessage, animationLevel, }) => { + const { + openMediaViewer, + closeMediaViewer, + openForwardMenu, + focusMessage, + } = getDispatch(); + const isOpen = Boolean(avatarOwner || messageId); const isFromSharedMedia = origin === MediaViewerOrigin.SharedMedia; @@ -641,7 +640,4 @@ export default memo(withGlobal( animationLevel, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'openMediaViewer', 'closeMediaViewer', 'openForwardMenu', 'focusMessage', - ]), )(MediaViewer)); diff --git a/src/components/mediaViewer/MediaViewerActions.tsx b/src/components/mediaViewer/MediaViewerActions.tsx index 54e8c4228..20c0ccc6f 100644 --- a/src/components/mediaViewer/MediaViewerActions.tsx +++ b/src/components/mediaViewer/MediaViewerActions.tsx @@ -4,9 +4,8 @@ import React, { useCallback, useMemo, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiMessage } from '../../api/types'; import { IS_SINGLE_COLUMN_LAYOUT } from '../../util/environment'; @@ -14,7 +13,6 @@ import { getMessageMediaHash } from '../../modules/helpers'; import useLang from '../../hooks/useLang'; import useMediaWithLoadProgress from '../../hooks/useMediaWithLoadProgress'; import { selectIsDownloading } from '../../modules/selectors'; -import { pick } from '../../util/iteratees'; import Button from '../ui/Button'; import DropdownMenu from '../ui/DropdownMenu'; @@ -39,9 +37,7 @@ type OwnProps = { onZoomToggle: NoneToVoidFunction; }; -type DispatchProps = Pick; - -const MediaViewerActions: FC = ({ +const MediaViewerActions: FC = ({ mediaData, isVideo, isZoomed, @@ -52,9 +48,12 @@ const MediaViewerActions: FC = ({ onCloseMediaViewer, onForward, onZoomToggle, - downloadMessageMedia, - cancelMessageMediaDownload, }) => { + const { + downloadMessageMedia, + cancelMessageMediaDownload, + } = getDispatch(); + const { loadProgress: downloadProgress } = useMediaWithLoadProgress( message && getMessageMediaHash(message, 'download'), !isDownloading, @@ -193,8 +192,4 @@ export default memo(withGlobal( isDownloading, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'downloadMessageMedia', - 'cancelMessageMediaDownload', - ]), )(MediaViewerActions)); diff --git a/src/components/mediaViewer/SenderInfo.tsx b/src/components/mediaViewer/SenderInfo.tsx index 44b6bb617..fd45d1c28 100644 --- a/src/components/mediaViewer/SenderInfo.tsx +++ b/src/components/mediaViewer/SenderInfo.tsx @@ -1,7 +1,6 @@ import React, { FC, useCallback } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiChat, ApiMessage, ApiUser } from '../../api/types'; import { getSenderTitle, isUserId } from '../../modules/helpers'; @@ -13,7 +12,6 @@ import { selectSender, selectUser, } from '../../modules/selectors'; -import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import Avatar from '../common/Avatar'; @@ -31,17 +29,18 @@ type StateProps = { message?: ApiMessage; }; -type DispatchProps = Pick; - -const SenderInfo: FC = ({ +const SenderInfo: FC = ({ chatId, messageId, sender, isAvatar, message, - closeMediaViewer, - focusMessage, }) => { + const { + closeMediaViewer, + focusMessage, + } = getDispatch(); + const handleFocusMessage = useCallback(() => { closeMediaViewer(); focusMessage({ chatId, messageId }); @@ -95,5 +94,4 @@ export default withGlobal( sender: message && selectSender(global, message), }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['closeMediaViewer', 'focusMessage']), )(SenderInfo); diff --git a/src/components/middle/AudioPlayer.tsx b/src/components/middle/AudioPlayer.tsx index 2db87ed69..683772a66 100644 --- a/src/components/middle/AudioPlayer.tsx +++ b/src/components/middle/AudioPlayer.tsx @@ -1,10 +1,9 @@ import React, { FC, useCallback, useEffect, useMemo, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { AudioOrigin } from '../../types'; -import { GlobalActions } from '../../global/types'; import { ApiAudio, ApiChat, ApiMessage, ApiUser, } from '../../api/types'; @@ -16,7 +15,6 @@ import { getMediaDuration, getMessageContent, getMessageMediaHash, getSenderTitle, isMessageLocal, } from '../../modules/helpers'; import { selectChat, selectSender } from '../../modules/selectors'; -import { pick } from '../../util/iteratees'; import buildClassName from '../../util/buildClassName'; import { makeTrackId } from '../../util/audioPlayer'; import { clearMediaSession } from '../../util/mediaSession'; @@ -47,17 +45,9 @@ type StateProps = { isMuted: boolean; }; -type DispatchProps = Pick; - const FAST_PLAYBACK_RATE = 1.8; -const AudioPlayer: FC = ({ +const AudioPlayer: FC = ({ message, className, noUi, @@ -66,12 +56,15 @@ const AudioPlayer: FC = ({ volume, playbackRate, isMuted, - setAudioPlayerVolume, - setAudioPlayerPlaybackRate, - setAudioPlayerMuted, - focusMessage, - closeAudioPlayer, }) => { + const { + setAudioPlayerVolume, + setAudioPlayerPlaybackRate, + setAudioPlayerMuted, + focusMessage, + closeAudioPlayer, + } = getDispatch(); + const lang = useLang(); const { audio, voice, video } = getMessageContent(message); const isVoice = Boolean(voice || video); @@ -293,8 +286,4 @@ export default withGlobal( isMuted, }; }, - (setGlobal, actions): DispatchProps => pick( - actions, - ['focusMessage', 'closeAudioPlayer', 'setAudioPlayerVolume', 'setAudioPlayerPlaybackRate', 'setAudioPlayerMuted'], - ), )(AudioPlayer); diff --git a/src/components/middle/ContactGreeting.tsx b/src/components/middle/ContactGreeting.tsx index 7f8ed3e7b..072edd57a 100644 --- a/src/components/middle/ContactGreeting.tsx +++ b/src/components/middle/ContactGreeting.tsx @@ -1,12 +1,10 @@ import React, { FC, memo, useCallback, useEffect, useRef, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiSticker, ApiUpdateConnectionStateType } from '../../api/types'; -import { pick } from '../../util/iteratees'; import { selectChat } from '../../modules/selectors'; import { useIntersectionObserver } from '../../hooks/useIntersectionObserver'; import useLang from '../../hooks/useLang'; @@ -26,18 +24,19 @@ type StateProps = { connectionState?: ApiUpdateConnectionStateType; }; -type DispatchProps = Pick; - const INTERSECTION_DEBOUNCE_MS = 200; -const ContactGreeting: FC = ({ +const ContactGreeting: FC = ({ sticker, connectionState, lastUnreadMessageId, - loadGreetingStickers, - sendMessage, - markMessageListRead, }) => { + const { + loadGreetingStickers, + sendMessage, + markMessageListRead, + } = getDispatch(); + const lang = useLang(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); @@ -110,7 +109,4 @@ export default memo(withGlobal( connectionState: global.connectionState, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadGreetingStickers', 'sendMessage', 'markMessageListRead', - ]), )(ContactGreeting)); diff --git a/src/components/middle/DeleteSelectedMessageModal.tsx b/src/components/middle/DeleteSelectedMessageModal.tsx index 705401999..f6e52c1f2 100644 --- a/src/components/middle/DeleteSelectedMessageModal.tsx +++ b/src/components/middle/DeleteSelectedMessageModal.tsx @@ -1,9 +1,7 @@ import React, { FC, useCallback, memo, useEffect, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; - -import { GlobalActions } from '../../global/types'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { selectCanDeleteSelectedMessages, selectCurrentChat, selectUser } from '../../modules/selectors'; import { @@ -14,7 +12,6 @@ import { isChatSuperGroup, } from '../../modules/helpers'; import renderText from '../common/helpers/renderText'; -import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import usePrevious from '../../hooks/usePrevious'; @@ -35,9 +32,7 @@ type StateProps = { willDeleteForAll?: boolean; }; -type DispatchProps = Pick; - -const DeleteSelectedMessageModal: FC = ({ +const DeleteSelectedMessageModal: FC = ({ isOpen, isSchedule, selectedMessageIds, @@ -46,10 +41,13 @@ const DeleteSelectedMessageModal: FC = ({ willDeleteForCurrentUserOnly, willDeleteForAll, onClose, - deleteMessages, - deleteScheduledMessages, - exitMessageSelectMode, }) => { + const { + deleteMessages, + deleteScheduledMessages, + exitMessageSelectMode, + } = getDispatch(); + const prevIsOpen = usePrevious(isOpen); const handleDeleteMessageForAll = useCallback(() => { @@ -130,9 +128,4 @@ export default memo(withGlobal( willDeleteForAll, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'deleteMessages', - 'deleteScheduledMessages', - 'exitMessageSelectMode', - ]), )(DeleteSelectedMessageModal)); diff --git a/src/components/middle/HeaderActions.tsx b/src/components/middle/HeaderActions.tsx index 6acf904b5..1fdec9f45 100644 --- a/src/components/middle/HeaderActions.tsx +++ b/src/components/middle/HeaderActions.tsx @@ -5,14 +5,13 @@ import React, { useCallback, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions, MessageListType } from '../../global/types'; +import { MessageListType } from '../../global/types'; import { MAIN_THREAD_ID } from '../../api/types'; import { IAnchorPosition } from '../../types'; import { ARE_CALLS_SUPPORTED, IS_SINGLE_COLUMN_LAYOUT } from '../../util/environment'; -import { pick } from '../../util/iteratees'; import { isChatBasicGroup, isChatChannel, isChatSuperGroup, isUserId, } from '../../modules/helpers'; @@ -52,14 +51,10 @@ interface StateProps { canCreateVoiceChat?: boolean; } -type DispatchProps = Pick; - // Chrome breaks layout when focusing input during transition const SEARCH_FOCUS_DELAY_MS = 400; -const HeaderActions: FC = ({ +const HeaderActions: FC = ({ chatId, threadId, noMenu, @@ -75,12 +70,15 @@ const HeaderActions: FC = ({ canCreateVoiceChat, isRightColumnShown, canExpandActions, - joinChannel, - sendBotCommand, - openLocalTextSearch, - restartBot, - openCallFallbackConfirm, }) => { + const { + joinChannel, + sendBotCommand, + openLocalTextSearch, + restartBot, + openCallFallbackConfirm, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const menuButtonRef = useRef(null); const [isMenuOpen, setIsMenuOpen] = useState(false); @@ -275,7 +273,4 @@ export default memo(withGlobal( canCreateVoiceChat, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'joinChannel', 'sendBotCommand', 'openLocalTextSearch', 'restartBot', 'openCallFallbackConfirm', - ]), )(HeaderActions)); diff --git a/src/components/middle/HeaderMenuContainer.tsx b/src/components/middle/HeaderMenuContainer.tsx index 8ca0e4615..c5224d1ad 100644 --- a/src/components/middle/HeaderMenuContainer.tsx +++ b/src/components/middle/HeaderMenuContainer.tsx @@ -1,9 +1,8 @@ import React, { FC, memo, useCallback, useEffect, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiChat } from '../../api/types'; import { IAnchorPosition } from '../../types'; @@ -12,7 +11,6 @@ import { disableScrolling, enableScrolling } from '../../util/scrollLock'; import { selectChat, selectNotifySettings, selectNotifyExceptions, selectUser, } from '../../modules/selectors'; -import { pick } from '../../util/iteratees'; import { isUserId, getCanDeleteChat, selectIsChatMuted, getCanAddContact, } from '../../modules/helpers'; @@ -26,11 +24,6 @@ import DeleteChatModal from '../common/DeleteChatModal'; import './HeaderMenuContainer.scss'; -type DispatchProps = Pick; - export type OwnProps = { chatId: string; threadId: number; @@ -62,7 +55,7 @@ type StateProps = { hasLinkedChat?: boolean; }; -const HeaderMenuContainer: FC = ({ +const HeaderMenuContainer: FC = ({ chatId, isOpen, withExtraActions, @@ -87,16 +80,19 @@ const HeaderMenuContainer: FC = ({ onSearchClick, onClose, onCloseAnimationEnd, - updateChatMutedState, - enterMessageSelectMode, - sendBotCommand, - restartBot, - joinGroupCall, - createGroupCall, - openLinkedChat, - addContact, - openCallFallbackConfirm, }) => { + const { + updateChatMutedState, + enterMessageSelectMode, + sendBotCommand, + restartBot, + joinGroupCall, + createGroupCall, + openLinkedChat, + addContact, + openCallFallbackConfirm, + } = getDispatch(); + const [isMenuOpen, setIsMenuOpen] = useState(true); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const { x, y } = anchor; @@ -313,15 +309,4 @@ export default memo(withGlobal( hasLinkedChat: Boolean(chat?.fullInfo?.linkedChatId), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'updateChatMutedState', - 'enterMessageSelectMode', - 'sendBotCommand', - 'restartBot', - 'joinGroupCall', - 'createGroupCall', - 'openLinkedChat', - 'addContact', - 'openCallFallbackConfirm', - ]), )(HeaderMenuContainer)); diff --git a/src/components/middle/MessageList.tsx b/src/components/middle/MessageList.tsx index 7127ecb2a..5048e8b9a 100644 --- a/src/components/middle/MessageList.tsx +++ b/src/components/middle/MessageList.tsx @@ -1,12 +1,12 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useRef, useState, } from '../../lib/teact/teact'; -import { getGlobal, withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, getGlobal, withGlobal } from '../../lib/teact/teactn'; import { ApiMessage, ApiRestrictionReason, MAIN_THREAD_ID, } from '../../api/types'; -import { GlobalActions, MessageListType } from '../../global/types'; +import { MessageListType } from '../../global/types'; import { LoadMoreDirection } from '../../types'; import { ANIMATION_END_DELAY, LOCAL_MESSAGE_ID_BASE, MESSAGE_LIST_SLICE } from '../../config'; @@ -32,7 +32,7 @@ import { isChatWithRepliesBot, isChatGroup, } from '../../modules/helpers'; -import { orderBy, pick } from '../../util/iteratees'; +import { orderBy } from '../../util/iteratees'; import { fastRaf, debounce, onTickEnd } from '../../util/schedulers'; import useLayoutEffectWithPrevDeps from '../../hooks/useLayoutEffectWithPrevDeps'; import useEffectWithPrevDeps from '../../hooks/useEffectWithPrevDeps'; @@ -91,8 +91,6 @@ type StateProps = { hasLinkedChat?: boolean; }; -type DispatchProps = Pick; - const BOTTOM_THRESHOLD = 20; const UNREAD_DIVIDER_TOP = 10; const UNREAD_DIVIDER_TOP_WITH_TOOLS = 60; @@ -104,7 +102,7 @@ const UNREAD_DIVIDER_CLASS = 'unread-divider'; const runDebouncedForScroll = debounce((cb) => cb(), SCROLL_DEBOUNCE, false); -const MessageList: FC = ({ +const MessageList: FC = ({ chatId, threadId, type, @@ -129,15 +127,14 @@ const MessageList: FC = ({ restrictionReason, focusingId, isSelectModeActive, - loadViewportMessages, - setScrollOffset, lastMessage, botDescription, threadTopMessageId, hasLinkedChat, withBottomShift, - openHistoryCalendar, }) => { + const { loadViewportMessages, setScrollOffset } = getDispatch(); + // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); @@ -530,7 +527,6 @@ const MessageList: FC = ({ noAppearanceAnimation={!messageGroups || !shouldAnimateAppearanceRef.current} onFabToggle={onFabToggle} onNotchToggle={onNotchToggle} - openHistoryCalendar={openHistoryCalendar} /> ) : ( @@ -602,9 +598,4 @@ export default memo(withGlobal( ...(withLastMessageWhenPreloading && { lastMessage }), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadViewportMessages', - 'setScrollOffset', - 'openHistoryCalendar', - ]), )(MessageList)); diff --git a/src/components/middle/MessageListContent.tsx b/src/components/middle/MessageListContent.tsx index fa75fb46f..a4c2d625d 100644 --- a/src/components/middle/MessageListContent.tsx +++ b/src/components/middle/MessageListContent.tsx @@ -16,6 +16,7 @@ import useMessageObservers from './hooks/useMessageObservers'; import Message from './message/Message'; import ActionMessage from './ActionMessage'; +import { getDispatch } from '../../lib/teact/teactn'; interface OwnProps { messageIds: number[]; @@ -39,7 +40,6 @@ interface OwnProps { noAppearanceAnimation: boolean; onFabToggle: AnyToVoidFunction; onNotchToggle: AnyToVoidFunction; - openHistoryCalendar: Function; } const UNREAD_DIVIDER_CLASS = 'unread-divider'; @@ -66,8 +66,9 @@ const MessageListContent: FC = ({ noAppearanceAnimation, onFabToggle, onNotchToggle, - openHistoryCalendar, }) => { + const { openHistoryCalendar } = getDispatch(); + const { observeIntersectionForMedia, observeIntersectionForReading, diff --git a/src/components/middle/MessageSelectToolbar.tsx b/src/components/middle/MessageSelectToolbar.tsx index 10a095728..1fa129250 100644 --- a/src/components/middle/MessageSelectToolbar.tsx +++ b/src/components/middle/MessageSelectToolbar.tsx @@ -1,9 +1,9 @@ import React, { FC, memo, useCallback, useEffect, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions, MessageListType } from '../../global/types'; +import { MessageListType } from '../../global/types'; import { selectCanDeleteSelectedMessages, @@ -12,7 +12,6 @@ import { selectCurrentMessageList, selectSelectedMessagesCount, } from '../../modules/selectors'; -import { pick } from '../../util/iteratees'; import useFlag from '../../hooks/useFlag'; import captureKeyboardListeners from '../../util/captureKeyboardListeners'; import buildClassName from '../../util/buildClassName'; @@ -41,11 +40,7 @@ type StateProps = { selectedMessageIds?: number[]; }; -type DispatchProps = Pick; - -const MessageSelectToolbar: FC = ({ +const MessageSelectToolbar: FC = ({ canPost, isActive, messageListType, @@ -55,10 +50,13 @@ const MessageSelectToolbar: FC = ({ canReportMessages, canDownloadMessages, selectedMessageIds, - exitMessageSelectMode, - openForwardMenuForSelectedMessages, - downloadSelectedMessages, }) => { + const { + exitMessageSelectMode, + openForwardMenuForSelectedMessages, + downloadSelectedMessages, + } = getDispatch(); + const [isDeleteModalOpen, openDeleteModal, closeDeleteModal] = useFlag(); const [isReportModalOpen, openReportModal, closeReportModal] = useFlag(); @@ -171,7 +169,4 @@ export default memo(withGlobal( selectedMessageIds, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'exitMessageSelectMode', 'openForwardMenuForSelectedMessages', 'downloadSelectedMessages', - ]), )(MessageSelectToolbar)); diff --git a/src/components/middle/MiddleColumn.tsx b/src/components/middle/MiddleColumn.tsx index 38c7f6b18..2c727d6fc 100644 --- a/src/components/middle/MiddleColumn.tsx +++ b/src/components/middle/MiddleColumn.tsx @@ -1,10 +1,10 @@ import React, { FC, useEffect, useState, memo, useMemo, useCallback, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { ApiChatBannedRights, MAIN_THREAD_ID } from '../../api/types'; -import { GlobalActions, MessageListType, MessageList as GlobalMessageList } from '../../global/types'; +import { MessageListType, MessageList as GlobalMessageList } from '../../global/types'; import { ThemeKey } from '../../types'; import { @@ -43,7 +43,6 @@ import { getCanPostInChat, getMessageSendingRestrictionReason, isChatChannel, isChatSuperGroup, isUserId, } from '../../modules/helpers'; import captureEscKeyListener from '../../util/captureEscKeyListener'; -import { pick } from '../../util/iteratees'; import buildClassName from '../../util/buildClassName'; import { createMessageHash } from '../../util/routing'; import useCustomBackground from '../../hooks/useCustomBackground'; @@ -104,18 +103,13 @@ type StateProps = { canRestartBot?: boolean; }; -type DispatchProps = Pick; - const CLOSE_ANIMATION_DURATION = IS_SINGLE_COLUMN_LAYOUT ? 450 + ANIMATION_END_DELAY : undefined; function isImage(item: DataTransferItem) { return item.kind === 'file' && item.type && SUPPORTED_IMAGE_CONTENT_TYPES.has(item.type); } -const MiddleColumn: FC = ({ +const MiddleColumn: FC = ({ chatId, threadId, messageListType, @@ -146,17 +140,20 @@ const MiddleColumn: FC = ({ canSubscribe, canStartBot, canRestartBot, - openChat, - unpinAllMessages, - loadUser, - closeLocalTextSearch, - exitMessageSelectMode, - closePaymentModal, - clearReceipt, - joinChannel, - sendBotCommand, - restartBot, }) => { + const { + openChat, + unpinAllMessages, + loadUser, + closeLocalTextSearch, + exitMessageSelectMode, + closePaymentModal, + clearReceipt, + joinChannel, + sendBotCommand, + restartBot, + } = getDispatch(); + const { width: windowWidth } = useWindowSize(); const lang = useLang(); @@ -588,10 +585,6 @@ export default memo(withGlobal( canRestartBot, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'openChat', 'unpinAllMessages', 'loadUser', 'closeLocalTextSearch', 'exitMessageSelectMode', - 'closePaymentModal', 'clearReceipt', 'joinChannel', 'sendBotCommand', 'restartBot', - ]), )(MiddleColumn)); function useIsReady( diff --git a/src/components/middle/MiddleHeader.tsx b/src/components/middle/MiddleHeader.tsx index 11bda9429..0381fdcb5 100644 --- a/src/components/middle/MiddleHeader.tsx +++ b/src/components/middle/MiddleHeader.tsx @@ -1,10 +1,10 @@ import React, { FC, useCallback, useMemo, memo, useEffect, useRef, useState, } from '../../lib/teact/teact'; -import { getGlobal, withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, getGlobal, withGlobal } from '../../lib/teact/teactn'; import cycleRestrict from '../../util/cycleRestrict'; -import { GlobalActions, MessageListType } from '../../global/types'; +import { MessageListType } from '../../global/types'; import { ApiMessage, ApiChat, @@ -48,7 +48,6 @@ import useEnsureMessage from '../../hooks/useEnsureMessage'; import useWindowSize from '../../hooks/useWindowSize'; import useShowTransition from '../../hooks/useShowTransition'; import useCurrentOrPrev from '../../hooks/useCurrentOrPrev'; -import { pick } from '../../util/iteratees'; import { formatIntegerCompact } from '../../util/textFormat'; import buildClassName from '../../util/buildClassName'; import useLang from '../../hooks/useLang'; @@ -96,12 +95,7 @@ type StateProps = { connectionState?: ApiUpdateConnectionStateType; }; -type DispatchProps = Pick; - -const MiddleHeader: FC = ({ +const MiddleHeader: FC = ({ chatId, threadId, messageListType, @@ -124,15 +118,18 @@ const MiddleHeader: FC = ({ shouldSkipHistoryAnimations, currentTransitionKey, connectionState, - openChatWithInfo, - pinMessage, - focusMessage, - openChat, - openPreviousChat, - loadPinnedMessages, - toggleLeftColumn, - exitMessageSelectMode, }) => { + const { + openChatWithInfo, + pinMessage, + focusMessage, + openChat, + openPreviousChat, + loadPinnedMessages, + toggleLeftColumn, + exitMessageSelectMode, + } = getDispatch(); + const lang = useLang(); const isBackButtonActive = useRef(true); @@ -523,14 +520,4 @@ export default memo(withGlobal( return state; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'openChatWithInfo', - 'pinMessage', - 'focusMessage', - 'openChat', - 'openPreviousChat', - 'loadPinnedMessages', - 'toggleLeftColumn', - 'exitMessageSelectMode', - ]), )(MiddleHeader)); diff --git a/src/components/middle/MobileSearch.tsx b/src/components/middle/MobileSearch.tsx index c8fa22c42..e9f98a73d 100644 --- a/src/components/middle/MobileSearch.tsx +++ b/src/components/middle/MobileSearch.tsx @@ -1,14 +1,12 @@ import React, { FC, memo, useCallback, useEffect, useRef, useState, useLayoutEffect, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { ApiChat } from '../../api/types'; -import { GlobalActions } from '../../global/types'; import { debounce } from '../../util/schedulers'; import { selectCurrentTextSearch, selectCurrentChat } from '../../modules/selectors'; -import { pick } from '../../util/iteratees'; import { getDayStartAt } from '../../util/dateFormat'; import Button from '../ui/Button'; @@ -29,26 +27,24 @@ type StateProps = { isHistoryCalendarOpen?: boolean; }; -type DispatchProps = Pick; - const runDebouncedForSearch = debounce((cb) => cb(), 200, false); -const MobileSearchFooter: FC = ({ +const MobileSearchFooter: FC = ({ isActive, chat, query, totalCount, foundIds, isHistoryCalendarOpen, - setLocalTextSearchQuery, - searchTextMessagesLocal, - focusMessage, - closeLocalTextSearch, - openHistoryCalendar, }) => { + const { + setLocalTextSearchQuery, + searchTextMessagesLocal, + focusMessage, + closeLocalTextSearch, + openHistoryCalendar, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const inputRef = useRef(null); const [focusedIndex, setFocusedIndex] = useState(0); @@ -218,11 +214,4 @@ export default memo(withGlobal( isHistoryCalendarOpen: Boolean(global.historyCalendarSelectedAt), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'setLocalTextSearchQuery', - 'searchTextMessagesLocal', - 'focusMessage', - 'closeLocalTextSearch', - 'openHistoryCalendar', - ]), )(MobileSearchFooter)); diff --git a/src/components/middle/ScrollDownButton.tsx b/src/components/middle/ScrollDownButton.tsx index 7a889c2dd..353e4bc90 100644 --- a/src/components/middle/ScrollDownButton.tsx +++ b/src/components/middle/ScrollDownButton.tsx @@ -1,15 +1,14 @@ import React, { FC, useCallback, memo, useRef, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions, MessageListType } from '../../global/types'; +import { MessageListType } from '../../global/types'; import { MAIN_THREAD_ID } from '../../api/types'; import { selectChat, selectCurrentMessageList } from '../../modules/selectors'; import { formatIntegerCompact } from '../../util/textFormat'; import buildClassName from '../../util/buildClassName'; -import { pick } from '../../util/iteratees'; import fastSmoothScroll from '../../util/fastSmoothScroll'; import useLang from '../../hooks/useLang'; @@ -28,18 +27,17 @@ type StateProps = { unreadCount?: number; }; -type DispatchProps = Pick; - const FOCUS_MARGIN = 20; -const ScrollDownButton: FC = ({ +const ScrollDownButton: FC = ({ isShown, canPost, messageListType, unreadCount, withExtraShift, - focusNextReply, }) => { + const { focusNextReply } = getDispatch(); + const lang = useLang(); // eslint-disable-next-line no-null/no-null const elementRef = useRef(null); @@ -104,5 +102,4 @@ export default memo(withGlobal( unreadCount: chat && threadId === MAIN_THREAD_ID && messageListType === 'thread' ? chat.unreadCount : undefined, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['focusNextReply']), )(ScrollDownButton)); diff --git a/src/components/middle/composer/BotCommandMenu.tsx b/src/components/middle/composer/BotCommandMenu.tsx index 5bf96c3ee..387932b8b 100644 --- a/src/components/middle/composer/BotCommandMenu.tsx +++ b/src/components/middle/composer/BotCommandMenu.tsx @@ -1,17 +1,15 @@ import React, { FC, memo, useCallback } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiBotCommand } from '../../../api/types'; import { IS_SINGLE_COLUMN_LAYOUT, IS_TOUCH_ENV } from '../../../util/environment'; -import { pick } from '../../../util/iteratees'; import useMouseInside from '../../../hooks/useMouseInside'; import Menu from '../../ui/Menu'; import BotCommand from './BotCommand'; import './BotCommandMenu.scss'; +import { getDispatch } from '../../../lib/teact/teactn'; export type OwnProps = { isOpen: boolean; @@ -19,11 +17,11 @@ export type OwnProps = { onClose: NoneToVoidFunction; }; -type DispatchProps = Pick; - -const BotCommandMenu: FC = ({ - isOpen, botCommands, onClose, sendBotCommand, +const BotCommandMenu: FC = ({ + isOpen, botCommands, onClose, }) => { + const { sendBotCommand } = getDispatch(); + const [handleMouseEnter, handleMouseLeave] = useMouseInside(isOpen, onClose, undefined, IS_SINGLE_COLUMN_LAYOUT); const handleClick = useCallback((botCommand: ApiBotCommand) => { @@ -57,7 +55,4 @@ const BotCommandMenu: FC = ({ ); }; -export default memo(withGlobal( - undefined, - (setGlobal, actions): DispatchProps => pick(actions, ['sendBotCommand']), -)(BotCommandMenu)); +export default memo(BotCommandMenu); diff --git a/src/components/middle/composer/BotCommandTooltip.tsx b/src/components/middle/composer/BotCommandTooltip.tsx index a70e60098..4821d9d9b 100644 --- a/src/components/middle/composer/BotCommandTooltip.tsx +++ b/src/components/middle/composer/BotCommandTooltip.tsx @@ -1,12 +1,10 @@ import React, { FC, useCallback, useEffect, useRef, memo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ApiBotCommand, ApiUser } from '../../../api/types'; -import { GlobalActions } from '../../../global/types'; -import { pick } from '../../../util/iteratees'; import buildClassName from '../../../util/buildClassName'; import setTooltipItemVisible from '../../../util/setTooltipItemVisible'; import useShowTransition from '../../../hooks/useShowTransition'; @@ -29,17 +27,16 @@ type StateProps = { usersById: Record; }; -type DispatchProps = Pick; - -const BotCommandTooltip: FC = ({ +const BotCommandTooltip: FC = ({ usersById, isOpen, withUsername, botCommands, onClick, onClose, - sendBotCommand, }) => { + const { sendBotCommand } = getDispatch(); + // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); const { shouldRender, transitionClassNames } = useShowTransition(isOpen, undefined, undefined, false); @@ -102,5 +99,4 @@ export default memo(withGlobal( (global): StateProps => ({ usersById: global.users.byId, }), - (setGlobal, actions): DispatchProps => pick(actions, ['sendBotCommand']), )(BotCommandTooltip)); diff --git a/src/components/middle/composer/BotKeyboardMenu.tsx b/src/components/middle/composer/BotKeyboardMenu.tsx index b9c72fa35..2acb5afa0 100644 --- a/src/components/middle/composer/BotKeyboardMenu.tsx +++ b/src/components/middle/composer/BotKeyboardMenu.tsx @@ -1,11 +1,9 @@ import React, { FC, memo, useEffect } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiMessage } from '../../../api/types'; import { IS_TOUCH_ENV } from '../../../util/environment'; -import { pick } from '../../../util/iteratees'; import { selectChatMessage, selectCurrentMessageList } from '../../../modules/selectors'; import useMouseInside from '../../../hooks/useMouseInside'; import useFlag from '../../../hooks/useFlag'; @@ -25,11 +23,11 @@ type StateProps = { message?: ApiMessage; }; -type DispatchProps = Pick; - -const BotKeyboardMenu: FC = ({ - isOpen, message, onClose, clickInlineButton, +const BotKeyboardMenu: FC = ({ + isOpen, message, onClose, }) => { + const { clickInlineButton } = getDispatch(); + const [handleMouseEnter, handleMouseLeave] = useMouseInside(isOpen, onClose); const { isKeyboardSingleUse } = message || {}; const [forceOpen, markForceOpen, unmarkForceOpen] = useFlag(true); @@ -87,7 +85,4 @@ export default memo(withGlobal( return { message: selectChatMessage(global, chatId, messageId) }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'clickInlineButton', - ]), )(BotKeyboardMenu)); diff --git a/src/components/middle/composer/Composer.tsx b/src/components/middle/composer/Composer.tsx index fa99fe6cd..82303e6fa 100644 --- a/src/components/middle/composer/Composer.tsx +++ b/src/components/middle/composer/Composer.tsx @@ -1,9 +1,9 @@ import React, { FC, memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions, GlobalState, MessageListType } from '../../../global/types'; +import { GlobalState, MessageListType } from '../../../global/types'; import { ApiAttachment, ApiBotInlineResult, @@ -52,7 +52,6 @@ import buildAttachment from './helpers/buildAttachment'; import renderText from '../../common/helpers/renderText'; import insertHtmlInSelection from '../../../util/insertHtmlInSelection'; import deleteLastCharacterOutsideSelection from '../../../util/deleteLastCharacterOutsideSelection'; -import { pick } from '../../../util/iteratees'; import buildClassName from '../../../util/buildClassName'; import windowSize from '../../../util/windowSize'; import { isSelectionInsideInput } from './helpers/selection'; @@ -142,13 +141,6 @@ type StateProps = } & Pick; -type DispatchProps = Pick; - enum MainButtonState { Send = 'send', Record = 'record', @@ -167,7 +159,7 @@ const SENDING_ANIMATION_DURATION = 350; // eslint-disable-next-line max-len const APPENDIX = ''; -const Composer: FC = ({ +const Composer: FC = ({ dropAreaState, shouldSchedule, canScheduleUntilOnline, @@ -205,21 +197,22 @@ const Composer: FC = ({ isInlineBotLoading, botCommands, chatBotCommands, - sendMessage, - editMessage, - saveDraft, - clearDraft, - showDialog, - setStickerSearchQuery, - setGifSearchQuery, - forwardMessages, - openPollModal, - closePollModal, - loadScheduledHistory, - openChat, - addRecentEmoji, - sendInlineBotResult, }) => { + const { + sendMessage, + clearDraft, + showDialog, + setStickerSearchQuery, + setGifSearchQuery, + forwardMessages, + openPollModal, + closePollModal, + loadScheduledHistory, + openChat, + addRecentEmoji, + sendInlineBotResult, + } = getDispatch(); + const lang = useLang(); // eslint-disable-next-line no-null/no-null @@ -428,8 +421,8 @@ const Composer: FC = ({ }; }, [chatId, resetComposer, stopRecordingVoiceRef]); - const handleEditComplete = useEditing(htmlRef, setHtml, editingMessage, resetComposer, openDeleteModal, editMessage); - useDraft(draft, chatId, threadId, html, htmlRef, setHtml, editingMessage, saveDraft, clearDraft); + const handleEditComplete = useEditing(htmlRef, setHtml, editingMessage, resetComposer, openDeleteModal); + useDraft(draft, chatId, threadId, html, htmlRef, setHtml, editingMessage); useClipboardPaste(insertTextAndUpdateCursor, setAttachments, editingMessage); const handleFileSelect = useCallback(async (files: File[], isQuick: boolean) => { @@ -1111,20 +1104,4 @@ export default memo(withGlobal( botCommands: chatBot && chatBot.fullInfo ? (chatBot.fullInfo.botCommands || false) : undefined, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'sendMessage', - 'editMessage', - 'saveDraft', - 'clearDraft', - 'showDialog', - 'setStickerSearchQuery', - 'setGifSearchQuery', - 'forwardMessages', - 'openPollModal', - 'closePollModal', - 'loadScheduledHistory', - 'openChat', - 'addRecentEmoji', - 'sendInlineBotResult', - ]), )(Composer)); diff --git a/src/components/middle/composer/ComposerEmbeddedMessage.tsx b/src/components/middle/composer/ComposerEmbeddedMessage.tsx index 69c96d86a..566cc28a9 100644 --- a/src/components/middle/composer/ComposerEmbeddedMessage.tsx +++ b/src/components/middle/composer/ComposerEmbeddedMessage.tsx @@ -1,9 +1,8 @@ import React, { FC, memo, useCallback, useEffect, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiChat, ApiMessage, ApiUser } from '../../../api/types'; import { @@ -19,7 +18,6 @@ import { selectEditingMessage, } from '../../../modules/selectors'; import captureEscKeyListener from '../../../util/captureEscKeyListener'; -import { pick } from '../../../util/iteratees'; import useAsyncRendering from '../../right/hooks/useAsyncRendering'; import useShowTransition from '../../../hooks/useShowTransition'; import buildClassName from '../../../util/buildClassName'; @@ -39,22 +37,23 @@ type StateProps = { forwardedMessagesCount?: number; }; -type DispatchProps = Pick; - const FORWARD_RENDERING_DELAY = 300; -const ComposerEmbeddedMessage: FC = ({ +const ComposerEmbeddedMessage: FC = ({ replyingToId, editingId, message, sender, shouldAnimate, forwardedMessagesCount, - setReplyingToId, - setEditingId, - focusMessage, - exitForwardMode, }) => { + const { + setReplyingToId, + setEditingId, + focusMessage, + exitForwardMode, + } = getDispatch(); + const isShown = Boolean( ((replyingToId || editingId) && message) || (sender && forwardedMessagesCount), @@ -166,10 +165,4 @@ export default memo(withGlobal( forwardedMessagesCount: isForwarding ? forwardMessageIds!.length : undefined, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'setReplyingToId', - 'setEditingId', - 'focusMessage', - 'exitForwardMode', - ]), )(ComposerEmbeddedMessage)); diff --git a/src/components/middle/composer/GifPicker.tsx b/src/components/middle/composer/GifPicker.tsx index 77fd3fa87..3aa19172d 100644 --- a/src/components/middle/composer/GifPicker.tsx +++ b/src/components/middle/composer/GifPicker.tsx @@ -1,15 +1,13 @@ import React, { FC, useEffect, memo, useRef, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiVideo } from '../../../api/types'; import { SLIDE_TRANSITION_DURATION } from '../../../config'; import { IS_TOUCH_ENV } from '../../../util/environment'; import buildClassName from '../../../util/buildClassName'; -import { pick } from '../../../util/iteratees'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; import useAsyncRendering from '../../right/hooks/useAsyncRendering'; @@ -29,18 +27,17 @@ type StateProps = { savedGifs?: ApiVideo[]; }; -type DispatchProps = Pick; - const INTERSECTION_DEBOUNCE = 300; -const GifPicker: FC = ({ +const GifPicker: FC = ({ className, loadAndPlay, canSendGifs, savedGifs, onGifSelect, - loadSavedGifs, }) => { + const { loadSavedGifs } = getDispatch(); + // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); @@ -88,5 +85,4 @@ export default memo(withGlobal( savedGifs: global.gifs.saved.gifs, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadSavedGifs']), )(GifPicker)); diff --git a/src/components/middle/composer/InlineBotTooltip.tsx b/src/components/middle/composer/InlineBotTooltip.tsx index 931310c02..2711d5217 100644 --- a/src/components/middle/composer/InlineBotTooltip.tsx +++ b/src/components/middle/composer/InlineBotTooltip.tsx @@ -1,9 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useRef, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiBotInlineMediaResult, ApiBotInlineResult, ApiBotInlineSwitchPm } from '../../../api/types'; import { IAllowedAttachmentOptions } from '../../../modules/helpers'; import { LoadMoreDirection } from '../../../types'; @@ -13,7 +11,6 @@ import setTooltipItemVisible from '../../../util/setTooltipItemVisible'; import buildClassName from '../../../util/buildClassName'; import useShowTransition from '../../../hooks/useShowTransition'; import { throttle } from '../../../util/schedulers'; -import { pick } from '../../../util/iteratees'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; import usePrevious from '../../../hooks/usePrevious'; import { useKeyboardNavigation } from './hooks/useKeyboardNavigation'; @@ -26,6 +23,7 @@ import ListItem from '../../ui/ListItem'; import InfiniteScroll from '../../ui/InfiniteScroll'; import './InlineBotTooltip.scss'; +import { getDispatch } from '../../../lib/teact/teactn'; const INTERSECTION_DEBOUNCE_MS = 200; const runThrottled = throttle((cb) => cb(), 500, true); @@ -42,9 +40,7 @@ export type OwnProps = { onClose: NoneToVoidFunction; }; -type DispatchProps = Pick; - -const InlineBotTooltip: FC = ({ +const InlineBotTooltip: FC = ({ isOpen, botId, isGallery, @@ -52,10 +48,13 @@ const InlineBotTooltip: FC = ({ switchPm, loadMore, onClose, - openChat, - startBot, onSelectResult, }) => { + const { + openChat, + startBot, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); const { shouldRender, transitionClassNames } = useShowTransition(isOpen, undefined, undefined, false); @@ -196,9 +195,4 @@ const InlineBotTooltip: FC = ({ ); }; -export default memo(withGlobal( - undefined, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'startBot', 'openChat', 'sendInlineBotResult', - ]), -)(InlineBotTooltip)); +export default memo(InlineBotTooltip); diff --git a/src/components/middle/composer/MessageInput.tsx b/src/components/middle/composer/MessageInput.tsx index 92eaffdbf..a69c214db 100644 --- a/src/components/middle/composer/MessageInput.tsx +++ b/src/components/middle/composer/MessageInput.tsx @@ -2,9 +2,8 @@ import { ChangeEvent } from 'react'; import React, { FC, useEffect, useRef, memo, useState, useCallback, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { IAnchorPosition, ISettings } from '../../../types'; import { EDITABLE_INPUT_ID } from '../../../config'; @@ -12,7 +11,6 @@ import { selectReplyingToId } from '../../../modules/selectors'; import { debounce } from '../../../util/schedulers'; import focusEditableElement from '../../../util/focusEditableElement'; import buildClassName from '../../../util/buildClassName'; -import { pick } from '../../../util/iteratees'; import { IS_ANDROID, IS_EMOJI_SUPPORTED, IS_IOS, IS_SINGLE_COLUMN_LAYOUT, IS_TOUCH_ENV, } from '../../../util/environment'; @@ -56,8 +54,6 @@ type StateProps = { messageSendKeyCombo?: ISettings['messageSendKeyCombo']; }; -type DispatchProps = Pick; - const MAX_INPUT_HEIGHT = IS_SINGLE_COLUMN_LAYOUT ? 256 : 416; const TAB_INDEX_PRIORITY_TIMEOUT = 2000; const TEXT_FORMATTER_SAFE_AREA_PX = 90; @@ -77,7 +73,7 @@ function clearSelection() { } } -const MessageInput: FC = ({ +const MessageInput: FC = ({ id, chatId, isAttachmentModalInput, @@ -94,9 +90,12 @@ const MessageInput: FC = ({ replyingToId, noTabCapture, messageSendKeyCombo, - editLastMessage, - replyToNextMessage, }) => { + const { + editLastMessage, + replyToNextMessage, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const inputRef = useRef(null); // eslint-disable-next-line no-null/no-null @@ -420,5 +419,4 @@ export default memo(withGlobal( noTabCapture: global.isPollModalOpen || global.payment.isPaymentModalOpen, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['editLastMessage', 'replyToNextMessage']), )(MessageInput)); diff --git a/src/components/middle/composer/StickerPicker.tsx b/src/components/middle/composer/StickerPicker.tsx index 3c0f1b68c..30b2b2dc0 100644 --- a/src/components/middle/composer/StickerPicker.tsx +++ b/src/components/middle/composer/StickerPicker.tsx @@ -1,9 +1,8 @@ import React, { FC, useState, useEffect, memo, useRef, useMemo, useCallback, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiStickerSet, ApiSticker } from '../../../api/types'; import { StickerSetOrRecent } from '../../../types'; @@ -12,7 +11,6 @@ import { IS_TOUCH_ENV } from '../../../util/environment'; import { MEMO_EMPTY_ARRAY } from '../../../util/memo'; import fastSmoothScroll from '../../../util/fastSmoothScroll'; import buildClassName from '../../../util/buildClassName'; -import { pick } from '../../../util/iteratees'; import fastSmoothScrollHorizontal from '../../../util/fastSmoothScrollHorizontal'; import useAsyncRendering from '../../right/hooks/useAsyncRendering'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; @@ -43,18 +41,13 @@ type StateProps = { shouldPlay?: boolean; }; -type DispatchProps = Pick; - const SMOOTH_SCROLL_DISTANCE = 500; const HEADER_BUTTON_WIDTH = 52; // px (including margin) const STICKER_INTERSECTION_THROTTLE = 200; const stickerSetIntersections: boolean[] = []; -const StickerPicker: FC = ({ +const StickerPicker: FC = ({ className, loadAndPlay, canSendStickers, @@ -64,13 +57,16 @@ const StickerPicker: FC = ({ stickerSetsById, shouldPlay, onStickerSelect, - loadStickerSets, - loadRecentStickers, - loadFavoriteStickers, - loadAddedStickers, - addRecentSticker, - unfaveSticker, }) => { + const { + loadStickerSets, + loadRecentStickers, + loadFavoriteStickers, + loadAddedStickers, + addRecentSticker, + unfaveSticker, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); // eslint-disable-next-line no-null/no-null @@ -296,12 +292,4 @@ export default memo(withGlobal( shouldPlay: global.settings.byKey.shouldLoopStickers, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadStickerSets', - 'loadRecentStickers', - 'loadFavoriteStickers', - 'loadAddedStickers', - 'addRecentSticker', - 'unfaveSticker', - ]), )(StickerPicker)); diff --git a/src/components/middle/composer/StickerTooltip.tsx b/src/components/middle/composer/StickerTooltip.tsx index 3427b22ed..c442254ca 100644 --- a/src/components/middle/composer/StickerTooltip.tsx +++ b/src/components/middle/composer/StickerTooltip.tsx @@ -1,16 +1,14 @@ import React, { FC, memo, useEffect, useRef, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ApiSticker } from '../../../api/types'; -import { GlobalActions } from '../../../global/types'; import { STICKER_SIZE_PICKER } from '../../../config'; import { IS_TOUCH_ENV } from '../../../util/environment'; import buildClassName from '../../../util/buildClassName'; import captureEscKeyListener from '../../../util/captureEscKeyListener'; -import { pick } from '../../../util/iteratees'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; import useShowTransition from '../../../hooks/useShowTransition'; import usePrevious from '../../../hooks/usePrevious'; @@ -29,16 +27,15 @@ type StateProps = { stickers?: ApiSticker[]; }; -type DispatchProps = Pick; - const INTERSECTION_THROTTLE = 200; -const StickerTooltip: FC = ({ +const StickerTooltip: FC = ({ isOpen, onStickerSelect, stickers, - clearStickersForEmoji, }) => { + const { clearStickersForEmoji } = getDispatch(); + // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); const { shouldRender, transitionClassNames } = useShowTransition(isOpen, undefined, undefined, false); @@ -96,5 +93,4 @@ export default memo(withGlobal( return { stickers }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['clearStickersForEmoji']), )(StickerTooltip)); diff --git a/src/components/middle/composer/WebPagePreview.tsx b/src/components/middle/composer/WebPagePreview.tsx index 1d4bd4c04..51777a978 100644 --- a/src/components/middle/composer/WebPagePreview.tsx +++ b/src/components/middle/composer/WebPagePreview.tsx @@ -1,15 +1,13 @@ import React, { FC, memo, useEffect, useMemo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiMessage, ApiMessageEntityTypes, ApiWebPage } from '../../../api/types'; import { ISettings } from '../../../types'; import { RE_LINK_TEMPLATE } from '../../../config'; import { selectNoWebPage, selectTheme } from '../../../modules/selectors'; -import { pick } from '../../../util/iteratees'; import parseMessageInput from '../../../util/parseMessageInput'; import useOnChange from '../../../hooks/useOnChange'; import useShowTransition from '../../../hooks/useShowTransition'; @@ -33,11 +31,10 @@ type StateProps = { noWebPage?: boolean; theme: ISettings['theme']; }; -type DispatchProps = Pick; const RE_LINK = new RegExp(RE_LINK_TEMPLATE, 'i'); -const WebPagePreview: FC = ({ +const WebPagePreview: FC = ({ chatId, threadId, messageText, @@ -45,10 +42,13 @@ const WebPagePreview: FC = ({ webPagePreview, noWebPage, theme, - loadWebPagePreview, - clearWebPagePreview, - toggleMessageWebPage, }) => { + const { + loadWebPagePreview, + clearWebPagePreview, + toggleMessageWebPage, + } = getDispatch(); + const link = useMemo(() => { const { text, entities } = parseMessageInput(messageText); @@ -121,7 +121,4 @@ export default memo(withGlobal( noWebPage, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadWebPagePreview', 'clearWebPagePreview', 'toggleMessageWebPage', - ]), )(WebPagePreview)); diff --git a/src/components/middle/composer/hooks/useDraft.ts b/src/components/middle/composer/hooks/useDraft.ts index f78b43727..80106632a 100644 --- a/src/components/middle/composer/hooks/useDraft.ts +++ b/src/components/middle/composer/hooks/useDraft.ts @@ -1,7 +1,7 @@ import { useCallback, useEffect, useMemo } from '../../../../lib/teact/teact'; +import { getDispatch } from '../../../../lib/teact/teactn'; import { ApiFormattedText, ApiMessage } from '../../../../api/types'; -import { GlobalActions } from '../../../../global/types'; import { DRAFT_DEBOUNCE, EDITABLE_INPUT_ID } from '../../../../config'; import usePrevious from '../../../../hooks/usePrevious'; @@ -25,9 +25,9 @@ export default ( htmlRef: { current: string }, setHtml: (html: string) => void, editedMessage: ApiMessage | undefined, - saveDraft: GlobalActions['saveDraft'], - clearDraft: GlobalActions['clearDraft'], ) => { + const { saveDraft, clearDraft } = getDispatch(); + const updateDraft = useCallback((draftChatId: string, draftThreadId: number) => { if (htmlRef.current.length && !editedMessage) { saveDraft({ chatId: draftChatId, threadId: draftThreadId, draft: parseMessageInput(htmlRef.current!) }); diff --git a/src/components/middle/composer/hooks/useEditing.ts b/src/components/middle/composer/hooks/useEditing.ts index e41fea379..cfd51e30a 100644 --- a/src/components/middle/composer/hooks/useEditing.ts +++ b/src/components/middle/composer/hooks/useEditing.ts @@ -1,7 +1,7 @@ import { useCallback, useEffect } from '../../../../lib/teact/teact'; +import { getDispatch } from '../../../../lib/teact/teactn'; import { ApiMessage } from '../../../../api/types'; -import { GlobalActions } from '../../../../global/types'; import { EDITABLE_INPUT_ID } from '../../../../config'; import parseMessageInput from '../../../../util/parseMessageInput'; @@ -15,8 +15,9 @@ export default ( editedMessage: ApiMessage | undefined, resetComposer: () => void, openDeleteModal: () => void, - editMessage: GlobalActions['editMessage'], ) => { + const { editMessage } = getDispatch(); + // TODO useOnChange // Handle editing message useEffect(() => { diff --git a/src/components/middle/message/Album.tsx b/src/components/middle/message/Album.tsx index da7b21189..cd3b66ed5 100644 --- a/src/components/middle/message/Album.tsx +++ b/src/components/middle/message/Album.tsx @@ -1,13 +1,12 @@ import React, { FC, useCallback } from '../../../lib/teact/teact'; -import { GlobalActions, GlobalState } from '../../../global/types'; +import { GlobalState } from '../../../global/types'; import { ApiMessage } from '../../../api/types'; import { IAlbum, ISettings } from '../../../types'; import { AlbumRectPart, IAlbumLayout } from './helpers/calculateAlbumLayout'; import { getMessageContent } from '../../../modules/helpers'; -import { getGlobal, withGlobal } from '../../../lib/teact/teactn'; -import { pick } from '../../../util/iteratees'; +import { getDispatch, getGlobal, withGlobal } from '../../../lib/teact/teactn'; import withSelectControl from './hocs/withSelectControl'; import { ObserveFn } from '../../../hooks/useIntersectionObserver'; import { @@ -41,9 +40,7 @@ type StateProps = { activeDownloadIds: number[]; }; -type DispatchProps = Pick; - -const Album: FC = ({ +const Album: FC = ({ album, observeIntersection, hasCustomAppendix, @@ -54,8 +51,9 @@ const Album: FC = ({ uploadsById, activeDownloadIds, theme, - cancelSendingMessage, }) => { + const { cancelSendingMessage } = getDispatch(); + const mediaCount = album.messages.length; const handleCancelUpload = useCallback((message: ApiMessage) => { @@ -139,7 +137,4 @@ export default withGlobal( activeDownloadIds, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'cancelSendingMessage', - ]), )(Album); diff --git a/src/components/middle/message/CommentButton.tsx b/src/components/middle/message/CommentButton.tsx index 84973bb3c..3ff995073 100644 --- a/src/components/middle/message/CommentButton.tsx +++ b/src/components/middle/message/CommentButton.tsx @@ -1,12 +1,11 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { getGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, getGlobal } from '../../../lib/teact/teactn'; import { ApiChat, ApiThreadInfo, ApiUser, } from '../../../api/types'; -import { GlobalActions } from '../../../global/types'; import { isUserId } from '../../../modules/helpers'; import { formatIntegerCompact } from '../../../util/textFormat'; @@ -20,14 +19,14 @@ import './CommentButton.scss'; type OwnProps = { threadInfo: ApiThreadInfo; disabled?: boolean; - openChat: GlobalActions['openChat']; }; const CommentButton: FC = ({ threadInfo, disabled, - openChat, }) => { + const { openChat } = getDispatch(); + const lang = useLang(); const { threadId, chatId, messagesCount, lastMessageId, lastReadInboxMessageId, recentReplierIds, diff --git a/src/components/middle/message/Contact.tsx b/src/components/middle/message/Contact.tsx index f1240ceb1..bfd90102c 100644 --- a/src/components/middle/message/Contact.tsx +++ b/src/components/middle/message/Contact.tsx @@ -1,17 +1,15 @@ import React, { FC, useCallback } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiUser, ApiContact, ApiCountryCode } from '../../../api/types'; import { selectUser } from '../../../modules/selectors'; import { formatPhoneNumberWithCode } from '../../../util/phoneNumber'; +import buildClassName from '../../../util/buildClassName'; import Avatar from '../../common/Avatar'; import './Contact.scss'; -import { pick } from '../../../util/iteratees'; -import buildClassName from '../../../util/buildClassName'; type OwnProps = { contact: ApiContact; @@ -22,11 +20,11 @@ type StateProps = { phoneCodeList: ApiCountryCode[]; }; -type DispatchProps = Pick; - -const Contact: FC = ({ - contact, user, openUserInfo, phoneCodeList, +const Contact: FC = ({ + contact, user, phoneCodeList, }) => { + const { openUserInfo } = getDispatch(); + const { firstName, lastName, @@ -60,7 +58,4 @@ export default withGlobal( phoneCodeList, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'openUserInfo', - ]), )(Contact); diff --git a/src/components/middle/message/ContextMenuContainer.tsx b/src/components/middle/message/ContextMenuContainer.tsx index 2cf8d186e..7c92b03d8 100644 --- a/src/components/middle/message/ContextMenuContainer.tsx +++ b/src/components/middle/message/ContextMenuContainer.tsx @@ -1,9 +1,9 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { getGlobal, withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, getGlobal, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions, MessageListType } from '../../../global/types'; +import { MessageListType } from '../../../global/types'; import { ApiMessage } from '../../../api/types'; import { IAlbum, IAnchorPosition } from '../../../types'; import { @@ -14,7 +14,6 @@ import { } from '../../../modules/selectors'; import { isChatGroup, isOwnMessage } from '../../../modules/helpers'; import { SEEN_BY_MEMBERS_EXPIRE, SEEN_BY_MEMBERS_CHAT_MAX } from '../../../config'; -import { pick } from '../../../util/iteratees'; import { getDayStartAt } from '../../../util/dateFormat'; import { copyTextToClipboard } from '../../../util/clipboard'; import useShowTransition from '../../../hooks/useShowTransition'; @@ -58,14 +57,7 @@ type StateProps = { canShowSeenBy?: boolean; }; -type DispatchProps = Pick; - -const ContextMenuContainer: FC = ({ +const ContextMenuContainer: FC = ({ isOpen, messageListType, chatUsername, @@ -92,20 +84,23 @@ const ContextMenuContainer: FC = ({ canDownload, activeDownloads, canShowSeenBy, - setReplyingToId, - setEditingId, - pinMessage, - openForwardMenu, - faveSticker, - unfaveSticker, - toggleMessageSelection, - sendScheduledMessages, - rescheduleMessage, - downloadMessageMedia, - cancelMessageMediaDownload, - loadSeenBy, - openSeenByModal, }) => { + const { + setReplyingToId, + setEditingId, + pinMessage, + openForwardMenu, + faveSticker, + unfaveSticker, + toggleMessageSelection, + sendScheduledMessages, + rescheduleMessage, + downloadMessageMedia, + cancelMessageMediaDownload, + loadSeenBy, + openSeenByModal, + } = getDispatch(); + const { transitionClassNames } = useShowTransition(isOpen, onCloseAnimationEnd, undefined, false); const [isMenuOpen, setIsMenuOpen] = useState(true); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); @@ -393,19 +388,4 @@ export default memo(withGlobal( canShowSeenBy, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'setReplyingToId', - 'setEditingId', - 'pinMessage', - 'openForwardMenu', - 'faveSticker', - 'unfaveSticker', - 'toggleMessageSelection', - 'sendScheduledMessages', - 'rescheduleMessage', - 'downloadMessageMedia', - 'cancelMessageMediaDownload', - 'loadSeenBy', - 'openSeenByModal', - ]), )(ContextMenuContainer)); diff --git a/src/components/middle/message/MentionLink.tsx b/src/components/middle/message/MentionLink.tsx index 48fb32b83..bc9e9f41c 100644 --- a/src/components/middle/message/MentionLink.tsx +++ b/src/components/middle/message/MentionLink.tsx @@ -1,10 +1,8 @@ import React, { FC } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiChat, ApiUser } from '../../../api/types'; -import { pick } from '../../../util/iteratees'; import { selectUser } from '../../../modules/selectors'; type OwnProps = { @@ -17,15 +15,16 @@ type StateProps = { userOrChat?: ApiUser | ApiChat; }; -type DispatchProps = Pick; - -const MentionLink: FC = ({ +const MentionLink: FC = ({ username, userOrChat, children, - openChat, - openChatByUsername, }) => { + const { + openChat, + openChatByUsername, + } = getDispatch(); + const handleClick = () => { if (userOrChat) { openChat({ id: userOrChat.id }); @@ -47,5 +46,4 @@ export default withGlobal( userOrChat: userId ? selectUser(global, userId) : undefined, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['openChat', 'openChatByUsername']), )(MentionLink); diff --git a/src/components/middle/message/Message.tsx b/src/components/middle/message/Message.tsx index c9a284072..84e855a48 100644 --- a/src/components/middle/message/Message.tsx +++ b/src/components/middle/message/Message.tsx @@ -6,9 +6,9 @@ import React, { useMemo, useRef, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions, MessageListType } from '../../../global/types'; +import { MessageListType } from '../../../global/types'; import { ApiMessage, ApiMessageOutgoingStatus, @@ -22,7 +22,6 @@ import { } from '../../../types'; import { IS_ANDROID, IS_TOUCH_ENV } from '../../../util/environment'; -import { pick } from '../../../util/iteratees'; import { selectChat, selectChatMessage, @@ -165,10 +164,6 @@ type StateProps = { threadInfo?: ApiThreadInfo; }; -type DispatchProps = Pick; - const NBSP = '\u00A0'; const GROUP_MESSAGE_HOVER_ATTRIBUTE = 'data-is-document-group-hover'; // eslint-disable-next-line max-len @@ -178,7 +173,7 @@ const APPENDIX_NOT_OWN = { __html: ' ) : undefined} - {withCommentButton && } + {withCommentButton && } {withAppendix && (
)} @@ -911,10 +908,4 @@ export default memo(withGlobal( ...(isFocused && { focusDirection, noFocusHighlight, isResizingContainer }), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'toggleMessageSelection', - 'clickInlineButton', - 'disableContextMenuHint', - 'openChat', - ]), )(Message)); diff --git a/src/components/middle/message/Poll.tsx b/src/components/middle/message/Poll.tsx index bb37c614f..f47a68469 100644 --- a/src/components/middle/message/Poll.tsx +++ b/src/components/middle/message/Poll.tsx @@ -7,14 +7,12 @@ import React, { useMemo, useRef, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiMessage, ApiPoll, ApiUser, ApiPollAnswer, } from '../../../api/types'; -import { pick } from '../../../util/iteratees'; import renderText from '../../common/helpers/renderText'; import { renderTextWithEntities } from '../../common/helpers/renderMessageText'; import { formatMediaDuration } from '../../../util/dateFormat'; @@ -41,22 +39,20 @@ type StateProps = { serverTimeOffset: number; }; -type DispatchProps = Pick; - const SOLUTION_CONTAINER_ID = '#middle-column-portals'; const SOLUTION_DURATION = 5000; const NBSP = '\u00A0'; -const Poll: FC = ({ +const Poll: FC = ({ message, poll, recentVoterIds, usersById, - loadMessage, onSendVote, - openPollResults, serverTimeOffset, }) => { + const { loadMessage, openPollResults } = getDispatch(); + const { id: messageId, chatId } = message; const { summary, results } = poll; const [isSubmitting, setIsSubmitting] = useState(false); @@ -372,5 +368,4 @@ export default memo(withGlobal( serverTimeOffset, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadMessage', 'openPollResults']), )(Poll)); diff --git a/src/components/middle/message/hocs/withSelectControl.tsx b/src/components/middle/message/hocs/withSelectControl.tsx index a5d76e57b..be3c947b0 100644 --- a/src/components/middle/message/hocs/withSelectControl.tsx +++ b/src/components/middle/message/hocs/withSelectControl.tsx @@ -5,38 +5,35 @@ import React, { useMemo, memo, } from '../../../../lib/teact/teact'; -import { withGlobal } from '../../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../../lib/teact/teactn'; import { OwnProps as PhotoProps } from '../Photo'; import { OwnProps as VideoProps } from '../Video'; import buildClassName from '../../../../util/buildClassName'; -import { GlobalActions } from '../../../../global/types'; import { selectIsInSelectMode, selectIsMessageSelected, } from '../../../../modules/selectors'; -import { pick } from '../../../../util/iteratees'; - -type OwnProps = PhotoProps & VideoProps; +type OwnProps = + PhotoProps + & VideoProps; type StateProps = { isInSelectMode?: boolean; isSelected?: boolean; }; -type DispatchProps = Pick; - export default function withSelectControl(WrappedComponent: FC) { - const ComponentWithSelectControl: FC = (props) => { + const ComponentWithSelectControl: FC = (props) => { const { isInSelectMode, isSelected, message, - toggleMessageSelection, dimensions, } = props; + const { toggleMessageSelection } = getDispatch(); const handleMessageSelect = useCallback((e: ReactMouseEvent) => { e.stopPropagation(); @@ -59,12 +56,7 @@ export default function withSelectControl(WrappedComponent: FC) { return (
pick(actions, [ - 'toggleMessageSelection', - ]), )(ComponentWithSelectControl)); } diff --git a/src/components/payment/PaymentModal.tsx b/src/components/payment/PaymentModal.tsx index 4f0832406..b926bb1ef 100644 --- a/src/components/payment/PaymentModal.tsx +++ b/src/components/payment/PaymentModal.tsx @@ -1,12 +1,11 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions, GlobalState } from '../../global/types'; +import { GlobalState } from '../../global/types'; import { PaymentStep, ShippingOption, Price } from '../../types'; -import { pick } from '../../util/iteratees'; import { formatCurrency } from '../../util/formatCurrency'; import { detectCardTypeText } from '../common/helpers/detectCardType'; import usePaymentReducer, { FormState } from '../../hooks/reducers/usePaymentReducer'; @@ -46,14 +45,13 @@ type StateProps = { needZip?: boolean; }; -type GlobalStateProps = Pick; +type GlobalStateProps = Pick; -type DispatchProps = Pick; - -const Invoice: FC = ({ +const Invoice: FC = ({ isOpen, onClose, step, @@ -76,12 +74,15 @@ const Invoice: FC = ({ needCountry, needZip, error, - validateRequestedInfo, - sendPaymentForm, - setPaymentStep, - sendCredentialsInfo, - clearPaymentError, }) => { + const { + validateRequestedInfo, + sendPaymentForm, + setPaymentStep, + sendCredentialsInfo, + clearPaymentError, + } = getDispatch(); + const [paymentState, paymentDispatch] = usePaymentReducer(); const [isLoading, setIsLoading] = useState(false); const lang = useLang(); @@ -250,7 +251,8 @@ const Invoice: FC = ({ case PaymentStep.Checkout: return sendForm(); default: - return () => {}; + return () => { + }; } }, [step, validateRequest, setStep, sendCredentials, sendForm]); @@ -399,15 +401,6 @@ export default memo(withGlobal( error, }; }, - (setGlobal, actions): DispatchProps => { - return pick(actions, [ - 'validateRequestedInfo', - 'sendPaymentForm', - 'setPaymentStep', - 'sendCredentialsInfo', - 'clearPaymentError', - ]); - }, )(Invoice)); function findShippingOption(shippingOptions: ShippingOption[], optionId: string) { diff --git a/src/components/right/AddChatMembers.tsx b/src/components/right/AddChatMembers.tsx index aec1969a5..fa78c5785 100644 --- a/src/components/right/AddChatMembers.tsx +++ b/src/components/right/AddChatMembers.tsx @@ -1,15 +1,14 @@ import React, { FC, useCallback, useMemo, memo, useState, useEffect, } from '../../lib/teact/teact'; -import { getGlobal, withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, getGlobal, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiChat, ApiChatMember, ApiUpdateConnectionStateType, } from '../../api/types'; import { NewChatMembersProgress } from '../../types'; -import { pick, unique } from '../../util/iteratees'; +import { unique } from '../../util/iteratees'; import { selectChat } from '../../modules/selectors'; import { filterUsersByName, isChatChannel, isUserBot, sortChatIds, @@ -45,9 +44,7 @@ type StateProps = { globalUserIds?: string[]; }; -type DispatchProps = Pick; - -const AddChatMembers: FC = ({ +const AddChatMembers: FC = ({ isChannel, connectionState, members, @@ -60,11 +57,11 @@ const AddChatMembers: FC = ({ isSearching, localUserIds, globalUserIds, - setUserSearchQuery, onClose, isActive, - loadContactList, }) => { + const { setUserSearchQuery, loadContactList } = getDispatch(); + const lang = useLang(); const [selectedMemberIds, setSelectedMemberIds] = useState([]); const prevSelectedMemberIds = usePrevious(selectedMemberIds); @@ -184,5 +181,4 @@ export default memo(withGlobal( connectionState, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadContactList', 'setUserSearchQuery']), )(AddChatMembers)); diff --git a/src/components/right/DeleteMemberModal.tsx b/src/components/right/DeleteMemberModal.tsx index 1bf6e3d5f..feab7e857 100644 --- a/src/components/right/DeleteMemberModal.tsx +++ b/src/components/right/DeleteMemberModal.tsx @@ -1,10 +1,8 @@ import React, { FC, useCallback, memo } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiChat } from '../../api/types'; -import { pick } from '../../util/iteratees'; import { selectCurrentChat, selectUser } from '../../modules/selectors'; import { getUserFirstOrLastName } from '../../modules/helpers'; import renderText from '../common/helpers/renderText'; @@ -24,16 +22,15 @@ type StateProps = { contactName?: string; }; -type DispatchProps = Pick; - -const DeleteMemberModal: FC = ({ +const DeleteMemberModal: FC = ({ isOpen, chat, userId, contactName, onClose, - deleteChatMember, }) => { + const { deleteChatMember } = getDispatch(); + const lang = useLang(); const handleDeleteChatMember = useCallback(() => { @@ -73,5 +70,4 @@ export default memo(withGlobal( contactName, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['deleteChatMember']), )(DeleteMemberModal)); diff --git a/src/components/right/GifSearch.tsx b/src/components/right/GifSearch.tsx index 42146be24..72e7135ac 100644 --- a/src/components/right/GifSearch.tsx +++ b/src/components/right/GifSearch.tsx @@ -1,9 +1,8 @@ import React, { FC, memo, useRef, useCallback, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ApiChat, ApiVideo } from '../../api/types'; import { IS_TOUCH_ENV } from '../../util/environment'; @@ -14,7 +13,6 @@ import { selectCurrentMessageList, } from '../../modules/selectors'; import { getAllowedAttachmentOptions } from '../../modules/helpers'; -import { pick } from '../../util/iteratees'; import buildClassName from '../../util/buildClassName'; import { useIntersectionObserver } from '../../hooks/useIntersectionObserver'; import useLang from '../../hooks/useLang'; @@ -38,22 +36,23 @@ type StateProps = { isChatWithBot?: boolean; }; -type DispatchProps = Pick; - const PRELOAD_BACKWARDS = 96; // GIF Search bot results are multiplied by 24 const INTERSECTION_DEBOUNCE = 300; -const GifSearch: FC = ({ +const GifSearch: FC = ({ onClose, isActive, query, results, chat, isChatWithBot, - searchMoreGifs, - sendMessage, - setGifSearchQuery, }) => { + const { + searchMoreGifs, + sendMessage, + setGifSearchQuery, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); @@ -138,5 +137,4 @@ export default memo(withGlobal( isChatWithBot, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['searchMoreGifs', 'sendMessage', 'setGifSearchQuery']), )(GifSearch)); diff --git a/src/components/right/PollAnswerResults.tsx b/src/components/right/PollAnswerResults.tsx index 9e5073587..bb8adea51 100644 --- a/src/components/right/PollAnswerResults.tsx +++ b/src/components/right/PollAnswerResults.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, useState, memo, useEffect, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { ApiChat, @@ -9,8 +9,6 @@ import { ApiPollAnswer, ApiPollResult, } from '../../api/types'; -import { GlobalActions } from '../../global/types'; -import { pick } from '../../util/iteratees'; import usePrevious from '../../hooks/usePrevious'; import useLang from '../../hooks/useLang'; @@ -34,12 +32,10 @@ type StateProps = { offset: string; }; -type DispatchProps = Pick; - const INITIAL_LIMIT = 4; const VIEW_MORE_LIMIT = 50; -const PollAnswerResults: FC = ({ +const PollAnswerResults: FC = ({ chat, message, answer, @@ -47,10 +43,13 @@ const PollAnswerResults: FC = ({ totalVoters, voters, offset, - loadPollOptionResults, - openChat, - closePollResults, }) => { + const { + loadPollOptionResults, + openChat, + closePollResults, + } = getDispatch(); + const prevVotersCount = usePrevious(answerVote.votersCount); const [isLoading, setIsLoading] = useState(true); const areVotersLoaded = Boolean(voters); @@ -140,5 +139,4 @@ export default memo(withGlobal( offset: (offsets?.[answer.option]) || '', }; }, - (global, actions): DispatchProps => pick(actions, ['loadPollOptionResults', 'openChat', 'closePollResults']), )(PollAnswerResults)); diff --git a/src/components/right/Profile.tsx b/src/components/right/Profile.tsx index 4bb1b1fb8..b9e907a4f 100644 --- a/src/components/right/Profile.tsx +++ b/src/components/right/Profile.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, useEffect, useMemo, useRef, useState, memo, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { MAIN_THREAD_ID, @@ -11,7 +11,6 @@ import { ApiUser, ApiUserStatus, } from '../../api/types'; -import { GlobalActions } from '../../global/types'; import { NewChatMembersProgress, ISettings, MediaViewerOrigin, ProfileState, ProfileTabType, SharedMediaType, AudioOrigin, } from '../../types'; @@ -35,7 +34,6 @@ import { selectActiveDownloadIds, selectUser, } from '../../modules/selectors'; -import { pick } from '../../util/iteratees'; import { captureEvents, SwipeDirection } from '../../util/captureEvents'; import { getSenderName } from '../left/search/helpers/getSenderName'; import useCacheBuster from '../../hooks/useCacheBuster'; @@ -96,12 +94,6 @@ type StateProps = { activeDownloadIds: number[]; }; -type DispatchProps = Pick; - const TABS = [ { type: 'media', title: 'SharedMediaTab2' }, { type: 'documents', title: 'SharedFilesTab2' }, @@ -112,7 +104,7 @@ const TABS = [ const HIDDEN_RENDER_DELAY = 1000; -const Profile: FC = ({ +const Profile: FC = ({ chatId, profileState, onProfileStateChange, @@ -138,18 +130,21 @@ const Profile: FC = ({ lastSyncTime, activeDownloadIds, serverTimeOffset, - setLocalMediaSearchType, - loadMoreMembers, - loadCommonChats, - openChat, - searchMediaMessagesLocal, - openMediaViewer, - openAudioPlayer, - openUserInfo, - focusMessage, - loadProfilePhotos, - setNewChatMembersDialogState, }) => { + const { + setLocalMediaSearchType, + loadMoreMembers, + loadCommonChats, + openChat, + searchMediaMessagesLocal, + openMediaViewer, + openAudioPlayer, + openUserInfo, + focusMessage, + loadProfilePhotos, + setNewChatMembersDialogState, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); // eslint-disable-next-line no-null/no-null @@ -542,17 +537,4 @@ export default memo(withGlobal( ...(hasCommonChatsTab && user && { commonChatIds: user.commonChats?.ids }), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'setLocalMediaSearchType', - 'loadMoreMembers', - 'searchMediaMessagesLocal', - 'openMediaViewer', - 'openAudioPlayer', - 'openUserInfo', - 'focusMessage', - 'loadProfilePhotos', - 'setNewChatMembersDialogState', - 'loadCommonChats', - 'openChat', - ]), )(Profile)); diff --git a/src/components/right/RightColumn.tsx b/src/components/right/RightColumn.tsx index 2b930247b..073eff4cd 100644 --- a/src/components/right/RightColumn.tsx +++ b/src/components/right/RightColumn.tsx @@ -1,16 +1,14 @@ import React, { FC, memo, useCallback, useEffect, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ManagementScreens, NewChatMembersProgress, ProfileState, RightColumnContent, } from '../../types'; import { MIN_SCREEN_WIDTH_FOR_STATIC_RIGHT_COLUMN } from '../../config'; import captureEscKeyListener from '../../util/captureEscKeyListener'; -import { pick } from '../../util/iteratees'; import { selectAreActiveChatsLoaded, selectCurrentMessageList, @@ -42,12 +40,6 @@ type StateProps = { shouldSkipHistoryAnimations?: boolean; }; -type DispatchProps = Pick; - const COLUMN_CLOSE_DELAY_MS = 300; const MAIN_SCREENS_COUNT = Object.keys(RightColumnContent).length / 2; const MANAGEMENT_SCREENS_COUNT = Object.keys(ManagementScreens).length / 2; @@ -59,23 +51,26 @@ function blurSearchInput() { } } -const RightColumn: FC = ({ +const RightColumn: FC = ({ contentKey, chatId, threadId, currentProfileUserId, isChatSelected, - toggleChatInfo, - toggleManagement, - openUserInfo, - closeLocalTextSearch, - setStickerSearchQuery, - setGifSearchQuery, - closePollResults, - addChatMembers, - setNewChatMembersDialogState, shouldSkipHistoryAnimations, }) => { + const { + toggleChatInfo, + toggleManagement, + openUserInfo, + closeLocalTextSearch, + setStickerSearchQuery, + setGifSearchQuery, + closePollResults, + addChatMembers, + setNewChatMembersDialogState, + } = getDispatch(); + const { width: windowWidth } = useWindowSize(); const [profileState, setProfileState] = useState(ProfileState.Profile); const [managementScreen, setManagementScreen] = useState(ManagementScreens.Initial); @@ -314,15 +309,4 @@ export default memo(withGlobal( shouldSkipHistoryAnimations: global.shouldSkipHistoryAnimations, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'openUserInfo', - 'toggleChatInfo', - 'toggleManagement', - 'closeLocalTextSearch', - 'setStickerSearchQuery', - 'setGifSearchQuery', - 'closePollResults', - 'addChatMembers', - 'setNewChatMembersDialogState', - ]), )(RightColumn)); diff --git a/src/components/right/RightHeader.tsx b/src/components/right/RightHeader.tsx index cabfdacea..f7077ce91 100644 --- a/src/components/right/RightHeader.tsx +++ b/src/components/right/RightHeader.tsx @@ -1,14 +1,12 @@ import React, { FC, memo, useCallback, useEffect, useRef, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; import { ManagementScreens, ProfileState } from '../../types'; import { IS_SINGLE_COLUMN_LAYOUT } from '../../util/environment'; import { debounce } from '../../util/schedulers'; -import { pick } from '../../util/iteratees'; import buildClassName from '../../util/buildClassName'; import { selectChat, @@ -59,11 +57,6 @@ type StateProps = { gifSearchQuery?: string; }; -type DispatchProps = Pick; - const COLUMN_CLOSE_DELAY_MS = 300; const runDebouncedForSearch = debounce((cb) => cb(), 200, false); @@ -91,7 +84,7 @@ enum HeaderContent { AddingMembers, } -const RightHeader: FC = ({ +const RightHeader: FC = ({ isColumnOpen, isProfile, isSearch, @@ -110,15 +103,17 @@ const RightHeader: FC = ({ messageSearchQuery, stickerSearchQuery, gifSearchQuery, - setLocalTextSearchQuery, - setStickerSearchQuery, - setGifSearchQuery, - searchTextMessagesLocal, - toggleManagement, - openHistoryCalendar, shouldSkipAnimation, - addContact, }) => { + const { + setLocalTextSearchQuery, + setStickerSearchQuery, + setGifSearchQuery, + searchTextMessagesLocal, + toggleManagement, + openHistoryCalendar, addContact, + } = getDispatch(); + // eslint-disable-next-line no-null/no-null const backButtonRef = useRef(null); @@ -372,13 +367,4 @@ export default memo(withGlobal( gifSearchQuery, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'setLocalTextSearchQuery', - 'setStickerSearchQuery', - 'setGifSearchQuery', - 'searchTextMessagesLocal', - 'toggleManagement', - 'openHistoryCalendar', - 'addContact', - ]), )(RightHeader)); diff --git a/src/components/right/RightSearch.tsx b/src/components/right/RightSearch.tsx index 2462e220c..65f34ef1f 100644 --- a/src/components/right/RightSearch.tsx +++ b/src/components/right/RightSearch.tsx @@ -1,10 +1,9 @@ import React, { FC, useMemo, memo, useRef, } from '../../lib/teact/teact'; -import { getGlobal, withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, getGlobal, withGlobal } from '../../lib/teact/teactn'; import { ApiMessage, ApiUser, ApiChat } from '../../api/types'; -import { GlobalActions } from '../../global/types'; import { selectUser, @@ -20,7 +19,7 @@ import { } from '../../modules/helpers'; import renderText from '../common/helpers/renderText'; import useLang from '../../hooks/useLang'; -import { orderBy, pick } from '../../util/iteratees'; +import { orderBy } from '../../util/iteratees'; import { MEMO_EMPTY_ARRAY } from '../../util/memo'; import useKeyboardListNavigation from '../../hooks/useKeyboardListNavigation'; import useHistoryBack from '../../hooks/useHistoryBack'; @@ -47,8 +46,6 @@ type StateProps = { foundIds?: number[]; }; -type DispatchProps = Pick; - interface Result { message: ApiMessage; senderUser?: ApiUser; @@ -56,7 +53,7 @@ interface Result { onClick: NoneToVoidFunction; } -const RightSearch: FC = ({ +const RightSearch: FC = ({ chatId, threadId, onClose, @@ -66,9 +63,12 @@ const RightSearch: FC = ({ query, totalCount, foundIds, - searchTextMessagesLocal, - focusMessage, }) => { + const { + searchTextMessagesLocal, + focusMessage, + } = getDispatch(); + const lang = useLang(); const foundResults = useMemo(() => { @@ -186,5 +186,4 @@ export default memo(withGlobal( foundIds, }; }, - (global, actions): DispatchProps => pick(actions, ['searchTextMessagesLocal', 'focusMessage']), )(RightSearch)); diff --git a/src/components/right/StickerSearch.tsx b/src/components/right/StickerSearch.tsx index 853c2cd2f..311514d67 100644 --- a/src/components/right/StickerSearch.tsx +++ b/src/components/right/StickerSearch.tsx @@ -1,11 +1,8 @@ import React, { FC, memo, useEffect, useRef, useState, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; -import { GlobalActions } from '../../global/types'; - -import { pick } from '../../util/iteratees'; import { throttle } from '../../util/schedulers'; import { selectCurrentStickerSearch } from '../../modules/selectors'; import { useIntersectionObserver } from '../../hooks/useIntersectionObserver'; @@ -28,20 +25,19 @@ type StateProps = { resultIds?: string[]; }; -type DispatchProps = Pick; - const INTERSECTION_THROTTLE = 200; const runThrottled = throttle((cb) => cb(), 60000, true); -const StickerSearch: FC = ({ +const StickerSearch: FC = ({ onClose, isActive, query, featuredIds, resultIds, - loadFeaturedStickers, }) => { + const { loadFeaturedStickers } = getDispatch(); + // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); @@ -118,5 +114,4 @@ export default memo(withGlobal( resultIds, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadFeaturedStickers']), )(StickerSearch)); diff --git a/src/components/right/StickerSetResult.tsx b/src/components/right/StickerSetResult.tsx index a58b8e8cb..417eeb31b 100644 --- a/src/components/right/StickerSetResult.tsx +++ b/src/components/right/StickerSetResult.tsx @@ -1,14 +1,12 @@ import React, { FC, useEffect, memo, useMemo, useCallback, } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { ApiStickerSet } from '../../api/types'; -import { GlobalActions } from '../../global/types'; import { ObserveFn } from '../../hooks/useIntersectionObserver'; import { STICKER_SIZE_SEARCH } from '../../config'; -import { pick } from '../../util/iteratees'; import { selectShouldLoopStickers, selectStickerSet } from '../../modules/selectors'; import useFlag from '../../hooks/useFlag'; import useOnChange from '../../hooks/useOnChange'; @@ -31,14 +29,14 @@ type StateProps = { shouldPlay?: boolean; }; -type DispatchProps = Pick; - const STICKERS_TO_DISPLAY = 5; -const StickerSetResult: FC = ({ +const StickerSetResult: FC = ({ stickerSetId, observeIntersection, set, shouldPlay, - loadStickers, toggleStickerSet, isSomeModalOpen, onModalToggle, + isSomeModalOpen, onModalToggle, }) => { + const { loadStickers, toggleStickerSet } = getDispatch(); + const lang = useLang(); const isAdded = set && Boolean(set.installedDate); const areStickersLoaded = Boolean(set?.stickers); @@ -125,5 +123,4 @@ export default memo(withGlobal( shouldPlay: selectShouldLoopStickers(global), }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadStickers', 'toggleStickerSet']), )(StickerSetResult)); diff --git a/src/components/right/management/ManageChannel.tsx b/src/components/right/management/ManageChannel.tsx index c944e8cce..a6246f952 100644 --- a/src/components/right/management/ManageChannel.tsx +++ b/src/components/right/management/ManageChannel.tsx @@ -2,13 +2,11 @@ import { ChangeEvent } from 'react'; import React, { FC, memo, useCallback, useEffect, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ManagementScreens, ManagementProgress } from '../../../types'; import { ApiChat, ApiMediaFormat } from '../../../api/types'; -import { pick } from '../../../util/iteratees'; import { getChatAvatarHash, getHasAdminRight } from '../../../modules/helpers'; import useMedia from '../../../hooks/useMedia'; import useLang from '../../../hooks/useLang'; @@ -40,28 +38,27 @@ type StateProps = { canChangeInfo?: boolean; }; -type DispatchProps = Pick; - const CHANNEL_TITLE_EMPTY = 'Channel title can\'t be empty'; -const ManageChannel: FC = ({ +const ManageChannel: FC = ({ chatId, chat, progress, isSignaturesShown, canChangeInfo, onScreenSelect, - updateChat, - toggleSignatures, - closeManagement, - leaveChannel, - deleteChannel, - openChat, onClose, isActive, }) => { + const { + updateChat, + toggleSignatures, + closeManagement, + leaveChannel, + deleteChannel, + openChat, + } = getDispatch(); + const currentTitle = chat ? (chat.title || '') : ''; const currentAbout = chat?.fullInfo ? (chat.fullInfo.about || '') : ''; const hasLinkedChat = chat?.fullInfo?.linkedChatId; @@ -266,7 +263,4 @@ export default memo(withGlobal( canChangeInfo: getHasAdminRight(chat, 'changeInfo'), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'toggleSignatures', 'updateChat', 'closeManagement', 'leaveChannel', 'deleteChannel', 'openChat', - ]), )(ManageChannel)); diff --git a/src/components/right/management/ManageChatAdministrators.tsx b/src/components/right/management/ManageChatAdministrators.tsx index fc6e119f4..906a93766 100644 --- a/src/components/right/management/ManageChatAdministrators.tsx +++ b/src/components/right/management/ManageChatAdministrators.tsx @@ -134,5 +134,4 @@ export default memo(withGlobal( usersById, }; }, - // (setGlobal, actions): DispatchProps => pick(actions, ['togglePreHistoryHidden', 'updateChat']), )(ManageChatAdministrators)); diff --git a/src/components/right/management/ManageChatPrivacyType.tsx b/src/components/right/management/ManageChatPrivacyType.tsx index 96fe019a8..ff131473a 100644 --- a/src/components/right/management/ManageChatPrivacyType.tsx +++ b/src/components/right/management/ManageChatPrivacyType.tsx @@ -1,14 +1,12 @@ import React, { FC, memo, useCallback, useEffect, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiChat } from '../../../api/types'; import { ManagementProgress } from '../../../types'; import { selectChat, selectManagement } from '../../../modules/selectors'; -import { pick } from '../../../util/iteratees'; import { isChatChannel } from '../../../modules/helpers'; import useFlag from '../../../hooks/useFlag'; import useLang from '../../../hooks/useLang'; @@ -23,7 +21,9 @@ import FloatingActionButton from '../../ui/FloatingActionButton'; import UsernameInput from '../../common/UsernameInput'; import ConfirmDialog from '../../ui/ConfirmDialog'; -type PrivacyType = 'private' | 'public'; +type PrivacyType = + 'private' + | 'public'; type OwnProps = { chatId: string; @@ -38,21 +38,20 @@ type StateProps = { isUsernameAvailable?: boolean; }; -type DispatchProps = Pick; - -const ManageChatPrivacyType: FC = ({ +const ManageChatPrivacyType: FC = ({ chat, onClose, isActive, isChannel, progress, isUsernameAvailable, - checkPublicLink, - updatePublicLink, - updatePrivateLink, }) => { + const { + checkPublicLink, + updatePublicLink, + updatePrivateLink, + } = getDispatch(); + const isPublic = Boolean(chat.username); const privateLink = chat.fullInfo?.inviteLink; @@ -178,7 +177,4 @@ export default memo(withGlobal( isUsernameAvailable, }; }, - (setGlobal, actions) => pick(actions, [ - 'checkPublicLink', 'updatePublicLink', 'updatePrivateLink', - ]), )(ManageChatPrivacyType)); diff --git a/src/components/right/management/ManageDiscussion.tsx b/src/components/right/management/ManageDiscussion.tsx index 3131850db..0fe7c6faf 100644 --- a/src/components/right/management/ManageDiscussion.tsx +++ b/src/components/right/management/ManageDiscussion.tsx @@ -1,15 +1,13 @@ import React, { FC, memo, useCallback, useEffect, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiChat } from '../../../api/types'; import { ManagementScreens } from '../../../types'; import { STICKER_SIZE_DISCUSSION_GROUPS } from '../../../config'; import { selectChat } from '../../../modules/selectors'; -import { pick } from '../../../util/iteratees'; import getAnimationData from '../../common/helpers/animatedAssets'; import useLang from '../../../hooks/useLang'; import useHistoryBack from '../../../hooks/useHistoryBack'; @@ -39,9 +37,7 @@ type StateProps = { isChannel?: boolean; }; -type DispatchProps = Pick; - -const ManageDiscussion: FC = ({ +const ManageDiscussion: FC = ({ chat, onClose, isActive, @@ -51,10 +47,13 @@ const ManageDiscussion: FC = ({ forDiscussionIds, isChannel, onScreenSelect, - loadGroupsForDiscussion, - linkDiscussionGroup, - unlinkDiscussionGroup, }) => { + const { + loadGroupsForDiscussion, + linkDiscussionGroup, + unlinkDiscussionGroup, + } = getDispatch(); + const [linkedGroupId, setLinkedGroupId] = useState(); const [animationData, setAnimationData] = useState>(); const [isAnimationLoaded, setIsAnimationLoaded] = useState(false); @@ -107,6 +106,7 @@ const ManageDiscussion: FC = ({
); } + function renderLinkGroupHeader() { const linkedGroup = chatsByIds[linkedGroupId]; @@ -210,7 +210,9 @@ const ManageDiscussion: FC = ({ key={id} teactOrderKey={i + 1} className="chat-item-clickable scroll-item" - onClick={() => { onDiscussionClick(id); }} + onClick={() => { + onDiscussionClick(id); + }} > @@ -273,7 +275,4 @@ export default memo(withGlobal( isChannel: chat && isChatChannel(chat), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'loadGroupsForDiscussion', 'linkDiscussionGroup', 'unlinkDiscussionGroup', - ]), )(ManageDiscussion)); diff --git a/src/components/right/management/ManageGroup.tsx b/src/components/right/management/ManageGroup.tsx index d5ec941b7..acdbe9b8b 100644 --- a/src/components/right/management/ManageGroup.tsx +++ b/src/components/right/management/ManageGroup.tsx @@ -2,11 +2,10 @@ import { ChangeEvent } from 'react'; import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ManagementScreens, ManagementProgress } from '../../../types'; import { ApiChat, ApiChatBannedRights, ApiMediaFormat } from '../../../api/types'; -import { GlobalActions } from '../../../global/types'; import { getChatAvatarHash, getHasAdminRight, isChatBasicGroup } from '../../../modules/helpers'; import useMedia from '../../../hooks/useMedia'; @@ -14,7 +13,6 @@ import useLang from '../../../hooks/useLang'; import useFlag from '../../../hooks/useFlag'; import { selectChat } from '../../../modules/selectors'; import { formatInteger } from '../../../util/textFormat'; -import { pick } from '../../../util/iteratees'; import renderText from '../../common/helpers/renderText'; import useHistoryBack from '../../../hooks/useHistoryBack'; @@ -44,18 +42,13 @@ type StateProps = { canBanUsers?: boolean; }; -type DispatchProps = Pick; - const GROUP_TITLE_EMPTY = 'Group title can\'t be empty'; // Some checkboxes control multiple rights, and some rights are not controlled from Permissions screen, // so we need to define the amount manually const TOTAL_PERMISSIONS_COUNT = 8; -const ManageGroup: FC = ({ +const ManageGroup: FC = ({ chatId, chat, progress, @@ -64,16 +57,19 @@ const ManageGroup: FC = ({ canChangeInfo, canBanUsers, onScreenSelect, - togglePreHistoryHidden, - updateChat, - deleteChat, - leaveChannel, - deleteChannel, - closeManagement, - openChat, onClose, isActive, }) => { + const { + togglePreHistoryHidden, + updateChat, + deleteChat, + leaveChannel, + deleteChannel, + closeManagement, + openChat, + } = getDispatch(); + const [isDeleteDialogOpen, openDeleteDialog, closeDeleteDialog] = useFlag(); const currentTitle = chat.title; const currentAbout = chat.fullInfo ? (chat.fullInfo.about || '') : ''; @@ -338,8 +334,4 @@ export default memo(withGlobal( canBanUsers: isBasicGroup ? chat.isCreator : getHasAdminRight(chat, 'banUsers'), }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'togglePreHistoryHidden', 'updateChat', 'closeManagement', - 'leaveChannel', 'deleteChannel', 'deleteChat', 'openChat', - ]), )(ManageGroup)); diff --git a/src/components/right/management/ManageGroupAdminRights.tsx b/src/components/right/management/ManageGroupAdminRights.tsx index 64174b7b2..1beb767b1 100644 --- a/src/components/right/management/ManageGroupAdminRights.tsx +++ b/src/components/right/management/ManageGroupAdminRights.tsx @@ -1,13 +1,11 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ApiChat, ApiChatAdminRights, ApiUser } from '../../../api/types'; import { ManagementScreens } from '../../../types'; -import { GlobalActions } from '../../../global/types'; -import { pick } from '../../../util/iteratees'; import { selectChat } from '../../../modules/selectors'; import { getUserFullName, isChatBasicGroup, isChatChannel } from '../../../modules/helpers'; import useLang from '../../../hooks/useLang'; @@ -39,11 +37,9 @@ type StateProps = { isFormFullyDisabled: boolean; }; -type DispatchProps = Pick; - const CUSTOM_TITLE_MAX_LENGTH = 16; -const ManageGroupAdminRights: FC = ({ +const ManageGroupAdminRights: FC = ({ selectedChatMemberId, onScreenSelect, chat, @@ -51,10 +47,11 @@ const ManageGroupAdminRights: FC = ({ currentUserId, isChannel, isFormFullyDisabled, - updateChatAdmin, onClose, isActive, }) => { + const { updateChatAdmin } = getDispatch(); + const [permissions, setPermissions] = useState({}); const [isTouched, setIsTouched] = useState(false); const [isLoading, setIsLoading] = useState(false); @@ -359,5 +356,4 @@ export default memo(withGlobal( isFormFullyDisabled, }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['updateChatAdmin']), )(ManageGroupAdminRights)); diff --git a/src/components/right/management/ManageGroupMembers.tsx b/src/components/right/management/ManageGroupMembers.tsx index 0188ba755..8b0499e23 100644 --- a/src/components/right/management/ManageGroupMembers.tsx +++ b/src/components/right/management/ManageGroupMembers.tsx @@ -1,13 +1,11 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ApiChatMember, ApiUser, ApiUserStatus } from '../../../api/types'; -import { GlobalActions } from '../../../global/types'; import { selectChat } from '../../../modules/selectors'; import { sortUserIds, isChatChannel } from '../../../modules/helpers'; -import { pick } from '../../../util/iteratees'; import useHistoryBack from '../../../hooks/useHistoryBack'; import PrivateChatInfo from '../../common/PrivateChatInfo'; @@ -28,18 +26,17 @@ type StateProps = { serverTimeOffset: number; }; -type DispatchProps = Pick; - -const ManageGroupMembers: FC = ({ +const ManageGroupMembers: FC = ({ members, usersById, userStatusesById, isChannel, - openUserInfo, onClose, isActive, serverTimeOffset, }) => { + const { openUserInfo } = getDispatch(); + const memberIds = useMemo(() => { if (!members || !usersById) { return undefined; @@ -103,7 +100,4 @@ export default memo(withGlobal( serverTimeOffset: global.serverTimeOffset, }; }, - (setGlobal, actions): DispatchProps => pick(actions, [ - 'openUserInfo', - ]), )(ManageGroupMembers)); diff --git a/src/components/right/management/ManageGroupPermissions.tsx b/src/components/right/management/ManageGroupPermissions.tsx index 84ca42816..1a4abfba2 100644 --- a/src/components/right/management/ManageGroupPermissions.tsx +++ b/src/components/right/management/ManageGroupPermissions.tsx @@ -1,15 +1,13 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ManagementScreens } from '../../../types'; import { ApiChat, ApiChatBannedRights, ApiChatMember } from '../../../api/types'; -import { GlobalActions } from '../../../global/types'; import useLang from '../../../hooks/useLang'; import { selectChat } from '../../../modules/selectors'; -import { pick } from '../../../util/iteratees'; import useHistoryBack from '../../../hooks/useHistoryBack'; import ListItem from '../../ui/ListItem'; @@ -31,8 +29,6 @@ type StateProps = { currentUserId?: string; }; -type DispatchProps = Pick; - const FLOATING_BUTTON_ANIMATION_TIMEOUT_MS = 250; function getLangKeyForBannedRightKey(key: string) { @@ -58,15 +54,16 @@ function getLangKeyForBannedRightKey(key: string) { } } -const ManageGroupPermissions: FC = ({ +const ManageGroupPermissions: FC = ({ onScreenSelect, onChatMemberSelect, chat, currentUserId, - updateChatDefaultBannedRights, onClose, isActive, }) => { + const { updateChatDefaultBannedRights } = getDispatch(); + const [permissions, setPermissions] = useState({}); const [havePermissionChanged, setHavePermissionChanged] = useState(false); const [isLoading, setIsLoading] = useState(false); @@ -305,5 +302,4 @@ export default memo(withGlobal( return { chat, currentUserId: global.currentUserId }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['updateChatDefaultBannedRights']), )(ManageGroupPermissions)); diff --git a/src/components/right/management/ManageGroupRemovedUsers.tsx b/src/components/right/management/ManageGroupRemovedUsers.tsx index f957acfea..5e8a0d46b 100644 --- a/src/components/right/management/ManageGroupRemovedUsers.tsx +++ b/src/components/right/management/ManageGroupRemovedUsers.tsx @@ -1,14 +1,12 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ApiChat, ApiChatMember, ApiUser } from '../../../api/types'; -import { GlobalActions } from '../../../global/types'; import { selectChat } from '../../../modules/selectors'; import { getHasAdminRight, getUserFullName } from '../../../modules/helpers'; -import { pick } from '../../../util/iteratees'; import useLang from '../../../hooks/useLang'; import useHistoryBack from '../../../hooks/useHistoryBack'; import useFlag from '../../../hooks/useFlag'; @@ -30,16 +28,15 @@ type StateProps = { canDeleteMembers?: boolean; }; -type DispatchProps = Pick; - -const ManageGroupRemovedUsers: FC = ({ +const ManageGroupRemovedUsers: FC = ({ chat, usersById, canDeleteMembers, - updateChatMemberBannedRights, onClose, isActive, }) => { + const { updateChatMemberBannedRights } = getDispatch(); + const lang = useLang(); const [isRemoveUserModalOpen, openRemoveUserModal, closeRemoveUserModal] = useFlag(); @@ -132,5 +129,4 @@ export default memo(withGlobal( return { chat, usersById, canDeleteMembers }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['updateChatMemberBannedRights']), )(ManageGroupRemovedUsers)); diff --git a/src/components/right/management/ManageGroupUserPermissions.tsx b/src/components/right/management/ManageGroupUserPermissions.tsx index 825a6ab54..05d3ff278 100644 --- a/src/components/right/management/ManageGroupUserPermissions.tsx +++ b/src/components/right/management/ManageGroupUserPermissions.tsx @@ -1,13 +1,11 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ApiChat, ApiChatBannedRights } from '../../../api/types'; import { ManagementScreens } from '../../../types'; -import { GlobalActions } from '../../../global/types'; -import { pick } from '../../../util/iteratees'; import { selectChat } from '../../../modules/selectors'; import useLang from '../../../hooks/useLang'; import useFlag from '../../../hooks/useFlag'; @@ -34,17 +32,16 @@ type StateProps = { isFormFullyDisabled?: boolean; }; -type DispatchProps = Pick; - -const ManageGroupUserPermissions: FC = ({ +const ManageGroupUserPermissions: FC = ({ chat, selectedChatMemberId, onScreenSelect, - updateChatMemberBannedRights, isFormFullyDisabled, onClose, isActive, }) => { + const { updateChatMemberBannedRights } = getDispatch(); + const [permissions, setPermissions] = useState({}); const [havePermissionChanged, setHavePermissionChanged] = useState(false); const [isLoading, setIsLoading] = useState(false); @@ -266,5 +263,4 @@ export default memo(withGlobal( return { chat, isFormFullyDisabled }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['updateChatMemberBannedRights']), )(ManageGroupUserPermissions)); diff --git a/src/components/right/management/ManageUser.tsx b/src/components/right/management/ManageUser.tsx index 3ba5641c7..6e44ad736 100644 --- a/src/components/right/management/ManageUser.tsx +++ b/src/components/right/management/ManageUser.tsx @@ -2,13 +2,11 @@ import { ChangeEvent } from 'react'; import React, { FC, memo, useCallback, useEffect, useState, } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiChat, ApiUser } from '../../../api/types'; import { ManagementProgress } from '../../../types'; -import { pick } from '../../../util/iteratees'; import { selectChat, selectNotifyExceptions, selectNotifySettings, selectUser, } from '../../../modules/selectors'; @@ -40,26 +38,25 @@ type StateProps = { isMuted?: boolean; }; -type DispatchProps = Pick; - const ERROR_FIRST_NAME_MISSING = 'Please provide first name'; -const ManageUser: FC = ({ +const ManageUser: FC = ({ userId, user, chat, progress, isMuted, - updateContact, - deleteUser, - deleteHistory, - closeManagement, - openChat, onClose, isActive, }) => { + const { + updateContact, + deleteUser, + deleteHistory, + closeManagement, + openChat, + } = getDispatch(); + const [isDeleteDialogOpen, openDeleteDialog, closeDeleteDialog] = useFlag(); const [isProfileFieldsTouched, setIsProfileFieldsTouched] = useState(false); const [error, setError] = useState(); @@ -219,7 +216,4 @@ export default memo(withGlobal( user, chat, progress, isMuted, }; }, - (global, actions): DispatchProps => pick(actions, [ - 'updateContact', 'deleteUser', 'closeManagement', 'openChat', 'deleteHistory', - ]), )(ManageUser)); diff --git a/src/components/right/management/RemoveGroupUserModal.tsx b/src/components/right/management/RemoveGroupUserModal.tsx index b9732d049..6d2896838 100644 --- a/src/components/right/management/RemoveGroupUserModal.tsx +++ b/src/components/right/management/RemoveGroupUserModal.tsx @@ -1,13 +1,11 @@ import React, { FC, useMemo, useState, memo, useRef, useCallback, } from '../../../lib/teact/teact'; -import { getGlobal, withGlobal } from '../../../lib/teact/teactn'; +import { getDispatch, getGlobal, withGlobal } from '../../../lib/teact/teactn'; -import { GlobalActions } from '../../../global/types'; import { ApiChat } from '../../../api/types'; import { filterUsersByName } from '../../../modules/helpers'; -import { pick } from '../../../util/iteratees'; import useLang from '../../../hooks/useLang'; import ChatOrUserPicker from '../../common/ChatOrUserPicker'; @@ -22,16 +20,17 @@ type StateProps = { currentUserId?: string; }; -type DispatchProps = Pick; - -const RemoveGroupUserModal: FC = ({ +const RemoveGroupUserModal: FC = ({ chat, currentUserId, isOpen, onClose, - loadMoreMembers, - deleteChatMember, }) => { + const { + loadMoreMembers, + deleteChatMember, + } = getDispatch(); + const lang = useLang(); const [filter, setFilter] = useState(''); // eslint-disable-next-line no-null/no-null @@ -78,5 +77,4 @@ export default memo(withGlobal( return { currentUserId }; }, - (setGlobal, actions): DispatchProps => pick(actions, ['loadMoreMembers', 'deleteChatMember']), )(RemoveGroupUserModal)); diff --git a/src/lib/teact/teactn.tsx b/src/lib/teact/teactn.tsx index 2b1069e81..bf7248231 100644 --- a/src/lib/teact/teactn.tsx +++ b/src/lib/teact/teactn.tsx @@ -24,8 +24,7 @@ type Reducer = ( payload: any, ) => GlobalState | void; -type MapStateToProps = ((global: GlobalState, ownProps: OwnProps) => AnyLiteral | null); -type MapActionsToProps = ((setGlobal: Function, actions: GlobalActions) => Partial | null); +type MapStateToProps = ((global: GlobalState, ownProps: OwnProps) => AnyLiteral); let currentGlobal = {} as GlobalState; @@ -34,7 +33,6 @@ const callbacks: Function[] = [updateContainers]; const actions = {} as GlobalActions; const containers = new Map; - mapReducersToProps: MapActionsToProps; ownProps: Props; mappedProps?: Props; forceUpdate: Function; @@ -94,16 +92,13 @@ function updateContainers() { // eslint-disable-next-line no-restricted-syntax for (const container of containers.values()) { const { - mapStateToProps, mapReducersToProps, ownProps, mappedProps, forceUpdate, + mapStateToProps, ownProps, mappedProps, forceUpdate, } = container; let newMappedProps; try { - newMappedProps = { - ...mapStateToProps(currentGlobal, ownProps), - ...mapReducersToProps(setGlobal, actions), - }; + newMappedProps = mapStateToProps(currentGlobal, ownProps); } catch (err) { handleError(err); @@ -173,7 +168,6 @@ export function removeCallback(cb: Function) { export function withGlobal( mapStateToProps: MapStateToProps = () => ({}), - mapReducersToProps: MapActionsToProps = () => ({}), ) { return (Component: FC) => { return function TeactNContainer(props: OwnProps) { @@ -192,7 +186,6 @@ export function withGlobal( if (!container) { container = { mapStateToProps, - mapReducersToProps, ownProps: props, areMappedPropsChanged: false, forceUpdate, @@ -211,10 +204,7 @@ export function withGlobal( container.ownProps = props; try { - container.mappedProps = { - ...mapStateToProps(currentGlobal, props), - ...mapReducersToProps(setGlobal, actions), - }; + container.mappedProps = mapStateToProps(currentGlobal, props); } catch (err) { handleError(err); }