diff --git a/lib/hooks/disconnected-bar.js b/lib/hooks/disconnected-bar.js --- a/lib/hooks/disconnected-bar.js +++ b/lib/hooks/disconnected-bar.js @@ -66,52 +66,4 @@ }, [connectionStatus, someRequestIsLate, setDisconnected]); } -function useShouldShowDisconnectedBar(): { - +disconnected: boolean, - +shouldShowDisconnectedBar: boolean, -} { - const connection = useSelector(connectionSelector(ashoatKeyserverID)); - invariant(connection, 'keyserver missing from keyserverStore'); - const disconnected = connection.showDisconnectedBar; - const socketConnected = connection.status === 'connected'; - - const shouldShowDisconnectedBar = disconnected || !socketConnected; - return { disconnected, shouldShowDisconnectedBar }; -} - -type DisconnectedBarCause = 'connecting' | 'disconnected'; - -function useDisconnectedBar( - changeShowing: boolean => void, -): DisconnectedBarCause { - const { disconnected, shouldShowDisconnectedBar } = - useShouldShowDisconnectedBar(); - - const prevShowDisconnectedBar = React.useRef(); - React.useEffect(() => { - const wasShowing = prevShowDisconnectedBar.current; - if (shouldShowDisconnectedBar && wasShowing === false) { - changeShowing(true); - } else if (!shouldShowDisconnectedBar && wasShowing) { - changeShowing(false); - } - prevShowDisconnectedBar.current = shouldShowDisconnectedBar; - }, [shouldShowDisconnectedBar, changeShowing]); - - const [barCause, setBarCause] = - React.useState('connecting'); - React.useEffect(() => { - if (shouldShowDisconnectedBar && disconnected) { - setBarCause('disconnected'); - } else if (shouldShowDisconnectedBar) { - setBarCause('connecting'); - } - }, [shouldShowDisconnectedBar, disconnected]); - return barCause; -} - -export { - useDisconnectedBarVisibilityHandler, - useShouldShowDisconnectedBar, - useDisconnectedBar, -}; +export { useDisconnectedBarVisibilityHandler };