import type { FC } from '../../../lib/teact/teact'; import React, { memo, useEffect } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import { SettingsScreens } from '../../../types'; import { FAQ_URL, PRIVACY_URL } from '../../../config'; import { selectIsGiveawayGiftsPurchaseAvailable, selectIsPremiumPurchaseBlocked, } from '../../../global/selectors'; import { formatInteger } from '../../../util/textFormat'; import useFlag from '../../../hooks/useFlag'; import useHistoryBack from '../../../hooks/useHistoryBack'; import useLastCallback from '../../../hooks/useLastCallback'; import useOldLang from '../../../hooks/useOldLang'; import StarIcon from '../../common/icons/StarIcon'; import ChatExtra from '../../common/profile/ChatExtra'; import ProfileInfo from '../../common/ProfileInfo'; import ConfirmDialog from '../../ui/ConfirmDialog'; import ListItem from '../../ui/ListItem'; type OwnProps = { isActive?: boolean; onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; type StateProps = { sessionCount: number; currentUserId?: string; canBuyPremium?: boolean; isGiveawayAvailable?: boolean; starsBalance?: number; shouldDisplayStars?: boolean; }; const SettingsMain: FC = ({ isActive, currentUserId, sessionCount, canBuyPremium, isGiveawayAvailable, starsBalance, shouldDisplayStars, onScreenSelect, onReset, }) => { const { loadMoreProfilePhotos, openPremiumModal, openSupportChat, openUrl, openPremiumGiftingModal, openStarsBalanceModal, } = getActions(); const [isSupportDialogOpen, openSupportDialog, closeSupportDialog] = useFlag(false); const lang = useOldLang(); useEffect(() => { if (currentUserId) { loadMoreProfilePhotos({ peerId: currentUserId, isPreload: true }); } }, [currentUserId]); useHistoryBack({ isActive, onBack: onReset, }); const handleOpenSupport = useLastCallback(() => { openSupportChat(); closeSupportDialog(); }); return (
{currentUserId && ( )} {currentUserId && ( )} onScreenSelect(SettingsScreens.General)} > {lang('Telegram.GeneralSettingsViewController')} onScreenSelect(SettingsScreens.Performance)} > {lang('Animations and Performance')} onScreenSelect(SettingsScreens.Notifications)} > {lang('Notifications')} onScreenSelect(SettingsScreens.DataStorage)} > {lang('DataSettings')} onScreenSelect(SettingsScreens.Privacy)} > {lang('PrivacySettings')} onScreenSelect(SettingsScreens.Folders)} > {lang('Filters')} onScreenSelect(SettingsScreens.ActiveSessions)} > {lang('SessionsTitle')} {sessionCount > 0 && ({sessionCount})} onScreenSelect(SettingsScreens.Language)} > {lang('Language')} {lang.langName} onScreenSelect(SettingsScreens.Stickers)} > {lang('StickersName')}
{canBuyPremium && ( } narrow // eslint-disable-next-line react/jsx-no-bind onClick={() => openPremiumModal()} > {lang('TelegramPremium')} )} {shouldDisplayStars && ( } narrow // eslint-disable-next-line react/jsx-no-bind onClick={() => openStarsBalanceModal({})} > {lang('MenuTelegramStars')} {Boolean(starsBalance) && ( {formatInteger(starsBalance)} )} )} {isGiveawayAvailable && ( openPremiumGiftingModal()} > {lang('GiftPremiumGifting')} )}
{lang('AskAQuestion')} openUrl({ url: FAQ_URL })} > {lang('TelegramFaq')} openUrl({ url: PRIVACY_URL })} > {lang('PrivacyPolicy')}
); }; export default memo(withGlobal( (global): StateProps => { const { currentUserId } = global; const isGiveawayAvailable = selectIsGiveawayGiftsPurchaseAvailable(global); const starsBalance = global.stars?.balance; const shouldDisplayStars = Boolean(global.stars?.history?.all?.transactions.length); return { sessionCount: global.activeSessions.orderedHashes.length, currentUserId, canBuyPremium: !selectIsPremiumPurchaseBlocked(global), isGiveawayAvailable, starsBalance, shouldDisplayStars, }; }, )(SettingsMain));