import React, { memo, useEffect, useState } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; import type { ApiStealthMode } from '../../api/types'; import { selectIsCurrentUserPremium, selectTabState } from '../../global/selectors'; import buildClassName from '../../util/buildClassName'; import { getServerTime } from '../../util/serverTime'; import useLang from '../../hooks/useLang'; import useLastCallback from '../../hooks/useLastCallback'; import Button from '../ui/Button'; import ListItem from '../ui/ListItem'; import Modal from '../ui/Modal'; import TextTimer from '../ui/TextTimer'; import styles from './StealthModeModal.module.scss'; type StateProps = { isOpen?: boolean; stealthMode?: ApiStealthMode; isCurrentUserPremium?: boolean; }; const StealthModeModal = ({ isOpen, stealthMode, isCurrentUserPremium } : StateProps) => { const { toggleStealthModal, activateStealthMode, showNotification, openPremiumModal, } = getActions(); const [isOnCooldown, setIsOnCooldown] = useState(false); useEffect(() => { if (!stealthMode) return; const serverTime = getServerTime(); if (stealthMode.cooldownUntil && stealthMode.cooldownUntil > serverTime) { setIsOnCooldown(true); } }, [stealthMode, isOpen]); const lang = useLang(); const handleTimerEnds = useLastCallback(() => { setIsOnCooldown(false); }); const handleClose = useLastCallback(() => { toggleStealthModal({ isOpen: false }); }); const handleActivate = useLastCallback(() => { if (!isCurrentUserPremium) { openPremiumModal({ initialSection: 'stories' }); return; } activateStealthMode(); showNotification({ title: lang('StealthModeOn'), message: lang('StealthModeOnHint'), }); toggleStealthModal({ isOpen: false }); }); return (
{lang('StealthMode')}
{lang(isCurrentUserPremium ? 'StealthModeHint' : 'StealthModePremiumHint')}
} > {lang('HideRecentViews')} {lang('HideRecentViewsDescription')} } > {lang('HideNextViews')} {lang('HideNextViewsDescription')}
); }; export default memo(withGlobal((global): StateProps => { const tabState = selectTabState(global); return { isOpen: tabState.storyViewer?.isStealthModalOpen, stealthMode: global.stories.stealthMode, isCurrentUserPremium: selectIsCurrentUserPremium(global), }; })(StealthModeModal));