import { FC, useEffect } from './lib/teact/teact'; import React, { withGlobal } from './lib/teact/teactn'; import { GlobalActions, GlobalState } from './global/types'; import { INACTIVE_MARKER, PAGE_TITLE } from './config'; import { pick } from './util/iteratees'; import { updateSizes } from './util/windowSize'; import { addActiveTabChangeListener } from './util/activeTabMonitor'; import useFlag from './hooks/useFlag'; import Auth from './components/auth/Auth'; import UiLoader from './components/common/UiLoader'; import Main from './components/main/Main.async'; import AppInactive from './components/main/AppInactive'; import { hasStoredSession } from './util/sessions'; // import Test from './components/test/TestNoRedundancy'; type StateProps = Pick; type DispatchProps = Pick; const App: FC = ({ authState, disconnect }) => { const [isInactive, markInactive] = useFlag(false); useEffect(() => { updateSizes(); addActiveTabChangeListener(() => { disconnect(); document.title = `${PAGE_TITLE}${INACTIVE_MARKER}`; markInactive(); }); }, [disconnect, markInactive]); // return ; if (isInactive) { return ; } if (authState) { switch (authState) { case 'authorizationStateWaitPhoneNumber': case 'authorizationStateWaitCode': case 'authorizationStateWaitPassword': case 'authorizationStateWaitRegistration': case 'authorizationStateWaitQrCode': return ; case 'authorizationStateClosed': case 'authorizationStateClosing': case 'authorizationStateLoggingOut': case 'authorizationStateReady': return renderMain(); } } return hasStoredSession(true) ? renderMain() : ; }; function renderMain() { return (
); } export default withGlobal( (global): StateProps => pick(global, ['authState']), (setGlobal, actions): DispatchProps => pick(actions, ['disconnect']), )(App);