Skip to content

Commit f9c7ca8

Browse files
committed
chore: checkConnectivity code cleanup
1 parent 56e11cb commit f9c7ca8

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/components/common/hooks/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ export const FILE_READING_FAILED_STATUS = {
3333
}
3434

3535
export const ONLINE_BANNER_TIMEOUT = 3000
36-
export const INTERNET_CONNECTIVITY_INTERVAL = 10000
36+
export const INTERNET_CONNECTIVITY_INTERVAL = 20000

src/components/common/hooks/useOnline/useOnline.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ export const useOnline = ({ onOnline = noop }: { onOnline?: () => void }) => {
1818
abortControllerRef.current.abort()
1919
}
2020

21+
const onConnectivitySuccess = () => {
22+
setOnline((prev) => {
23+
if (!prev) onOnline()
24+
return true
25+
})
26+
}
27+
2128
const checkConnectivity = async () => {
2229
if (isAirgapped) return
2330

@@ -27,20 +34,13 @@ export const useOnline = ({ onOnline = noop }: { onOnline?: () => void }) => {
2734

2835
try {
2936
await getInternetConnectivity(abortControllerRef.current)
30-
setOnline((prev) => {
31-
if (!prev) {
32-
onOnline()
33-
}
34-
return true
35-
})
37+
onConnectivitySuccess()
38+
3639
timeoutRef.current = setTimeout(checkConnectivity, INTERNET_CONNECTIVITY_INTERVAL)
3740
} catch (error) {
3841
try {
3942
await getFallbackInternetConnectivity(abortControllerRef.current)
40-
setOnline((prev) => {
41-
if (!prev) onOnline()
42-
return true
43-
})
43+
onConnectivitySuccess()
4444
} catch {
4545
setOnline(false)
4646
} finally {

0 commit comments

Comments
 (0)