-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 네트워크 상태가 오프라인일 경우 토스트로 안내하는 기능 (#568)
* feat: 네트워크가 오프라인 상태가 되었을 때 토스트로 오프라인 상태임을 알리는 컴포넌트 구현 * feat: 외부에서 토스트를 닫기 위한 함수를 ToastProvider에서 return에 추가 * rename: NetworkCatcher -> NetworkStateCatcher로 직관적인 이름으로 변경 * feat: 네트워크 상태를 감지하기 위한 컴포넌트를 App에서 호출
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {useEffect} from 'react'; | ||
|
||
import {useToast} from '@hooks/useToast/useToast'; | ||
|
||
const NetworkStateCatcher = () => { | ||
const {showToast, closeToast} = useToast(); | ||
|
||
const handleNetworkOnline = () => { | ||
closeToast(); | ||
}; | ||
|
||
const handleNetworkOffline = () => { | ||
// TODO: (@weadie) 토스트 높이는 z-index 이슈가 해결되면 반영할 예정입니다. | ||
showToast({ | ||
message: '네트워크 연결 상태를 확인해주세요.', | ||
isAlwaysOn: true, | ||
type: 'error', | ||
position: 'bottom', | ||
bottom: '6rem', | ||
}); | ||
}; | ||
|
||
const addNetworkStateEventListener = () => { | ||
window.addEventListener('online', handleNetworkOnline); | ||
window.addEventListener('offline', handleNetworkOffline); | ||
}; | ||
|
||
const removeNetworkStateEventListener = () => { | ||
window.removeEventListener('online', handleNetworkOnline); | ||
window.removeEventListener('offline', handleNetworkOffline); | ||
}; | ||
|
||
useEffect(() => { | ||
addNetworkStateEventListener(); | ||
|
||
return removeNetworkStateEventListener; | ||
}, []); | ||
|
||
return null; | ||
}; | ||
|
||
export default NetworkStateCatcher; |