This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C-1184] Fetch lineups after coming back online (#2083)
- Loading branch information
1 parent
b416893
commit 92ab4a0
Showing
8 changed files
with
117 additions
and
62 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
import { reachabilitySelectors } from '@audius/common' | ||
import { useSelector } from 'react-redux' | ||
const { getIsReachable } = reachabilitySelectors | ||
|
||
type OnBecomeReachable = () => any | ||
type OnBecomeUnreachable = () => any | ||
|
||
export const useReachability = ( | ||
onBecomeReachable: OnBecomeReachable | null, | ||
onBecomeUnreachable: OnBecomeUnreachable | null | ||
) => { | ||
const isInternetReachable = useSelector(getIsReachable) | ||
const [lastReachabilityState, setLastReachabilityState] = | ||
useState(isInternetReachable) | ||
|
||
useEffect(() => { | ||
if (isInternetReachable !== lastReachabilityState) { | ||
isInternetReachable ? onBecomeReachable?.() : onBecomeUnreachable?.() | ||
setLastReachabilityState(isInternetReachable) | ||
} | ||
}, [ | ||
isInternetReachable, | ||
lastReachabilityState, | ||
onBecomeReachable, | ||
onBecomeUnreachable | ||
]) | ||
|
||
return isInternetReachable | ||
} | ||
|
||
export const useBecomeReachable = (onBecomeReachable: OnBecomeReachable) => { | ||
return useReachability(onBecomeReachable, null) | ||
} | ||
|
||
export const useBecomeUnreachable = ( | ||
onBecomeUnreachable: OnBecomeUnreachable | ||
) => { | ||
return useReachability(null, onBecomeUnreachable) | ||
} | ||
|
||
export default useReachability |
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
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,19 @@ | ||
import { | ||
reachabilityActions, | ||
reachabilitySelectors, | ||
getContext | ||
} from '@audius/common' | ||
import { take, select, call } from 'typed-redux-saga' | ||
|
||
const { getIsReachable } = reachabilitySelectors | ||
|
||
export function* getReachability() { | ||
return yield* select(getIsReachable) | ||
} | ||
|
||
export function* awaitReachability() { | ||
const isNativeMobile = yield* getContext('isNativeMobile') | ||
const isReachable = yield* call(getReachability) | ||
if (isReachable || !isNativeMobile) return | ||
yield* take(reachabilityActions.SET_REACHABLE) | ||
} |