diff --git a/src/components/left/ConnectionState.tsx b/src/components/left/ConnectionState.tsx index 2bdd7ecd4..2112944dc 100644 --- a/src/components/left/ConnectionState.tsx +++ b/src/components/left/ConnectionState.tsx @@ -1,9 +1,7 @@ -import React, { FC } from '../../lib/teact/teact'; -import { withGlobal } from '../../lib/teact/teactn'; +import React, { memo, FC } from '../../lib/teact/teact'; import { GlobalState } from '../../global/types'; -import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import Spinner from '../ui/Spinner'; @@ -12,12 +10,10 @@ import './ConnectionState.scss'; type StateProps = Pick; -const ConnectionState: FC = ({ connectionState }) => { +const ConnectionState: FC = () => { const lang = useLang(); - const isConnecting = connectionState === 'connectionStateConnecting'; - - return isConnecting && ( + return (
{lang('WaitingForNetwork')}
@@ -25,6 +21,4 @@ const ConnectionState: FC = ({ connectionState }) => { ); }; -export default withGlobal( - (global): StateProps => pick(global, ['connectionState']), -)(ConnectionState); +export default memo(ConnectionState); diff --git a/src/components/left/main/LeftMain.scss b/src/components/left/main/LeftMain.scss index 01b7b8b04..0d9f1fc3a 100644 --- a/src/components/left/main/LeftMain.scss +++ b/src/components/left/main/LeftMain.scss @@ -6,9 +6,20 @@ overflow: hidden; z-index: 1; + .connection-state-wrapper { + position: absolute; + top: 3.75rem; + width: 100%; + } + > .Transition { flex: 1; overflow: hidden; + transition: transform 300ms ease; + + &.pull-down { + transform: translateY(3.75rem); + } } .ChatFolders { diff --git a/src/components/left/main/LeftMain.tsx b/src/components/left/main/LeftMain.tsx index f4dd2ca23..ddb46b2f3 100644 --- a/src/components/left/main/LeftMain.tsx +++ b/src/components/left/main/LeftMain.tsx @@ -1,10 +1,14 @@ import React, { - FC, memo, useState, useRef, useCallback, useEffect, + FC, useState, useRef, useCallback, useEffect, } from '../../../lib/teact/teact'; +import { withGlobal } from '../../../lib/teact/teactn'; +import { GlobalState } from '../../../global/types'; import { LeftColumnContent } from '../../../types'; import { IS_TOUCH_ENV } from '../../../util/environment'; +import { pick } from '../../../util/iteratees'; +import useBrowserOnline from '../../../hooks/useBrowserOnline'; import Transition from '../../ui/Transition'; import LeftMainHeader from './LeftMainHeader'; @@ -13,6 +17,7 @@ import ChatFolders from './ChatFolders'; import LeftSearch from '../search/LeftSearch.async'; import ContactList from './ContactList.async'; import NewChatButton from '../NewChatButton'; +import ShowTransition from '../../ui/ShowTransition'; import './LeftMain.scss'; @@ -26,7 +31,7 @@ type OwnProps = { onReset: () => void; }; -type StateProps = {}; +type StateProps = Pick; const TRANSITION_RENDER_COUNT = Object.keys(LeftColumnContent).length / 2; const BUTTON_CLOSE_DELAY_MS = 250; @@ -40,9 +45,13 @@ const LeftMain: FC = ({ onSearchQuery, onContentChange, onReset, + connectionState, }) => { const [isNewChatButtonShown, setIsNewChatButtonShown] = useState(IS_TOUCH_ENV); + const isBrowserOnline = useBrowserOnline(); + const isConnecting = !isBrowserOnline || connectionState === 'connectionStateConnecting'; + const isMouseInside = useRef(false); const handleSelectSettings = useCallback(() => { @@ -121,13 +130,16 @@ const LeftMain: FC = ({ onSelectArchived={handleSelectArchived} onReset={onReset} /> - + + {() => } + {(isActive) => { switch (content) { @@ -159,4 +171,6 @@ const LeftMain: FC = ({ ); }; -export default memo(LeftMain); +export default withGlobal( + (global): StateProps => pick(global, ['connectionState']), +)(LeftMain); diff --git a/src/hooks/useBackgroundMode.ts b/src/hooks/useBackgroundMode.ts index 43eb8ad03..80e9f8074 100644 --- a/src/hooks/useBackgroundMode.ts +++ b/src/hooks/useBackgroundMode.ts @@ -1,9 +1,9 @@ import { useEffect } from '../lib/teact/teact'; -export default ( +export default function useBackgroundMode( onBlur: AnyToVoidFunction, onFocus: AnyToVoidFunction, -) => { +) { useEffect(() => { if (!document.hasFocus()) { onBlur(); @@ -17,4 +17,4 @@ export default ( window.removeEventListener('blur', onBlur); }; }, [onBlur, onFocus]); -}; +} diff --git a/src/hooks/useBrowserOnline.ts b/src/hooks/useBrowserOnline.ts new file mode 100644 index 000000000..afcdf8c4d --- /dev/null +++ b/src/hooks/useBrowserOnline.ts @@ -0,0 +1,21 @@ +import { useEffect, useState } from '../lib/teact/teact'; + +export default function useBrowserOnline() { + const [isOnline, setIsOnline] = useState(window.navigator.onLine); + + useEffect(() => { + function handleChange() { + setIsOnline(window.navigator.onLine); + } + + window.addEventListener('online', handleChange); + window.addEventListener('offline', handleChange); + + return () => { + window.removeEventListener('offline', handleChange); + window.removeEventListener('online', handleChange); + }; + }, []); + + return isOnline; +}