From 842d2432a111875a53ae90aa30f5ab6311977c24 Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Wed, 14 May 2025 19:01:49 +0300 Subject: [PATCH] Gift Transfer: Add 2FA set up button (#5876) --- src/assets/localization/fallback.strings | 1 + src/components/left/ArchivedChats.tsx | 8 +- src/components/left/LeftColumn.tsx | 168 ++++++++---------- src/components/left/main/ChatFolders.tsx | 13 +- src/components/left/main/ChatList.tsx | 20 +-- src/components/left/main/EmptyFolder.tsx | 10 +- src/components/left/main/LeftMain.tsx | 19 +- src/components/left/main/LeftMainHeader.tsx | 4 +- src/components/left/newChat/NewChat.tsx | 10 +- .../left/settings/PrivacyMessages.tsx | 6 +- src/components/left/settings/Settings.tsx | 22 +-- .../left/settings/SettingsGeneral.tsx | 6 +- .../settings/SettingsGeneralBackground.tsx | 7 +- .../left/settings/SettingsHeader.tsx | 7 +- .../left/settings/SettingsLanguage.tsx | 5 +- src/components/left/settings/SettingsMain.tsx | 21 ++- .../left/settings/SettingsPrivacy.tsx | 41 +++-- .../settings/SettingsPrivacyVisibility.tsx | 16 +- .../left/settings/SettingsStickers.tsx | 7 +- .../left/settings/folders/SettingsFolders.tsx | 48 ++--- .../settings/passcode/SettingsPasscode.tsx | 28 ++- .../passcode/SettingsPasscodeEnabled.tsx | 9 +- .../left/settings/twoFa/SettingsTwoFa.tsx | 59 +++--- .../twoFa/SettingsTwoFaCongratulations.tsx | 14 +- .../settings/twoFa/SettingsTwoFaEnabled.tsx | 11 +- .../middle/message/actions/SuggestedPhoto.tsx | 2 +- .../gift/withdraw/GiftWithdrawModal.tsx | 26 ++- src/global/actions/api/chats.ts | 4 +- src/global/actions/ui/passcode.ts | 2 +- src/global/actions/ui/settings.ts | 42 ++++- src/global/initialState.ts | 7 +- src/global/selectors/ui.ts | 12 ++ src/global/types/actions.ts | 8 +- src/global/types/tabState.ts | 7 +- src/types/language.d.ts | 1 + 35 files changed, 342 insertions(+), 329 deletions(-) diff --git a/src/assets/localization/fallback.strings b/src/assets/localization/fallback.strings index a0614c43e..7fe60b864 100644 --- a/src/assets/localization/fallback.strings +++ b/src/assets/localization/fallback.strings @@ -1674,6 +1674,7 @@ "GiftFilterHidden" = "Hidden"; "GiftSearchEmpty" = "No matching gifts"; "GiftSearchReset" = "View All Gifts"; +"SetUp2FA" = "Set up Two-Step Verification"; "CheckPasswordTitle" = "Enter Password"; "CheckPasswordPlaceholder" = "Password"; "CheckPasswordDescription" = "Please enter your password to continue."; diff --git a/src/components/left/ArchivedChats.tsx b/src/components/left/ArchivedChats.tsx index d3d650c6c..98bfedaf8 100644 --- a/src/components/left/ArchivedChats.tsx +++ b/src/components/left/ArchivedChats.tsx @@ -4,7 +4,6 @@ import { getActions } from '../../global'; import type { GlobalState } from '../../global/types'; import type { FolderEditDispatch } from '../../hooks/reducers/useFoldersReducer'; -import type { LeftColumnContent, SettingsScreens } from '../../types'; import { ANIMATION_END_DELAY } from '../../config'; import buildClassName from '../../util/buildClassName'; @@ -35,9 +34,7 @@ export type OwnProps = { isStoryRibbonShown?: boolean; onReset: () => void; onTopicSearch: NoneToVoidFunction; - onSettingsScreenSelect: (screen: SettingsScreens) => void; foldersDispatch: FolderEditDispatch; - onLeftColumnContentChange: (content: LeftColumnContent) => void; }; const ArchivedChats: FC = ({ @@ -47,8 +44,6 @@ const ArchivedChats: FC = ({ isStoryRibbonShown, onReset, onTopicSearch, - onSettingsScreenSelect, - onLeftColumnContentChange, foldersDispatch, }) => { const { updateArchiveSettings } = getActions(); @@ -136,8 +131,7 @@ const ArchivedChats: FC = ({ folderType="archived" isActive={isActive} isForumPanelOpen={isForumPanelVisible} - onSettingsScreenSelect={onSettingsScreenSelect} - onLeftColumnContentChange={onLeftColumnContentChange} + isMainList foldersDispatch={foldersDispatch} archiveSettings={archiveSettings} /> diff --git a/src/components/left/LeftColumn.tsx b/src/components/left/LeftColumn.tsx index 08d428ff3..610f6736b 100644 --- a/src/components/left/LeftColumn.tsx +++ b/src/components/left/LeftColumn.tsx @@ -38,13 +38,14 @@ interface OwnProps { } type StateProps = { + contentKey: LeftColumnContent; + settingsScreen: SettingsScreens; searchQuery?: string; searchDate?: number; isFirstChatFolderActive: boolean; shouldSkipHistoryAnimations?: boolean; currentUserId?: string; hasPasscode?: boolean; - nextSettingsScreen?: SettingsScreens; nextFoldersAction?: ReducerAction; isChatOpen: boolean; isAppUpdateAvailable?: boolean; @@ -73,13 +74,14 @@ const RESET_TRANSITION_DELAY_MS = 250; function LeftColumn({ ref, + contentKey, + settingsScreen, searchQuery, searchDate, isFirstChatFolderActive, shouldSkipHistoryAnimations, currentUserId, hasPasscode, - nextSettingsScreen, nextFoldersAction, isChatOpen, isAppUpdateAvailable, @@ -100,11 +102,10 @@ function LeftColumn({ loadPasswordInfo, clearTwoFaError, openChat, - requestNextSettingsScreen, + openLeftColumnContent, + openSettingsScreen, } = getActions(); - const [content, setContent] = useState(LeftColumnContent.ChatList); - const [settingsScreen, setSettingsScreen] = useState(SettingsScreens.Main); const [contactsFilter, setContactsFilter] = useState(''); const [foldersState, foldersDispatch] = useFoldersReducer(); @@ -112,7 +113,7 @@ function LeftColumn({ const [lastResetTime, setLastResetTime] = useState(0); let contentType: ContentType = ContentType.Main; - switch (content) { + switch (contentKey) { case LeftColumnContent.Archived: contentType = ContentType.Archived; break; @@ -131,8 +132,8 @@ function LeftColumn({ const handleReset = useLastCallback((forceReturnToChatList?: true | Event) => { function fullReset() { - setContent(LeftColumnContent.ChatList); - setSettingsScreen(SettingsScreens.Main); + openLeftColumnContent({ contentKey: undefined }); + openSettingsScreen({ screen: undefined }); setContactsFilter(''); setGlobalSearchClosing({ isClosing: true }); resetChatCreation(); @@ -150,24 +151,24 @@ function LeftColumn({ return; } - if (content === LeftColumnContent.NewGroupStep2) { - setContent(LeftColumnContent.NewGroupStep1); + if (contentKey === LeftColumnContent.NewGroupStep2) { + openLeftColumnContent({ contentKey: LeftColumnContent.NewGroupStep1 }); return; } - if (content === LeftColumnContent.NewChannelStep2) { - setContent(LeftColumnContent.NewChannelStep1); + if (contentKey === LeftColumnContent.NewChannelStep2) { + openLeftColumnContent({ contentKey: LeftColumnContent.NewChannelStep1 }); return; } - if (content === LeftColumnContent.NewGroupStep1) { + if (contentKey === LeftColumnContent.NewGroupStep1) { const pickerSearchInput = document.getElementById('new-group-picker-search'); if (pickerSearchInput) { pickerSearchInput.blur(); } } - if (content === LeftColumnContent.Settings) { + if (contentKey === LeftColumnContent.Settings) { switch (settingsScreen) { case SettingsScreens.EditProfile: case SettingsScreens.Folders: @@ -180,14 +181,14 @@ function LeftColumn({ case SettingsScreens.Language: case SettingsScreens.Stickers: case SettingsScreens.Experimental: - setSettingsScreen(SettingsScreens.Main); + openSettingsScreen({ screen: SettingsScreens.Main }); return; case SettingsScreens.GeneralChatBackground: - setSettingsScreen(SettingsScreens.General); + openSettingsScreen({ screen: SettingsScreens.General }); return; case SettingsScreens.GeneralChatBackgroundColor: - setSettingsScreen(SettingsScreens.GeneralChatBackground); + openSettingsScreen({ screen: SettingsScreens.GeneralChatBackground }); return; case SettingsScreens.PrivacyPhoneNumber: @@ -211,141 +212,143 @@ function LeftColumn({ case SettingsScreens.PasscodeDisabled: case SettingsScreens.PasscodeEnabled: case SettingsScreens.PasscodeCongratulations: - setSettingsScreen(SettingsScreens.Privacy); + openSettingsScreen({ screen: SettingsScreens.Privacy }); return; case SettingsScreens.PasscodeNewPasscode: - setSettingsScreen(hasPasscode ? SettingsScreens.PasscodeEnabled : SettingsScreens.PasscodeDisabled); + openSettingsScreen({ + screen: hasPasscode ? SettingsScreens.PasscodeEnabled : SettingsScreens.PasscodeDisabled, + }); return; case SettingsScreens.PasscodeChangePasscodeCurrent: case SettingsScreens.PasscodeTurnOff: - setSettingsScreen(SettingsScreens.PasscodeEnabled); + openSettingsScreen({ screen: SettingsScreens.PasscodeEnabled }); return; case SettingsScreens.PasscodeNewPasscodeConfirm: - setSettingsScreen(SettingsScreens.PasscodeNewPasscode); + openSettingsScreen({ screen: SettingsScreens.PasscodeNewPasscode }); return; case SettingsScreens.PasscodeChangePasscodeNew: - setSettingsScreen(SettingsScreens.PasscodeChangePasscodeCurrent); + openSettingsScreen({ screen: SettingsScreens.PasscodeChangePasscodeCurrent }); return; case SettingsScreens.PasscodeChangePasscodeConfirm: - setSettingsScreen(SettingsScreens.PasscodeChangePasscodeNew); + openSettingsScreen({ screen: SettingsScreens.PasscodeChangePasscodeNew }); return; case SettingsScreens.PrivacyPhoneNumberAllowedContacts: case SettingsScreens.PrivacyPhoneNumberDeniedContacts: - setSettingsScreen(SettingsScreens.PrivacyPhoneNumber); + openSettingsScreen({ screen: SettingsScreens.PrivacyPhoneNumber }); return; case SettingsScreens.PrivacyLastSeenAllowedContacts: case SettingsScreens.PrivacyLastSeenDeniedContacts: - setSettingsScreen(SettingsScreens.PrivacyLastSeen); + openSettingsScreen({ screen: SettingsScreens.PrivacyLastSeen }); return; case SettingsScreens.PrivacyProfilePhotoAllowedContacts: case SettingsScreens.PrivacyProfilePhotoDeniedContacts: - setSettingsScreen(SettingsScreens.PrivacyProfilePhoto); + openSettingsScreen({ screen: SettingsScreens.PrivacyProfilePhoto }); return; case SettingsScreens.PrivacyBioAllowedContacts: case SettingsScreens.PrivacyBioDeniedContacts: - setSettingsScreen(SettingsScreens.PrivacyBio); + openSettingsScreen({ screen: SettingsScreens.PrivacyBio }); return; case SettingsScreens.PrivacyBirthdayAllowedContacts: case SettingsScreens.PrivacyBirthdayDeniedContacts: - setSettingsScreen(SettingsScreens.PrivacyBirthday); + openSettingsScreen({ screen: SettingsScreens.PrivacyBirthday }); return; case SettingsScreens.PrivacyGiftsAllowedContacts: case SettingsScreens.PrivacyGiftsDeniedContacts: - setSettingsScreen(SettingsScreens.PrivacyGifts); + openSettingsScreen({ screen: SettingsScreens.PrivacyGifts }); return; case SettingsScreens.PrivacyPhoneCallAllowedContacts: case SettingsScreens.PrivacyPhoneCallDeniedContacts: - setSettingsScreen(SettingsScreens.PrivacyPhoneCall); + openSettingsScreen({ screen: SettingsScreens.PrivacyPhoneCall }); return; case SettingsScreens.PrivacyPhoneP2PAllowedContacts: case SettingsScreens.PrivacyPhoneP2PDeniedContacts: - setSettingsScreen(SettingsScreens.PrivacyPhoneP2P); + openSettingsScreen({ screen: SettingsScreens.PrivacyPhoneP2P }); return; case SettingsScreens.PrivacyForwardingAllowedContacts: case SettingsScreens.PrivacyForwardingDeniedContacts: - setSettingsScreen(SettingsScreens.PrivacyForwarding); + openSettingsScreen({ screen: SettingsScreens.PrivacyForwarding }); return; case SettingsScreens.PrivacyVoiceMessagesAllowedContacts: case SettingsScreens.PrivacyVoiceMessagesDeniedContacts: - setSettingsScreen(SettingsScreens.PrivacyVoiceMessages); + openSettingsScreen({ screen: SettingsScreens.PrivacyVoiceMessages }); return; case SettingsScreens.PrivacyGroupChatsAllowedContacts: case SettingsScreens.PrivacyGroupChatsDeniedContacts: - setSettingsScreen(SettingsScreens.PrivacyGroupChats); + openSettingsScreen({ screen: SettingsScreens.PrivacyGroupChats }); return; case SettingsScreens.TwoFaNewPassword: - setSettingsScreen(SettingsScreens.TwoFaDisabled); + openSettingsScreen({ screen: SettingsScreens.TwoFaDisabled }); return; case SettingsScreens.TwoFaNewPasswordConfirm: - setSettingsScreen(SettingsScreens.TwoFaNewPassword); + openSettingsScreen({ screen: SettingsScreens.TwoFaNewPassword }); return; case SettingsScreens.TwoFaNewPasswordHint: - setSettingsScreen(SettingsScreens.TwoFaNewPasswordConfirm); + openSettingsScreen({ screen: SettingsScreens.TwoFaNewPasswordConfirm }); return; case SettingsScreens.TwoFaNewPasswordEmail: - setSettingsScreen(SettingsScreens.TwoFaNewPasswordHint); + openSettingsScreen({ screen: SettingsScreens.TwoFaNewPasswordHint }); return; case SettingsScreens.TwoFaNewPasswordEmailCode: - setSettingsScreen(SettingsScreens.TwoFaNewPasswordEmail); + openSettingsScreen({ screen: SettingsScreens.TwoFaNewPasswordEmail }); return; case SettingsScreens.TwoFaChangePasswordCurrent: case SettingsScreens.TwoFaTurnOff: case SettingsScreens.TwoFaRecoveryEmailCurrentPassword: - setSettingsScreen(SettingsScreens.TwoFaEnabled); + openSettingsScreen({ screen: SettingsScreens.TwoFaEnabled }); return; case SettingsScreens.TwoFaChangePasswordNew: - setSettingsScreen(SettingsScreens.TwoFaChangePasswordCurrent); + openSettingsScreen({ screen: SettingsScreens.TwoFaChangePasswordCurrent }); return; case SettingsScreens.TwoFaChangePasswordConfirm: - setSettingsScreen(SettingsScreens.TwoFaChangePasswordNew); + openSettingsScreen({ screen: SettingsScreens.TwoFaChangePasswordNew }); return; case SettingsScreens.TwoFaChangePasswordHint: - setSettingsScreen(SettingsScreens.TwoFaChangePasswordConfirm); + openSettingsScreen({ screen: SettingsScreens.TwoFaChangePasswordConfirm }); return; case SettingsScreens.TwoFaRecoveryEmail: - setSettingsScreen(SettingsScreens.TwoFaRecoveryEmailCurrentPassword); + openSettingsScreen({ screen: SettingsScreens.TwoFaRecoveryEmailCurrentPassword }); return; case SettingsScreens.TwoFaRecoveryEmailCode: - setSettingsScreen(SettingsScreens.TwoFaRecoveryEmail); + openSettingsScreen({ screen: SettingsScreens.TwoFaRecoveryEmail }); return; case SettingsScreens.FoldersCreateFolder: case SettingsScreens.FoldersEditFolder: - setSettingsScreen(SettingsScreens.Folders); + openSettingsScreen({ screen: SettingsScreens.Folders }); return; case SettingsScreens.FoldersShare: - setSettingsScreen(SettingsScreens.FoldersEditFolder); + openSettingsScreen({ screen: SettingsScreens.FoldersEditFolder }); return; case SettingsScreens.FoldersIncludedChatsFromChatList: case SettingsScreens.FoldersExcludedChatsFromChatList: - setSettingsScreen(SettingsScreens.FoldersEditFolderFromChatList); + openSettingsScreen({ screen: SettingsScreens.FoldersEditFolderFromChatList }); return; case SettingsScreens.FoldersEditFolderFromChatList: case SettingsScreens.FoldersEditFolderInvites: - setContent(LeftColumnContent.ChatList); - setSettingsScreen(SettingsScreens.Main); + openLeftColumnContent({ contentKey: LeftColumnContent.ChatList }); + openSettingsScreen({ screen: SettingsScreens.Main }); return; case SettingsScreens.QuickReaction: case SettingsScreens.CustomEmoji: - setSettingsScreen(SettingsScreens.Stickers); + openSettingsScreen({ screen: SettingsScreens.Stickers }); return; case SettingsScreens.DoNotTranslate: - setSettingsScreen(SettingsScreens.Language); + openSettingsScreen({ screen: SettingsScreens.Language }); return; case SettingsScreens.PrivacyNoPaidMessages: - setSettingsScreen(SettingsScreens.PrivacyMessages); + openSettingsScreen({ screen: SettingsScreens.PrivacyMessages }); return; default: @@ -353,8 +356,8 @@ function LeftColumn({ } } - if (content === LeftColumnContent.ChatList && isFirstChatFolderActive) { - setContent(LeftColumnContent.GlobalSearch); + if (contentKey === LeftColumnContent.ChatList && isFirstChatFolderActive) { + openLeftColumnContent({ contentKey: LeftColumnContent.GlobalSearch }); return; } @@ -363,12 +366,12 @@ function LeftColumn({ }); const handleSearchQuery = useLastCallback((query: string) => { - if (content === LeftColumnContent.Contacts) { + if (contentKey === LeftColumnContent.Contacts) { setContactsFilter(query); return; } - setContent(LeftColumnContent.GlobalSearch); + openLeftColumnContent({ contentKey: LeftColumnContent.GlobalSearch }); if (query !== searchQuery) { setGlobalSearchQuery({ query }); @@ -376,15 +379,15 @@ function LeftColumn({ }); const handleTopicSearch = useLastCallback(() => { - setContent(LeftColumnContent.GlobalSearch); + openLeftColumnContent({ contentKey: LeftColumnContent.GlobalSearch }); setGlobalSearchQuery({ query: '' }); setGlobalSearchChatId({ id: forumPanelChatId }); }); useEffect( () => { - const isArchived = content === LeftColumnContent.Archived; - const isChatList = content === LeftColumnContent.ChatList; + const isArchived = contentKey === LeftColumnContent.Archived; + const isChatList = contentKey === LeftColumnContent.ChatList; const noChatOrForumOpen = !isChatOpen && !isForumPanelOpen; // We listen for escape key only in these cases: // 1. When we are in archived chats and no chat or forum is open. @@ -399,16 +402,16 @@ function LeftColumn({ return undefined; } }, - [isFirstChatFolderActive, content, handleReset, isChatOpen, isForumPanelOpen], + [isFirstChatFolderActive, contentKey, handleReset, isChatOpen, isForumPanelOpen], ); const handleHotkeySearch = useLastCallback((e: KeyboardEvent) => { - if (content === LeftColumnContent.GlobalSearch) { + if (contentKey === LeftColumnContent.GlobalSearch) { return; } e.preventDefault(); - setContent(LeftColumnContent.GlobalSearch); + openLeftColumnContent({ contentKey: LeftColumnContent.GlobalSearch }); }); const handleHotkeySavedMessages = useLastCallback((e: KeyboardEvent) => { @@ -418,12 +421,12 @@ function LeftColumn({ const handleArchivedChats = useLastCallback((e: KeyboardEvent) => { e.preventDefault(); - setContent(LeftColumnContent.Archived); + openLeftColumnContent({ contentKey: LeftColumnContent.Archived }); }); const handleHotkeySettings = useLastCallback((e: KeyboardEvent) => { e.preventDefault(); - setContent(LeftColumnContent.Settings); + openLeftColumnContent({ contentKey: LeftColumnContent.Settings }); }); useHotkeys(useMemo(() => ({ @@ -448,21 +451,10 @@ function LeftColumn({ }, [clearTwoFaError, loadPasswordInfo, settingsScreen]); useSyncEffect(() => { - if (nextSettingsScreen !== undefined) { - setContent(LeftColumnContent.Settings); - setSettingsScreen(nextSettingsScreen); - requestNextSettingsScreen({ screen: undefined }); - } - if (nextFoldersAction) { foldersDispatch(nextFoldersAction); } - }, [foldersDispatch, nextFoldersAction, nextSettingsScreen, requestNextSettingsScreen]); - - const handleSettingsScreenSelect = useLastCallback((screen: SettingsScreens) => { - setContent(LeftColumnContent.Settings); - setSettingsScreen(screen); - }); + }, [foldersDispatch, nextFoldersAction]); const prevSettingsScreenRef = useStateRef(usePrevious(contentType === ContentType.Settings ? settingsScreen : -1)); @@ -476,8 +468,8 @@ function LeftColumn({ selectorToPreventScroll: '#Settings .custom-scroll', onSwipeRightStart: handleReset, onCancel: () => { - setContent(LeftColumnContent.Settings); - handleSettingsScreenSelect(prevSettingsScreenRef.current!); + openLeftColumnContent({ contentKey: LeftColumnContent.Settings }); + openSettingsScreen({ screen: prevSettingsScreenRef.current! }); }, }); }, [prevSettingsScreenRef, ref]); @@ -491,8 +483,6 @@ function LeftColumn({ onReset={handleReset} onTopicSearch={handleTopicSearch} foldersDispatch={foldersDispatch} - onSettingsScreenSelect={handleSettingsScreenSelect} - onLeftColumnContentChange={setContent} isForumPanelOpen={isForumPanelOpen} archiveSettings={archiveSettings} isStoryRibbonShown={isArchivedStoryRibbonShown} @@ -506,7 +496,6 @@ function LeftColumn({ foldersState={foldersState} foldersDispatch={foldersDispatch} shouldSkipTransition={shouldSkipHistoryAnimations} - onScreenSelect={handleSettingsScreenSelect} onReset={handleReset} /> ); @@ -516,8 +505,7 @@ function LeftColumn({ key={lastResetTime} isActive={isActive} isChannel - content={content} - onContentChange={setContent} + content={contentKey} onReset={handleReset} /> ); @@ -526,23 +514,20 @@ function LeftColumn({ ); default: return ( ( }, shouldSkipHistoryAnimations, activeChatFolder, - nextSettingsScreen, + leftColumn, nextFoldersAction, storyViewer: { isArchivedRibbonShown, @@ -612,7 +597,6 @@ export default memo(withGlobal( shouldSkipHistoryAnimations, currentUserId, hasPasscode, - nextSettingsScreen, nextFoldersAction, isChatOpen, isAppUpdateAvailable, @@ -623,6 +607,8 @@ export default memo(withGlobal( archiveSettings, isArchivedStoryRibbonShown: isArchivedRibbonShown, isAccountFrozen, + contentKey: leftColumn.contentKey, + settingsScreen: leftColumn.settingsScreen, }; }, )(LeftColumn)); diff --git a/src/components/left/main/ChatFolders.tsx b/src/components/left/main/ChatFolders.tsx index 9f5433289..9aff02d7d 100644 --- a/src/components/left/main/ChatFolders.tsx +++ b/src/components/left/main/ChatFolders.tsx @@ -7,7 +7,6 @@ import { getActions, getGlobal, withGlobal } from '../../../global'; import type { ApiChatFolder, ApiChatlistExportedInvite, ApiSession } from '../../../api/types'; import type { GlobalState } from '../../../global/types'; import type { FolderEditDispatch } from '../../../hooks/reducers/useFoldersReducer'; -import type { LeftColumnContent } from '../../../types'; import type { MenuItemContextAction } from '../../ui/ListItem'; import type { TabWithProperties } from '../../ui/TabList'; import { SettingsScreens } from '../../../types'; @@ -38,9 +37,7 @@ import Transition from '../../ui/Transition'; import ChatList from './ChatList'; type OwnProps = { - onSettingsScreenSelect: (screen: SettingsScreens) => void; foldersDispatch: FolderEditDispatch; - onLeftColumnContentChange: (content: LeftColumnContent) => void; shouldHideFolderTabs?: boolean; isForumPanelOpen?: boolean; }; @@ -68,8 +65,6 @@ const FIRST_FOLDER_INDEX = 0; const ChatFolders: FC = ({ foldersDispatch, - onSettingsScreenSelect, - onLeftColumnContentChange, chatFoldersById, orderedFolderIds, activeChatFolder, @@ -97,6 +92,7 @@ const ChatFolders: FC = ({ openEditChatFolder, openLimitReachedModal, markChatMessagesRead, + openSettingsScreen, } = getActions(); // eslint-disable-next-line no-null/no-null @@ -207,7 +203,7 @@ const ChatFolders: FC = ({ title: lang('FilterEditFolders'), icon: 'edit', handler: () => { - onSettingsScreenSelect(SettingsScreens.Folders); + openSettingsScreen({ screen: SettingsScreens.Folders }); }, }); @@ -260,7 +256,7 @@ const ChatFolders: FC = ({ }); }, [ displayedFolders, maxFolders, folderCountersById, lang, chatFoldersById, maxChatLists, folderInvitesById, - maxFolderInvites, folderUnreadChatsCountersById, onSettingsScreenSelect, + maxFolderInvites, folderUnreadChatsCountersById, openSettingsScreen, ]); const handleSwitchTab = useLastCallback((index: number) => { @@ -365,8 +361,7 @@ const ChatFolders: FC = ({ isActive={isActive} isForumPanelOpen={isForumPanelOpen} foldersDispatch={foldersDispatch} - onSettingsScreenSelect={onSettingsScreenSelect} - onLeftColumnContentChange={onLeftColumnContentChange} + isMainList canDisplayArchive={(hasArchivedChats || hasArchivedStories) && !archiveSettings.isHidden} archiveSettings={archiveSettings} sessions={sessions} diff --git a/src/components/left/main/ChatList.tsx b/src/components/left/main/ChatList.tsx index 234e4aa55..d3d209133 100644 --- a/src/components/left/main/ChatList.tsx +++ b/src/components/left/main/ChatList.tsx @@ -7,7 +7,6 @@ import { getActions } from '../../../global'; import type { ApiSession } from '../../../api/types'; import type { GlobalState } from '../../../global/types'; import type { FolderEditDispatch } from '../../../hooks/reducers/useFoldersReducer'; -import type { SettingsScreens } from '../../../types'; import { LeftColumnContent } from '../../../types'; import { @@ -51,10 +50,9 @@ type OwnProps = { archiveSettings?: GlobalState['archiveSettings']; isForumPanelOpen?: boolean; sessions?: Record; - foldersDispatch?: FolderEditDispatch; - onSettingsScreenSelect?: (screen: SettingsScreens) => void; - onLeftColumnContentChange?: (content: LeftColumnContent) => void; isAccountFrozen?: boolean; + isMainList?: boolean; + foldersDispatch?: FolderEditDispatch; }; const INTERSECTION_THROTTLE = 200; @@ -70,10 +68,9 @@ const ChatList: FC = ({ canDisplayArchive, archiveSettings, sessions, - foldersDispatch, - onSettingsScreenSelect, - onLeftColumnContentChange, isAccountFrozen, + isMainList, + foldersDispatch, }) => { const { openChat, @@ -81,6 +78,7 @@ const ChatList: FC = ({ closeForumPanel, toggleStoryRibbon, openFrozenAccountModal, + openLeftColumnContent, } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); @@ -150,7 +148,7 @@ const ChatList: FC = ({ const position = Number(digit) + shift - 1; if (isArchiveInList && position === -1) { - onLeftColumnContentChange?.(LeftColumnContent.Archived); + if (isMainList) openLeftColumnContent({ contentKey: LeftColumnContent.Archived }); return; } @@ -166,8 +164,7 @@ const ChatList: FC = ({ document.removeEventListener('keydown', handleKeyDown); }; }, [ - archiveSettings, isSaved, isActive, onLeftColumnContentChange, openChat, openNextChat, orderedIds, - shouldDisplayArchive, + archiveSettings, isSaved, isActive, openChat, openNextChat, orderedIds, shouldDisplayArchive, isMainList, ]); const { observe } = useIntersectionObserver({ @@ -176,7 +173,7 @@ const ChatList: FC = ({ }); const handleArchivedClick = useLastCallback(() => { - onLeftColumnContentChange!(LeftColumnContent.Archived); + openLeftColumnContent({ contentKey: LeftColumnContent.Archived }); closeForumPanel(); }); @@ -288,7 +285,6 @@ const ChatList: FC = ({ folderId={folderId} folderType={folderType} foldersDispatch={foldersDispatch!} - onSettingsScreenSelect={onSettingsScreenSelect!} /> ) ) : ( diff --git a/src/components/left/main/EmptyFolder.tsx b/src/components/left/main/EmptyFolder.tsx index 8f39df226..99fbc2e38 100644 --- a/src/components/left/main/EmptyFolder.tsx +++ b/src/components/left/main/EmptyFolder.tsx @@ -1,6 +1,6 @@ import type { FC } from '../../../lib/teact/teact'; import React, { memo, useCallback } from '../../../lib/teact/teact'; -import { withGlobal } from '../../../global'; +import { getActions, withGlobal } from '../../../global'; import type { ApiChatFolder, ApiSticker } from '../../../api/types'; import type { FolderEditDispatch } from '../../../hooks/reducers/useFoldersReducer'; @@ -21,7 +21,6 @@ type OwnProps = { folderId?: number; folderType: 'all' | 'archived' | 'saved' | 'folder'; foldersDispatch: FolderEditDispatch; - onSettingsScreenSelect: (screen: SettingsScreens) => void; }; type StateProps = { @@ -32,15 +31,16 @@ type StateProps = { const ICON_SIZE = 96; const EmptyFolder: FC = ({ - chatFolder, animatedEmoji, foldersDispatch, onSettingsScreenSelect, + chatFolder, animatedEmoji, foldersDispatch, }) => { + const { openSettingsScreen } = getActions(); const lang = useOldLang(); const { isMobile } = useAppLayout(); const handleEditFolder = useCallback(() => { foldersDispatch({ type: 'editFolder', payload: chatFolder }); - onSettingsScreenSelect(SettingsScreens.FoldersEditFolderFromChatList); - }, [chatFolder, foldersDispatch, onSettingsScreenSelect]); + openSettingsScreen({ screen: SettingsScreens.FoldersEditFolderFromChatList }); + }, [chatFolder, foldersDispatch]); return (
diff --git a/src/components/left/main/LeftMain.tsx b/src/components/left/main/LeftMain.tsx index a9915ec3b..8b13e18a6 100644 --- a/src/components/left/main/LeftMain.tsx +++ b/src/components/left/main/LeftMain.tsx @@ -5,7 +5,6 @@ import React, { import { getActions } from '../../../global'; import type { FolderEditDispatch } from '../../../hooks/reducers/useFoldersReducer'; -import type { SettingsScreens } from '../../../types'; import { LeftColumnContent } from '../../../types'; import { PRODUCTION_URL } from '../../../config'; @@ -40,8 +39,6 @@ type OwnProps = { isForumPanelOpen?: boolean; isClosingSearch?: boolean; onSearchQuery: (query: string) => void; - onContentChange: (content: LeftColumnContent) => void; - onSettingsScreenSelect: (screen: SettingsScreens) => void; onTopicSearch: NoneToVoidFunction; isAccountFrozen?: boolean; onReset: () => void; @@ -64,13 +61,11 @@ const LeftMain: FC = ({ isElectronUpdateAvailable, isForumPanelOpen, onSearchQuery, - onContentChange, - onSettingsScreenSelect, onReset, onTopicSearch, isAccountFrozen, }) => { - const { closeForumPanel } = getActions(); + const { closeForumPanel, openLeftColumnContent } = getActions(); const [isNewChatButtonShown, setIsNewChatButtonShown] = useState(IS_TOUCH_ENV); const [isElectronAutoUpdateEnabled, setIsElectronAutoUpdateEnabled] = useState(false); @@ -116,15 +111,15 @@ const LeftMain: FC = ({ }); const handleSelectSettings = useLastCallback(() => { - onContentChange(LeftColumnContent.Settings); + openLeftColumnContent({ contentKey: LeftColumnContent.Settings }); }); const handleSelectContacts = useLastCallback(() => { - onContentChange(LeftColumnContent.Contacts); + openLeftColumnContent({ contentKey: LeftColumnContent.Contacts }); }); const handleSelectArchived = useLastCallback(() => { - onContentChange(LeftColumnContent.Archived); + openLeftColumnContent({ contentKey: LeftColumnContent.Archived }); closeForumPanel(); }); @@ -139,11 +134,11 @@ const LeftMain: FC = ({ }); const handleSelectNewChannel = useLastCallback(() => { - onContentChange(LeftColumnContent.NewChannelStep1); + openLeftColumnContent({ contentKey: LeftColumnContent.NewChannelStep1 }); }); const handleSelectNewGroup = useLastCallback(() => { - onContentChange(LeftColumnContent.NewGroupStep1); + openLeftColumnContent({ contentKey: LeftColumnContent.NewGroupStep1 }); }); useEffect(() => { @@ -199,8 +194,6 @@ const LeftMain: FC = ({ return ( diff --git a/src/components/left/main/LeftMainHeader.tsx b/src/components/left/main/LeftMainHeader.tsx index 4f66ae2ae..371f1907c 100644 --- a/src/components/left/main/LeftMainHeader.tsx +++ b/src/components/left/main/LeftMainHeader.tsx @@ -113,7 +113,7 @@ const LeftMainHeader: FC = ({ setSharedSettingOption, setGlobalSearchChatId, lockScreen, - requestNextSettingsScreen, + openSettingsScreen, } = getActions(); const oldLang = useOldLang(); @@ -146,7 +146,7 @@ const LeftMainHeader: FC = ({ if (hasPasscode) { lockScreen(); } else { - requestNextSettingsScreen({ screen: SettingsScreens.PasscodeDisabled }); + openSettingsScreen({ screen: SettingsScreens.PasscodeDisabled }); } }); diff --git a/src/components/left/newChat/NewChat.tsx b/src/components/left/newChat/NewChat.tsx index 2af8deb73..694c2904f 100644 --- a/src/components/left/newChat/NewChat.tsx +++ b/src/components/left/newChat/NewChat.tsx @@ -1,5 +1,6 @@ import type { FC } from '../../../lib/teact/teact'; import React, { memo, useCallback, useState } from '../../../lib/teact/teact'; +import { getActions } from '../../../global'; import { LeftColumnContent } from '../../../types'; @@ -15,7 +16,6 @@ export type OwnProps = { isActive: boolean; isChannel?: boolean; content: LeftColumnContent; - onContentChange: (content: LeftColumnContent) => void; onReset: () => void; }; @@ -25,14 +25,16 @@ const NewChat: FC = ({ isActive, isChannel = false, content, - onContentChange, onReset, }) => { + const { openLeftColumnContent } = getActions(); const [newChatMemberIds, setNewChatMemberIds] = useState([]); const handleNextStep = useCallback(() => { - onContentChange(isChannel ? LeftColumnContent.NewChannelStep2 : LeftColumnContent.NewGroupStep2); - }, [isChannel, onContentChange]); + openLeftColumnContent({ + contentKey: isChannel ? LeftColumnContent.NewChannelStep2 : LeftColumnContent.NewGroupStep2, + }); + }, [isChannel]); return ( void; }; type StateProps = { @@ -52,9 +51,8 @@ function PrivacyMessages({ isCurrentUserPremium, noPaidReactionsForUsersCount, onReset, - onScreenSelect, }: OwnProps & StateProps) { - const { updateGlobalPrivacySettings } = getActions(); + const { updateGlobalPrivacySettings, openSettingsScreen } = getActions(); const oldLang = useOldLang(); const lang = useLang(); @@ -133,7 +131,7 @@ function PrivacyMessages({ icon="delete-user" // eslint-disable-next-line react/jsx-no-bind onClick={() => { - onScreenSelect(SettingsScreens.PrivacyNoPaidMessages); + openSettingsScreen({ screen: SettingsScreens.PrivacyNoPaidMessages }); }} >
diff --git a/src/components/left/settings/Settings.tsx b/src/components/left/settings/Settings.tsx index d63528d9a..42dc845bc 100644 --- a/src/components/left/settings/Settings.tsx +++ b/src/components/left/settings/Settings.tsx @@ -150,7 +150,6 @@ export type OwnProps = { currentScreen: SettingsScreens; foldersState: FoldersState; foldersDispatch: FolderEditDispatch; - onScreenSelect: (screen: SettingsScreens) => void; shouldSkipTransition?: boolean; onReset: (forceReturnToChatList?: true | Event) => void; }; @@ -160,11 +159,10 @@ const Settings: FC = ({ currentScreen, foldersState, foldersDispatch, - onScreenSelect, onReset, shouldSkipTransition, }) => { - const { closeShareChatFolderModal } = getActions(); + const { closeShareChatFolderModal, openSettingsScreen } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); @@ -205,9 +203,9 @@ const Settings: FC = ({ || currentScreen === SettingsScreens.FoldersExcludedChats ) { if (foldersState.mode === 'create') { - onScreenSelect(SettingsScreens.FoldersCreateFolder); + openSettingsScreen({ screen: SettingsScreens.FoldersCreateFolder }); } else { - onScreenSelect(SettingsScreens.FoldersEditFolder); + openSettingsScreen({ screen: SettingsScreens.FoldersEditFolder }); } return; } @@ -243,7 +241,7 @@ const Settings: FC = ({ switch (currentScreen) { case SettingsScreens.Main: return ( - + ); case SettingsScreens.EditProfile: return ( @@ -255,7 +253,6 @@ const Settings: FC = ({ case SettingsScreens.General: return ( = ({ case SettingsScreens.Privacy: return ( @@ -294,7 +290,6 @@ const Settings: FC = ({ ); case SettingsScreens.DoNotTranslate: @@ -303,7 +298,7 @@ const Settings: FC = ({ ); case SettingsScreens.Stickers: return ( - + ); case SettingsScreens.Experimental: return ( @@ -312,7 +307,6 @@ const Settings: FC = ({ case SettingsScreens.GeneralChatBackground: return ( @@ -358,7 +352,6 @@ const Settings: FC = ({ return ( @@ -412,7 +405,6 @@ const Settings: FC = ({ ); @@ -433,7 +425,6 @@ const Settings: FC = ({ state={foldersState} dispatch={foldersDispatch} isActive={isScreenActive} - onScreenSelect={onScreenSelect} onReset={handleReset} /> ); @@ -461,7 +452,6 @@ const Settings: FC = ({ dispatch={twoFaDispatch} shownScreen={activeScreen} isActive={isScreenActive} - onScreenSelect={onScreenSelect} onReset={handleReset} /> ); @@ -482,7 +472,6 @@ const Settings: FC = ({ onSetPasscode={setPrivacyPasscode} shownScreen={activeScreen} isActive={isScreenActive} - onScreenSelect={onScreenSelect} onReset={handleReset} /> ); @@ -511,7 +500,6 @@ const Settings: FC = ({ {renderCurrentSectionContent(isScreenActive, activeKey)} diff --git a/src/components/left/settings/SettingsGeneral.tsx b/src/components/left/settings/SettingsGeneral.tsx index 9d859d6a4..d11c30c5a 100644 --- a/src/components/left/settings/SettingsGeneral.tsx +++ b/src/components/left/settings/SettingsGeneral.tsx @@ -26,7 +26,6 @@ import RangeSlider from '../../ui/RangeSlider'; type OwnProps = { isActive?: boolean; - onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; @@ -46,11 +45,10 @@ const SettingsGeneral: FC = ({ timeFormat, theme, shouldUseSystemTheme, - onScreenSelect, onReset, }) => { const { - setSharedSettingOption, + setSharedSettingOption, openSettingsScreen, } = getActions(); const lang = useLang(); @@ -146,7 +144,7 @@ const SettingsGeneral: FC = ({ icon="photo" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.GeneralChatBackground)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.GeneralChatBackground })} > {lang('ChatBackground')} diff --git a/src/components/left/settings/SettingsGeneralBackground.tsx b/src/components/left/settings/SettingsGeneralBackground.tsx index fcfcaf43e..91b40a27c 100644 --- a/src/components/left/settings/SettingsGeneralBackground.tsx +++ b/src/components/left/settings/SettingsGeneralBackground.tsx @@ -27,7 +27,6 @@ import './SettingsGeneralBackground.scss'; type OwnProps = { isActive?: boolean; - onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; @@ -44,7 +43,6 @@ const runThrottled = throttle((cb) => cb(), 60000, true); const SettingsGeneralBackground: FC = ({ isActive, - onScreenSelect, onReset, background, isBlurred, @@ -55,6 +53,7 @@ const SettingsGeneralBackground: FC = ({ loadWallpapers, uploadWallpaper, setThemeSettings, + openSettingsScreen, } = getActions(); const themeRef = useRef(); @@ -81,8 +80,8 @@ const SettingsGeneralBackground: FC = ({ }, [handleFileSelect]); const handleSetColor = useCallback(() => { - onScreenSelect(SettingsScreens.GeneralChatBackgroundColor); - }, [onScreenSelect]); + openSettingsScreen({ screen: SettingsScreens.GeneralChatBackgroundColor }); + }, []); const handleResetToDefault = useCallback(() => { setThemeSettings({ diff --git a/src/components/left/settings/SettingsHeader.tsx b/src/components/left/settings/SettingsHeader.tsx index 6172d088d..f656bfc39 100644 --- a/src/components/left/settings/SettingsHeader.tsx +++ b/src/components/left/settings/SettingsHeader.tsx @@ -21,25 +21,24 @@ type OwnProps = { currentScreen: SettingsScreens; editedFolderId?: number; onReset: () => void; - onScreenSelect: (screen: SettingsScreens) => void; }; const SettingsHeader: FC = ({ currentScreen, editedFolderId, onReset, - onScreenSelect, }) => { const { signOut, openDeleteChatFolderModal, + openSettingsScreen, } = getActions(); const { isMobile } = useAppLayout(); const [isSignOutDialogOpen, setIsSignOutDialogOpen] = useState(false); const handleMultiClick = useMultiClick(5, () => { - onScreenSelect(SettingsScreens.Experimental); + openSettingsScreen({ screen: SettingsScreens.Experimental }); }); const openSignOutConfirmation = useCallback(() => { @@ -270,7 +269,7 @@ const SettingsHeader: FC = ({ size="smaller" color="translucent" // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.EditProfile)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.EditProfile })} ariaLabel={oldLang('lng_settings_information')} > diff --git a/src/components/left/settings/SettingsLanguage.tsx b/src/components/left/settings/SettingsLanguage.tsx index 185d4900c..1b83136cb 100644 --- a/src/components/left/settings/SettingsLanguage.tsx +++ b/src/components/left/settings/SettingsLanguage.tsx @@ -25,7 +25,6 @@ import Loading from '../../ui/Loading'; type OwnProps = { isActive?: boolean; onReset: () => void; - onScreenSelect: (screen: SettingsScreens) => void; }; type StateProps = { @@ -41,7 +40,6 @@ const SettingsLanguage: FC = ({ canTranslate, canTranslateChats, doNotTranslate, - onScreenSelect, onReset, }) => { const { @@ -49,6 +47,7 @@ const SettingsLanguage: FC = ({ setSettingOption, setSharedSettingOption, openPremiumModal, + openSettingsScreen, } = getActions(); const [selectedLanguage, setSelectedLanguage] = useState(language); @@ -120,7 +119,7 @@ const SettingsLanguage: FC = ({ }, [doNotTranslate, lang, language]); const handleDoNotSelectOpen = useLastCallback(() => { - onScreenSelect(SettingsScreens.DoNotTranslate); + openSettingsScreen({ screen: SettingsScreens.DoNotTranslate }); }); useHistoryBack({ diff --git a/src/components/left/settings/SettingsMain.tsx b/src/components/left/settings/SettingsMain.tsx index 8b9f0cdac..bceebefb8 100644 --- a/src/components/left/settings/SettingsMain.tsx +++ b/src/components/left/settings/SettingsMain.tsx @@ -25,7 +25,6 @@ import ListItem from '../../ui/ListItem'; type OwnProps = { isActive?: boolean; - onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; @@ -44,7 +43,6 @@ const SettingsMain: FC = ({ canBuyPremium, isGiveawayAvailable, starsBalance, - onScreenSelect, onReset, }) => { const { @@ -54,6 +52,7 @@ const SettingsMain: FC = ({ openUrl, openGiftRecipientPicker, openStarsBalanceModal, + openSettingsScreen, } = getActions(); const [isSupportDialogOpen, openSupportDialog, closeSupportDialog] = useFlag(false); @@ -98,7 +97,7 @@ const SettingsMain: FC = ({ icon="settings" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.General)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.General })} > {lang('TelegramGeneralSettingsViewController')} @@ -106,7 +105,7 @@ const SettingsMain: FC = ({ icon="animations" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.Performance)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.Performance })} > {lang('MenuAnimations')} @@ -114,7 +113,7 @@ const SettingsMain: FC = ({ icon="unmute" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.Notifications)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.Notifications })} > {lang('Notifications')} @@ -122,7 +121,7 @@ const SettingsMain: FC = ({ icon="data" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.DataStorage)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.DataStorage })} > {lang('DataSettings')} @@ -130,7 +129,7 @@ const SettingsMain: FC = ({ icon="lock" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.Privacy)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.Privacy })} > {lang('PrivacySettings')} @@ -138,7 +137,7 @@ const SettingsMain: FC = ({ icon="folder" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.Folders)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.Folders })} > {lang('Filters')} @@ -146,7 +145,7 @@ const SettingsMain: FC = ({ icon="active-sessions" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.ActiveSessions)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.ActiveSessions })} > {lang('SessionsTitle')} {sessionCount > 0 && ({sessionCount})} @@ -155,7 +154,7 @@ const SettingsMain: FC = ({ icon="language" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.Language)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.Language })} > {lang('Language')} {lang.languageInfo.nativeName} @@ -164,7 +163,7 @@ const SettingsMain: FC = ({ icon="stickers" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.Stickers)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.Stickers })} > {lang('MenuStickers')} diff --git a/src/components/left/settings/SettingsPrivacy.tsx b/src/components/left/settings/SettingsPrivacy.tsx index c5f2370e3..1f920981d 100644 --- a/src/components/left/settings/SettingsPrivacy.tsx +++ b/src/components/left/settings/SettingsPrivacy.tsx @@ -22,7 +22,6 @@ import ListItem from '../../ui/ListItem'; type OwnProps = { isActive?: boolean; - onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; @@ -60,7 +59,6 @@ const SettingsPrivacy: FC = ({ canDisplayChatInTitle, canSetPasscode, privacy, - onScreenSelect, onReset, isCurrentUserFrozen, }) => { @@ -73,6 +71,7 @@ const SettingsPrivacy: FC = ({ updateGlobalPrivacySettings, loadWebAuthorizations, setSharedSettingOption, + openSettingsScreen, } = getActions(); useEffect(() => { @@ -160,7 +159,7 @@ const SettingsPrivacy: FC = ({ icon="delete-user" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.PrivacyBlockedUsers)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PrivacyBlockedUsers })} > {oldLang('BlockedUsers')} {blockedCount || ''} @@ -170,9 +169,9 @@ const SettingsPrivacy: FC = ({ icon="key" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect( - hasPasscode ? SettingsScreens.PasscodeEnabled : SettingsScreens.PasscodeDisabled, - )} + onClick={() => openSettingsScreen({ + screen: hasPasscode ? SettingsScreens.PasscodeEnabled : SettingsScreens.PasscodeDisabled, + })} >
{oldLang('Passcode')} @@ -186,9 +185,9 @@ const SettingsPrivacy: FC = ({ icon="lock" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect( - hasPassword ? SettingsScreens.TwoFaEnabled : SettingsScreens.TwoFaDisabled, - )} + onClick={() => openSettingsScreen({ + screen: hasPassword ? SettingsScreens.TwoFaEnabled : SettingsScreens.TwoFaDisabled, + })} >
{oldLang('TwoStepVerification')} @@ -202,7 +201,7 @@ const SettingsPrivacy: FC = ({ icon="web" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.ActiveWebsites)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.ActiveWebsites })} > {oldLang('PrivacySettings.WebSessions')} {webAuthCount} @@ -217,7 +216,7 @@ const SettingsPrivacy: FC = ({ narrow className="no-icon" // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.PrivacyPhoneNumber)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PrivacyPhoneNumber })} >
{oldLang('PrivacyPhoneTitle')} @@ -230,7 +229,7 @@ const SettingsPrivacy: FC = ({ narrow className="no-icon" // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.PrivacyLastSeen)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PrivacyLastSeen })} >
{oldLang('LastSeenTitle')} @@ -243,7 +242,7 @@ const SettingsPrivacy: FC = ({ narrow className="no-icon" // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.PrivacyProfilePhoto)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PrivacyProfilePhoto })} >
{oldLang('PrivacyProfilePhotoTitle')} @@ -256,7 +255,7 @@ const SettingsPrivacy: FC = ({ narrow className="no-icon" // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.PrivacyBio)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PrivacyBio })} >
{oldLang('PrivacyBio')} @@ -269,7 +268,7 @@ const SettingsPrivacy: FC = ({ narrow className="no-icon" // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.PrivacyBirthday)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PrivacyBirthday })} >
{oldLang('PrivacyBirthday')} @@ -282,7 +281,7 @@ const SettingsPrivacy: FC = ({ narrow className="no-icon" // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.PrivacyGifts)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PrivacyGifts })} >
{lang('PrivacyGifts')} @@ -295,7 +294,7 @@ const SettingsPrivacy: FC = ({ narrow className="no-icon" // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.PrivacyForwarding)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PrivacyForwarding })} >
{oldLang('PrivacyForwardsTitle')} @@ -308,7 +307,7 @@ const SettingsPrivacy: FC = ({ narrow className="no-icon" // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.PrivacyPhoneCall)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PrivacyPhoneCall })} >
{oldLang('WhoCanCallMe')} @@ -323,7 +322,7 @@ const SettingsPrivacy: FC = ({ rightElement={isCurrentUserPremium && } className="no-icon" // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.PrivacyVoiceMessages)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PrivacyVoiceMessages })} >
{oldLang('PrivacyVoiceMessagesTitle')} @@ -337,7 +336,7 @@ const SettingsPrivacy: FC = ({ rightElement={isCurrentUserPremium && } className="no-icon" // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.PrivacyMessages)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PrivacyMessages })} >
{oldLang('PrivacyMessagesTitle')} @@ -353,7 +352,7 @@ const SettingsPrivacy: FC = ({ narrow className="no-icon" // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.PrivacyGroupChats)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PrivacyGroupChats })} >
{oldLang('WhoCanAddMe')} diff --git a/src/components/left/settings/SettingsPrivacyVisibility.tsx b/src/components/left/settings/SettingsPrivacyVisibility.tsx index 274c0fa69..791e32991 100644 --- a/src/components/left/settings/SettingsPrivacyVisibility.tsx +++ b/src/components/left/settings/SettingsPrivacyVisibility.tsx @@ -26,7 +26,6 @@ import SettingsPrivacyPublicProfilePhoto from './SettingsPrivacyPublicProfilePho type OwnProps = { screen: SettingsScreens; isActive?: boolean; - onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; @@ -50,15 +49,14 @@ const SettingsPrivacyVisibility: FC = ({ hasCurrentUserFullInfo, currentUserFallbackPhoto, isPremiumRequired, - onScreenSelect, onReset, shouldDisplayGiftsButton, isCurrentUserPremium, }) => { - const lang = useLang(); - const { updateGlobalPrivacySettings, showNotification } = getActions(); + const lang = useLang(); + useHistoryBack({ isActive, onBack: onReset, @@ -120,7 +118,6 @@ const SettingsPrivacyVisibility: FC = ({ {screen === SettingsScreens.PrivacyProfilePhoto && primaryPrivacy?.visibility !== 'everybody' && ( @@ -140,7 +137,6 @@ const SettingsPrivacyVisibility: FC = ({ )}
@@ -150,15 +146,13 @@ const SettingsPrivacyVisibility: FC = ({ function PrivacySubsection({ screen, privacy, - onScreenSelect, isPremiumRequired, }: { screen: SettingsScreens; privacy?: ApiPrivacySettings; isPremiumRequired?: boolean; - onScreenSelect: (screen: SettingsScreens) => void; }) { - const { setPrivacyVisibility } = getActions(); + const { setPrivacyVisibility, openSettingsScreen } = getActions(); const oldLang = useOldLang(); const lang = useLang(); @@ -376,7 +370,7 @@ function PrivacySubsection({ icon="add-user" // eslint-disable-next-line react/jsx-no-bind onClick={() => { - onScreenSelect(allowedContactsScreen); + openSettingsScreen({ screen: allowedContactsScreen }); }} >
@@ -391,7 +385,7 @@ function PrivacySubsection({ icon="delete-user" // eslint-disable-next-line react/jsx-no-bind onClick={() => { - onScreenSelect(deniedContactsScreen); + openSettingsScreen({ screen: deniedContactsScreen }); }} >
diff --git a/src/components/left/settings/SettingsStickers.tsx b/src/components/left/settings/SettingsStickers.tsx index b58d5997b..6208729dc 100644 --- a/src/components/left/settings/SettingsStickers.tsx +++ b/src/components/left/settings/SettingsStickers.tsx @@ -31,7 +31,6 @@ const DEFAULT_REACTION_SIZE = 1.5 * REM; type OwnProps = { isActive?: boolean; - onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; @@ -58,11 +57,11 @@ const SettingsStickers: FC = ({ availableReactions, canPlayAnimatedEmojis, onReset, - onScreenSelect, }) => { const { setSettingOption, openStickerSet, + openSettingsScreen, } = getActions(); const lang = useOldLang(); @@ -104,7 +103,7 @@ const SettingsStickers: FC = ({ onScreenSelect(SettingsScreens.CustomEmoji)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.CustomEmoji })} icon="smile" > {lang('StickersList.EmojiItem')} @@ -115,7 +114,7 @@ const SettingsStickers: FC = ({ className="SettingsDefaultReaction" narrow // eslint-disable-next-line react/jsx-no-bind - onClick={() => onScreenSelect(SettingsScreens.QuickReaction)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.QuickReaction })} > void; onReset: () => void; }; @@ -33,13 +32,13 @@ const SettingsFolders: FC = ({ state, dispatch, isActive, - onScreenSelect, onReset, }) => { const { openShareChatFolderModal, editChatFolder, addChatFolder, + openSettingsScreen, } = getActions(); const handleReset = useCallback(() => { @@ -59,18 +58,15 @@ const SettingsFolders: FC = ({ || currentScreen === SettingsScreens.FoldersExcludedChats ) { if (state.mode === 'create') { - onScreenSelect(SettingsScreens.FoldersCreateFolder); + openSettingsScreen({ screen: SettingsScreens.FoldersCreateFolder }); } else { - onScreenSelect(SettingsScreens.FoldersEditFolder); + openSettingsScreen({ screen: SettingsScreens.FoldersEditFolder }); } return; } onReset(); - }, [ - state.mode, dispatch, - currentScreen, onReset, onScreenSelect, - ]); + }, [state.mode, dispatch, currentScreen, onReset]); const isCreating = state.mode === 'create'; @@ -119,38 +115,42 @@ const SettingsFolders: FC = ({ const handleCreateFolder = useCallback(() => { dispatch({ type: 'reset' }); - onScreenSelect(SettingsScreens.FoldersCreateFolder); - }, [onScreenSelect, dispatch]); + openSettingsScreen({ screen: SettingsScreens.FoldersCreateFolder }); + }, [dispatch]); const handleEditFolder = useCallback((folder: ApiChatFolder) => { dispatch({ type: 'editFolder', payload: folder }); - onScreenSelect(SettingsScreens.FoldersEditFolder); - }, [dispatch, onScreenSelect]); + openSettingsScreen({ screen: SettingsScreens.FoldersEditFolder }); + }, [dispatch]); const handleAddIncludedChats = useCallback(() => { dispatch({ type: 'editIncludeFilters' }); - onScreenSelect(currentScreen === SettingsScreens.FoldersEditFolderFromChatList - ? SettingsScreens.FoldersIncludedChatsFromChatList - : SettingsScreens.FoldersIncludedChats); - }, [currentScreen, dispatch, onScreenSelect]); + openSettingsScreen({ + screen: currentScreen === SettingsScreens.FoldersEditFolderFromChatList + ? SettingsScreens.FoldersIncludedChatsFromChatList + : SettingsScreens.FoldersIncludedChats, + }); + }, [currentScreen, dispatch]); const handleAddExcludedChats = useCallback(() => { dispatch({ type: 'editExcludeFilters' }); - onScreenSelect(currentScreen === SettingsScreens.FoldersEditFolderFromChatList - ? SettingsScreens.FoldersExcludedChatsFromChatList - : SettingsScreens.FoldersExcludedChats); - }, [currentScreen, dispatch, onScreenSelect]); + openSettingsScreen({ + screen: currentScreen === SettingsScreens.FoldersEditFolderFromChatList + ? SettingsScreens.FoldersExcludedChatsFromChatList + : SettingsScreens.FoldersExcludedChats, + }); + }, [currentScreen, dispatch]); const handleShareFolder = useCallback(() => { openShareChatFolderModal({ folderId: state.folderId!, noRequestNextScreen: true }); dispatch({ type: 'setIsChatlist', payload: true }); - onScreenSelect(SettingsScreens.FoldersShare); - }, [dispatch, onScreenSelect, state.folderId]); + openSettingsScreen({ screen: SettingsScreens.FoldersShare }); + }, [dispatch, state.folderId]); const handleOpenInvite = useCallback((url: string) => { openShareChatFolderModal({ folderId: state.folderId!, url, noRequestNextScreen: true }); - onScreenSelect(SettingsScreens.FoldersShare); - }, [onScreenSelect, state.folderId]); + openSettingsScreen({ screen: SettingsScreens.FoldersShare }); + }, [state.folderId]); switch (currentScreen) { case SettingsScreens.Folders: diff --git a/src/components/left/settings/passcode/SettingsPasscode.tsx b/src/components/left/settings/passcode/SettingsPasscode.tsx index 6eeb128db..5fd359118 100644 --- a/src/components/left/settings/passcode/SettingsPasscode.tsx +++ b/src/components/left/settings/passcode/SettingsPasscode.tsx @@ -20,7 +20,6 @@ export type OwnProps = { shownScreen: SettingsScreens; isActive?: boolean; onSetPasscode: (passcode: string) => void; - onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; @@ -33,7 +32,6 @@ const SettingsPasscode: FC = ({ error, isActive, isLoading, - onScreenSelect, onSetPasscode, onReset, }) => { @@ -42,52 +40,53 @@ const SettingsPasscode: FC = ({ clearPasscode, setPasscodeError, clearPasscodeError, + openSettingsScreen, } = getActions(); const lang = useOldLang(); const handleStartWizard = useCallback(() => { onSetPasscode(''); - onScreenSelect(SettingsScreens.PasscodeNewPasscode); - }, [onScreenSelect, onSetPasscode]); + openSettingsScreen({ screen: SettingsScreens.PasscodeNewPasscode }); + }, [onSetPasscode]); const handleNewPassword = useCallback((value: string) => { onSetPasscode(value); - onScreenSelect(SettingsScreens.PasscodeNewPasscodeConfirm); - }, [onScreenSelect, onSetPasscode]); + openSettingsScreen({ screen: SettingsScreens.PasscodeNewPasscodeConfirm }); + }, [onSetPasscode]); const handleNewPasswordConfirm = useCallback(() => { setPasscode({ passcode }); onSetPasscode(''); - onScreenSelect(SettingsScreens.PasscodeCongratulations); - }, [onScreenSelect, onSetPasscode, passcode, setPasscode]); + openSettingsScreen({ screen: SettingsScreens.PasscodeCongratulations }); + }, [onSetPasscode, passcode]); const handleChangePasswordCurrent = useCallback((currentPasscode: string) => { onSetPasscode(''); decryptSession(currentPasscode).then(() => { - onScreenSelect(SettingsScreens.PasscodeChangePasscodeNew); + openSettingsScreen({ screen: SettingsScreens.PasscodeChangePasscodeNew }); }, () => { setPasscodeError({ error: lang('PasscodeController.Error.Current'), }); }); - }, [lang, onScreenSelect, onSetPasscode, setPasscodeError]); + }, [lang, onSetPasscode]); const handleChangePasswordNew = useCallback((value: string) => { onSetPasscode(value); - onScreenSelect(SettingsScreens.PasscodeChangePasscodeConfirm); - }, [onScreenSelect, onSetPasscode]); + openSettingsScreen({ screen: SettingsScreens.PasscodeChangePasscodeConfirm }); + }, [onSetPasscode]); const handleTurnOff = useCallback((currentPasscode: string) => { decryptSession(currentPasscode).then(() => { clearPasscode(); - onScreenSelect(SettingsScreens.Privacy); + openSettingsScreen({ screen: SettingsScreens.Privacy }); }, () => { setPasscodeError({ error: lang('PasscodeController.Error.Current'), }); }); - }, [clearPasscode, lang, onScreenSelect, setPasscodeError]); + }, [lang]); switch (currentScreen) { case SettingsScreens.PasscodeDisabled: @@ -145,7 +144,6 @@ const SettingsPasscode: FC = ({ case SettingsScreens.PasscodeEnabled: return ( void; onReset: () => void; }; const SettingsPasscodeEnabled: FC = ({ - isActive, onReset, onScreenSelect, + isActive, onReset, }) => { + const { openSettingsScreen } = getActions(); const lang = useOldLang(); useHistoryBack({ isActive, onBack: onReset }); @@ -45,14 +46,14 @@ const SettingsPasscodeEnabled: FC = ({ onScreenSelect(SettingsScreens.PasscodeChangePasscodeCurrent)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PasscodeChangePasscodeCurrent })} > {lang('Passcode.Change')} onScreenSelect(SettingsScreens.PasscodeTurnOff)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.PasscodeTurnOff })} > {lang('Passcode.TurnOff')} diff --git a/src/components/left/settings/twoFa/SettingsTwoFa.tsx b/src/components/left/settings/twoFa/SettingsTwoFa.tsx index cddae79cd..8d47baf0d 100644 --- a/src/components/left/settings/twoFa/SettingsTwoFa.tsx +++ b/src/components/left/settings/twoFa/SettingsTwoFa.tsx @@ -22,7 +22,6 @@ export type OwnProps = { shownScreen: SettingsScreens; dispatch: TwoFaDispatch; isActive?: boolean; - onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; @@ -38,7 +37,6 @@ const SettingsTwoFa: FC = ({ waitingEmailCodeLength, dispatch, isActive, - onScreenSelect, onReset, }) => { const { @@ -48,6 +46,7 @@ const SettingsTwoFa: FC = ({ updateRecoveryEmail, provideTwoFaEmailCode, clearPassword, + openSettingsScreen, } = getActions(); const lang = useLang(); @@ -56,31 +55,31 @@ const SettingsTwoFa: FC = ({ useEffect(() => { if (waitingEmailCodeLength) { if (currentScreen === SettingsScreens.TwoFaNewPasswordEmail) { - onScreenSelect(SettingsScreens.TwoFaNewPasswordEmailCode); + openSettingsScreen({ screen: SettingsScreens.TwoFaNewPasswordEmailCode }); } else if (currentScreen === SettingsScreens.TwoFaRecoveryEmail) { - onScreenSelect(SettingsScreens.TwoFaRecoveryEmailCode); + openSettingsScreen({ screen: SettingsScreens.TwoFaRecoveryEmailCode }); } } - }, [currentScreen, onScreenSelect, waitingEmailCodeLength]); + }, [currentScreen, waitingEmailCodeLength, openSettingsScreen]); const handleStartWizard = useCallback(() => { dispatch({ type: 'reset' }); - onScreenSelect(SettingsScreens.TwoFaNewPassword); - }, [dispatch, onScreenSelect]); + openSettingsScreen({ screen: SettingsScreens.TwoFaNewPassword }); + }, [dispatch, openSettingsScreen]); const handleNewPassword = useCallback((value: string) => { dispatch({ type: 'setPassword', payload: value }); - onScreenSelect(SettingsScreens.TwoFaNewPasswordConfirm); - }, [dispatch, onScreenSelect]); + openSettingsScreen({ screen: SettingsScreens.TwoFaNewPasswordConfirm }); + }, [dispatch, openSettingsScreen]); const handleNewPasswordConfirm = useCallback(() => { - onScreenSelect(SettingsScreens.TwoFaNewPasswordHint); - }, [onScreenSelect]); + openSettingsScreen({ screen: SettingsScreens.TwoFaNewPasswordHint }); + }, [openSettingsScreen]); const handleNewPasswordHint = useCallback((value?: string) => { dispatch({ type: 'setHint', payload: value }); - onScreenSelect(SettingsScreens.TwoFaNewPasswordEmail); - }, [dispatch, onScreenSelect]); + openSettingsScreen({ screen: SettingsScreens.TwoFaNewPasswordEmail }); + }, [dispatch, openSettingsScreen]); const handleNewPasswordEmail = useCallback((value?: string) => { dispatch({ type: 'setEmail', payload: value }); @@ -88,29 +87,29 @@ const SettingsTwoFa: FC = ({ ...state, email: value, onSuccess: () => { - onScreenSelect(SettingsScreens.TwoFaCongratulations); + openSettingsScreen({ screen: SettingsScreens.TwoFaCongratulations }); }, }); - }, [dispatch, onScreenSelect, state, updatePassword]); + }, [dispatch, state, updatePassword, openSettingsScreen]); const handleChangePasswordCurrent = useCallback((value: string) => { dispatch({ type: 'setCurrentPassword', payload: value }); checkPassword({ currentPassword: value, onSuccess: () => { - onScreenSelect(SettingsScreens.TwoFaChangePasswordNew); + openSettingsScreen({ screen: SettingsScreens.TwoFaChangePasswordNew }); }, }); - }, [checkPassword, dispatch, onScreenSelect]); + }, [checkPassword, dispatch, openSettingsScreen]); const handleChangePasswordNew = useCallback((value: string) => { dispatch({ type: 'setPassword', payload: value }); - onScreenSelect(SettingsScreens.TwoFaChangePasswordConfirm); - }, [dispatch, onScreenSelect]); + openSettingsScreen({ screen: SettingsScreens.TwoFaChangePasswordConfirm }); + }, [dispatch, openSettingsScreen]); const handleChangePasswordConfirm = useCallback(() => { - onScreenSelect(SettingsScreens.TwoFaChangePasswordHint); - }, [onScreenSelect]); + openSettingsScreen({ screen: SettingsScreens.TwoFaChangePasswordHint }); + }, [openSettingsScreen]); const handleChangePasswordHint = useCallback((value?: string) => { dispatch({ type: 'setHint', payload: value }); @@ -118,29 +117,29 @@ const SettingsTwoFa: FC = ({ ...state, hint: value, onSuccess: () => { - onScreenSelect(SettingsScreens.TwoFaCongratulations); + openSettingsScreen({ screen: SettingsScreens.TwoFaCongratulations }); }, }); - }, [dispatch, onScreenSelect, state, updatePassword]); + }, [dispatch, state, updatePassword, openSettingsScreen]); const handleTurnOff = useCallback((value: string) => { clearPassword({ currentPassword: value, onSuccess: () => { - onScreenSelect(SettingsScreens.Privacy); + openSettingsScreen({ screen: SettingsScreens.Privacy }); }, }); - }, [clearPassword, onScreenSelect]); + }, [clearPassword, openSettingsScreen]); const handleRecoveryEmailCurrentPassword = useCallback((value: string) => { dispatch({ type: 'setCurrentPassword', payload: value }); checkPassword({ currentPassword: value, onSuccess: () => { - onScreenSelect(SettingsScreens.TwoFaRecoveryEmail); + openSettingsScreen({ screen: SettingsScreens.TwoFaRecoveryEmail }); }, }); - }, [checkPassword, dispatch, onScreenSelect]); + }, [checkPassword, dispatch, openSettingsScreen]); const handleRecoveryEmail = useCallback((value?: string) => { dispatch({ type: 'setEmail', payload: value }); @@ -148,10 +147,10 @@ const SettingsTwoFa: FC = ({ ...state, email: value!, onSuccess: () => { - onScreenSelect(SettingsScreens.TwoFaCongratulations); + openSettingsScreen({ screen: SettingsScreens.TwoFaCongratulations }); }, }); - }, [dispatch, onScreenSelect, state, updateRecoveryEmail]); + }, [dispatch, state, updateRecoveryEmail, openSettingsScreen]); const handleEmailCode = useCallback((code: string) => { provideTwoFaEmailCode({ code }); @@ -257,7 +256,6 @@ const SettingsTwoFa: FC = ({ case SettingsScreens.TwoFaCongratulations: return ( @@ -266,7 +264,6 @@ const SettingsTwoFa: FC = ({ case SettingsScreens.TwoFaEnabled: return ( void; onReset: () => void; }; const SettingsTwoFaCongratulations: FC = ({ - isActive, onReset, onScreenSelect, + isActive, onReset, }) => { + const { openSettingsScreen } = getActions(); const lang = useOldLang(); - const handleClick = useCallback(() => { - onScreenSelect(SettingsScreens.Privacy); - }, [onScreenSelect]); + const handleClick = useLastCallback(() => { + openSettingsScreen({ screen: SettingsScreens.Privacy }); + }); useHistoryBack({ isActive, diff --git a/src/components/left/settings/twoFa/SettingsTwoFaEnabled.tsx b/src/components/left/settings/twoFa/SettingsTwoFaEnabled.tsx index 0ada082a8..61ba4ee16 100644 --- a/src/components/left/settings/twoFa/SettingsTwoFaEnabled.tsx +++ b/src/components/left/settings/twoFa/SettingsTwoFaEnabled.tsx @@ -1,5 +1,6 @@ import type { FC } from '../../../../lib/teact/teact'; import React, { memo } from '../../../../lib/teact/teact'; +import { getActions } from '../../../../global'; import { SettingsScreens } from '../../../../types'; @@ -16,13 +17,13 @@ import lockPreviewUrl from '../../../../assets/lock.png'; type OwnProps = { isActive?: boolean; - onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; const SettingsTwoFaEnabled: FC = ({ - isActive, onReset, onScreenSelect, + isActive, onReset, }) => { + const { openSettingsScreen } = getActions(); const lang = useOldLang(); useHistoryBack({ @@ -49,21 +50,21 @@ const SettingsTwoFaEnabled: FC = ({ onScreenSelect(SettingsScreens.TwoFaChangePasswordCurrent)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.TwoFaChangePasswordCurrent })} > {lang('ChangePassword')} onScreenSelect(SettingsScreens.TwoFaTurnOff)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.TwoFaTurnOff })} > {lang('TurnPasswordOff')} onScreenSelect(SettingsScreens.TwoFaRecoveryEmailCurrentPassword)} + onClick={() => openSettingsScreen({ screen: SettingsScreens.TwoFaRecoveryEmailCurrentPassword })} > {lang('SetRecoveryEmail')} diff --git a/src/components/middle/message/actions/SuggestedPhoto.tsx b/src/components/middle/message/actions/SuggestedPhoto.tsx index f25a10adc..bbafa4d32 100644 --- a/src/components/middle/message/actions/SuggestedPhoto.tsx +++ b/src/components/middle/message/actions/SuggestedPhoto.tsx @@ -67,7 +67,7 @@ const SuggestedPhotoAction = ({ title: lang('ActionSuggestedPhotoUpdatedTitle'), message: lang('ActionSuggestedPhotoUpdatedDescription'), action: { - action: 'requestNextSettingsScreen', + action: 'openSettingsScreen', payload: { screen: SettingsScreens.Main, }, diff --git a/src/components/modals/gift/withdraw/GiftWithdrawModal.tsx b/src/components/modals/gift/withdraw/GiftWithdrawModal.tsx index 5673083c7..6d4d5ee11 100644 --- a/src/components/modals/gift/withdraw/GiftWithdrawModal.tsx +++ b/src/components/modals/gift/withdraw/GiftWithdrawModal.tsx @@ -6,7 +6,7 @@ import { getActions, withGlobal } from '../../../../global'; import type { ApiStarGiftUnique } from '../../../../api/types'; import type { TabState } from '../../../../global/types'; -import type { CustomPeer } from '../../../../types'; +import { type CustomPeer, SettingsScreens } from '../../../../types'; import { getDays } from '../../../../util/dates/units'; import { getServerTime } from '../../../../util/serverTime'; @@ -22,6 +22,7 @@ import Avatar from '../../../common/Avatar'; import Icon from '../../../common/icons/Icon'; import PasswordForm from '../../../common/PasswordForm'; import RadialPatternBackground from '../../../common/profile/RadialPatternBackground'; +import Button from '../../../ui/Button'; import Modal from '../../../ui/Modal'; import styles from './GiftWithdrawModal.module.scss'; @@ -44,7 +45,13 @@ const FRAGMENT_PEER: CustomPeer = { const GIFT_STICKER_SIZE = 4.5 * REM; const GiftWithdrawModal = ({ modal, hasPassword, passwordHint }: OwnProps & StateProps) => { - const { closeGiftWithdrawModal, clearGiftWithdrawError, processStarGiftWithdrawal } = getActions(); + const { + closeGiftWithdrawModal, + clearGiftWithdrawError, + closeGiftInfoModal, + processStarGiftWithdrawal, + openSettingsScreen, + } = getActions(); const isOpen = Boolean(modal); const [shouldShowPassword, setShouldShowPassword] = useState(false); @@ -68,6 +75,14 @@ const GiftWithdrawModal = ({ modal, hasPassword, passwordHint }: OwnProps & Stat }); }); + const handleSetUpPassword = useLastCallback(() => { + openSettingsScreen({ + screen: SettingsScreens.TwoFaDisabled, + }); + closeGiftWithdrawModal(); + closeGiftInfoModal(); + }); + return ( )} - {!hasPassword && {lang('ErrorPasswordMissing')}} + {!hasPassword && ( + <> + {lang('ErrorPasswordMissing')} + + + )} {hasPassword && !exportDelay && ( message: 'Failed to set passcode', tabId, }); - actions.requestNextSettingsScreen({ screen: SettingsScreens.PasscodeDisabled, tabId }); + actions.openSettingsScreen({ screen: SettingsScreens.PasscodeDisabled, tabId }); } }); diff --git a/src/global/actions/ui/settings.ts b/src/global/actions/ui/settings.ts index 7b14b341c..0bd6d9efe 100644 --- a/src/global/actions/ui/settings.ts +++ b/src/global/actions/ui/settings.ts @@ -1,7 +1,7 @@ import { addCallback } from '../../../lib/teact/teactn'; import type { ActionReturnType, GlobalState } from '../../types'; -import { type LangCode, SettingsScreens } from '../../../types'; +import { type LangCode, LeftColumnContent, SettingsScreens } from '../../../types'; import { requestMutation } from '../../../lib/fasterdom/fasterdom'; import { IS_IOS } from '../../../util/browser/windowEnvironment'; @@ -17,7 +17,7 @@ import { } from '../../index'; import { replaceSettings, updateSharedSettings, updateThemeSettings } from '../../reducers'; import { updateTabState } from '../../reducers/tabs'; -import { selectCanAnimateInterface, selectChatFolder } from '../../selectors'; +import { selectCanAnimateInterface, selectChatFolder, selectTabState } from '../../selectors'; import { selectSharedSettings } from '../../selectors/sharedState'; let prevGlobal: GlobalState | undefined; @@ -142,22 +142,48 @@ addActionHandler('setThemeSettings', (global, actions, payload): ActionReturnTyp return updateThemeSettings(global, theme, settings); }); -addActionHandler('requestNextSettingsScreen', (global, actions, payload): ActionReturnType => { - const { screen, foldersAction, tabId = getCurrentTabId() } = payload; +addActionHandler('requestNextFoldersAction', (global, actions, payload): ActionReturnType => { + const { foldersAction, tabId = getCurrentTabId() } = payload; return updateTabState(global, { - nextSettingsScreen: screen, nextFoldersAction: foldersAction, }, tabId); }); +addActionHandler('openLeftColumnContent', (global, actions, payload): ActionReturnType => { + const { contentKey = LeftColumnContent.ChatList, tabId = getCurrentTabId() } = payload; + const tabState = selectTabState(global, tabId); + return updateTabState(global, { + leftColumn: { + ...tabState.leftColumn, + contentKey, + }, + }, tabId); +}); + +addActionHandler('openSettingsScreen', (global, actions, payload): ActionReturnType => { + const { screen = SettingsScreens.Main, tabId = getCurrentTabId() } = payload; + const tabState = selectTabState(global, tabId); + // Force settings only if new screen is passed, do not on resets + if (payload.screen) actions.openLeftColumnContent({ contentKey: LeftColumnContent.Settings, tabId }); + return updateTabState(global, { + leftColumn: { + ...tabState.leftColumn, + settingsScreen: screen, + }, + }, tabId); +}); + addActionHandler('openEditChatFolder', (global, actions, payload): ActionReturnType => { const { folderId, isOnlyInvites, tabId = getCurrentTabId() } = payload; const chatFolder = selectChatFolder(global, folderId); if (!chatFolder) return; - actions.requestNextSettingsScreen({ + actions.openSettingsScreen({ screen: isOnlyInvites ? SettingsScreens.FoldersEditFolderInvites : SettingsScreens.FoldersEditFolderFromChatList, + tabId, + }); + actions.requestNextFoldersAction({ foldersAction: { type: 'editFolder', payload: chatFolder, @@ -178,7 +204,7 @@ addActionHandler('openShareChatFolderModal', (global, actions, payload): ActionR return undefined; } - if (!noRequestNextScreen) actions.requestNextSettingsScreen({ screen: SettingsScreens.FoldersShare, tabId }); + if (!noRequestNextScreen) actions.openSettingsScreen({ screen: SettingsScreens.FoldersShare, tabId }); return updateTabState(global, { shareFolderScreen: { @@ -192,7 +218,7 @@ addActionHandler('openShareChatFolderModal', (global, actions, payload): ActionR addActionHandler('closeShareChatFolderModal', (global, actions, payload): ActionReturnType => { const { tabId = getCurrentTabId() } = payload || {}; - actions.requestNextSettingsScreen({ screen: undefined, tabId }); + actions.openSettingsScreen({ screen: undefined, tabId }); return updateTabState(global, { shareFolderScreen: undefined, diff --git a/src/global/initialState.ts b/src/global/initialState.ts index 87eb9b8be..757321a63 100644 --- a/src/global/initialState.ts +++ b/src/global/initialState.ts @@ -1,6 +1,6 @@ import type { PerformanceType } from '../types'; import type { GlobalState, SharedState, TabState } from './types'; -import { NewChatMembersProgress } from '../types'; +import { LeftColumnContent, NewChatMembersProgress, SettingsScreens } from '../types'; import { ANIMATION_LEVEL_DEFAULT, @@ -361,6 +361,11 @@ export const INITIAL_TAB_STATE: TabState = { userSearch: {}, + leftColumn: { + contentKey: LeftColumnContent.ChatList, + settingsScreen: SettingsScreens.Main, + }, + middleSearch: { byChatThreadKey: {}, }, diff --git a/src/global/selectors/ui.ts b/src/global/selectors/ui.ts index 90ad12cba..a35f4c450 100644 --- a/src/global/selectors/ui.ts +++ b/src/global/selectors/ui.ts @@ -168,3 +168,15 @@ export function selectActiveWebApp( return selectWebApp(global, activeWebAppKey, tabId); } + +export function selectLeftColumnContentKey( + global: T, ...[tabId = getCurrentTabId()]: TabArgs +) { + return selectTabState(global, tabId).leftColumn.contentKey; +} + +export function selectSettingsScreen( + global: T, ...[tabId = getCurrentTabId()]: TabArgs +) { + return selectTabState(global, tabId).leftColumn.settingsScreen; +} diff --git a/src/global/types/actions.ts b/src/global/types/actions.ts index a60471ed5..4f3668cbc 100644 --- a/src/global/types/actions.ts +++ b/src/global/types/actions.ts @@ -67,6 +67,7 @@ import type { GlobalSearchContent, IAnchorPosition, IThemeSettings, + LeftColumnContent, LoadMoreDirection, ManagementScreens, MediaViewerMedia, @@ -2308,8 +2309,13 @@ export interface ActionPayloads { } | undefined; loadPeerColors: undefined; loadTimezones: undefined; - requestNextSettingsScreen: { + openLeftColumnContent: { + contentKey?: LeftColumnContent; + } & WithTabId; + openSettingsScreen: { screen?: SettingsScreens; + } & WithTabId; + requestNextFoldersAction: { foldersAction?: ReducerAction; } & WithTabId; sortChatFolders: { folderIds: number[] }; diff --git a/src/global/types/tabState.ts b/src/global/types/tabState.ts index 5e9e3e554..49bbea0fe 100644 --- a/src/global/types/tabState.ts +++ b/src/global/types/tabState.ts @@ -65,6 +65,7 @@ import type { GlobalSearchContent, IAnchorPosition, InlineBotSettings, + LeftColumnContent, ManagementProgress, ManagementState, MediaViewerMedia, @@ -120,7 +121,6 @@ export type TabState = { shouldCloseRightColumn?: boolean; nextProfileTab?: ProfileTabType; forceScrollProfileTab?: boolean; - nextSettingsScreen?: SettingsScreens; nextFoldersAction?: ReducerAction; shareFolderScreen?: { folderId: number; @@ -217,6 +217,11 @@ export type TabState = { filter: GiftProfileFilterOptions; }; + leftColumn: { + contentKey: LeftColumnContent; + settingsScreen: SettingsScreens; + }; + globalSearch: { query?: string; minDate?: number; diff --git a/src/types/language.d.ts b/src/types/language.d.ts index 0287c6cf8..21af3fcd0 100644 --- a/src/types/language.d.ts +++ b/src/types/language.d.ts @@ -1368,6 +1368,7 @@ export interface LangPair { 'GiftFilterHidden': undefined; 'GiftSearchEmpty': undefined; 'GiftSearchReset': undefined; + 'SetUp2FA': undefined; 'CheckPasswordTitle': undefined; 'CheckPasswordPlaceholder': undefined; 'CheckPasswordDescription': undefined;