feat(ott-1761): check internet connection (#551)
Co-authored-by: boyvanov <boyvanov.sergey@gmail.com>keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
parent
77daf294b8
commit
94977f3df1
@ -0,0 +1,32 @@ |
|||||||
|
import { useNoNetworkPopupStore } from 'features/NoNetworkPopup' |
||||||
|
import { Background } from 'features/Background' |
||||||
|
|
||||||
|
import { |
||||||
|
ArrowLoader, |
||||||
|
Container, |
||||||
|
Logo, |
||||||
|
SubTitle, |
||||||
|
Title, |
||||||
|
Wrapper, |
||||||
|
} from './styled' |
||||||
|
|
||||||
|
export * from './store' |
||||||
|
|
||||||
|
export const NoNetworkPopup = () => { |
||||||
|
const { isOnline } = useNoNetworkPopupStore() |
||||||
|
|
||||||
|
if (isOnline) return null |
||||||
|
|
||||||
|
return ( |
||||||
|
<Wrapper> |
||||||
|
<Background> |
||||||
|
<Container> |
||||||
|
<Logo /> |
||||||
|
<ArrowLoader /> |
||||||
|
<Title t='lost_connection' /> |
||||||
|
<SubTitle t='check_connection' /> |
||||||
|
</Container> |
||||||
|
</Background> |
||||||
|
</Wrapper> |
||||||
|
) |
||||||
|
} |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
import { useState } from 'react' |
||||||
|
|
||||||
|
import { useEventListener } from 'hooks' |
||||||
|
|
||||||
|
export const useNetwork = () => { |
||||||
|
const [isOnline, setNetwork] = useState(window.navigator.onLine) |
||||||
|
|
||||||
|
const updateNetwork = () => { |
||||||
|
setNetwork(window.navigator.onLine) |
||||||
|
} |
||||||
|
|
||||||
|
useEventListener({ |
||||||
|
callback: updateNetwork, |
||||||
|
event: 'offline', |
||||||
|
}) |
||||||
|
|
||||||
|
useEventListener({ |
||||||
|
callback: updateNetwork, |
||||||
|
event: 'online', |
||||||
|
}) |
||||||
|
|
||||||
|
return { isOnline } |
||||||
|
} |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
import type { ReactNode } from 'react' |
||||||
|
import { createContext, useContext } from 'react' |
||||||
|
|
||||||
|
import { useNetwork } from './hooks' |
||||||
|
|
||||||
|
type Context = ReturnType<typeof useNetwork> |
||||||
|
type Props = { children: ReactNode } |
||||||
|
|
||||||
|
const NoNetworkPopupContext = createContext({} as Context) |
||||||
|
|
||||||
|
export const NoNetworkPopupStore = ({ children }: Props) => { |
||||||
|
const value = useNetwork() |
||||||
|
return ( |
||||||
|
<NoNetworkPopupContext.Provider value={value}> |
||||||
|
{children} |
||||||
|
</NoNetworkPopupContext.Provider> |
||||||
|
) |
||||||
|
} |
||||||
|
|
||||||
|
export const useNoNetworkPopupStore = () => useContext(NoNetworkPopupContext) |
||||||
@ -0,0 +1,81 @@ |
|||||||
|
import styled from 'styled-components/macro' |
||||||
|
|
||||||
|
import { Arrows } from 'features/ArrowLoader/styled' |
||||||
|
import { T9n } from 'features/T9n' |
||||||
|
|
||||||
|
export const Wrapper = styled.div` |
||||||
|
position: absolute; |
||||||
|
left: 0; |
||||||
|
top: 0; |
||||||
|
width: 100vw; |
||||||
|
height: 100vh; |
||||||
|
z-index: 1000; |
||||||
|
` |
||||||
|
|
||||||
|
export const Container = styled.div` |
||||||
|
display: flex; |
||||||
|
flex-direction: column; |
||||||
|
align-items: center; |
||||||
|
justify-content: center; |
||||||
|
color: #FFFFFF; |
||||||
|
` |
||||||
|
|
||||||
|
export const Logo = styled.div` |
||||||
|
width: 234px; |
||||||
|
height: 54px; |
||||||
|
background-size: contain; |
||||||
|
background-repeat: no-repeat; |
||||||
|
background-image: url(/images/logo.svg); |
||||||
|
margin-bottom: 87px; |
||||||
|
|
||||||
|
@media (max-width: 850px) { |
||||||
|
width: 144px; |
||||||
|
height: 33px; |
||||||
|
margin-bottom: 54px; |
||||||
|
} |
||||||
|
` |
||||||
|
|
||||||
|
export const FakeArrowLoader = styled.div` |
||||||
|
width: 0; |
||||||
|
height: 0; |
||||||
|
visibility: hidden; |
||||||
|
background-image: url(/images/arrowGroup.svg); |
||||||
|
` |
||||||
|
|
||||||
|
export const ArrowLoader = styled(Arrows)` |
||||||
|
width: 94px; |
||||||
|
height: 87px; |
||||||
|
|
||||||
|
@media (max-width: 850px) { |
||||||
|
width: 58px; |
||||||
|
height: 54px; |
||||||
|
} |
||||||
|
` |
||||||
|
|
||||||
|
export const Title = styled(T9n)` |
||||||
|
font-weight: bold; |
||||||
|
font-size: 24px; |
||||||
|
line-height: 24px; |
||||||
|
margin-top: 87px; |
||||||
|
|
||||||
|
@media (max-width: 850px) { |
||||||
|
font-size: 14px; |
||||||
|
line-height: 15px; |
||||||
|
margin-top: 54px; |
||||||
|
} |
||||||
|
` |
||||||
|
|
||||||
|
export const SubTitle = styled(T9n)` |
||||||
|
font-weight: 500; |
||||||
|
font-size: 16px; |
||||||
|
line-height: 20px; |
||||||
|
letter-spacing: 0.03em; |
||||||
|
opacity: 0.8; |
||||||
|
margin-top: 12px; |
||||||
|
|
||||||
|
@media (max-width: 850px) { |
||||||
|
font-size: 10px; |
||||||
|
line-height: 12px; |
||||||
|
margin-top: 7px; |
||||||
|
} |
||||||
|
` |
||||||
Loading…
Reference in new issue