Skip to content

Commit d6bad18

Browse files
chrisbobbegnprice
authored andcommitted
offline notice [nfc]: Pull out new Hook useShouldShowUncertaintyNotice
1 parent 5115a26 commit d6bad18

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/common/OfflineNotice.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,10 @@ const styles = createStyleSheet({
2828

2929
type Props = $ReadOnly<{||}>;
3030

31-
/**
32-
* Shows a notice if the app is working in offline mode.
33-
*
34-
* Shows a different notice if we've taken longer than we expect to
35-
* determine Internet reachability. IOW, if the user sees this, there's a
36-
* bug.
37-
*
38-
* Shows nothing if the Internet is reachable.
39-
*/
40-
export default function OfflineNotice(props: Props): Node {
31+
function useShouldShowUncertaintyNotice() {
4132
const isOnline = useGlobalSelector(state => getGlobalSession(state).isOnline);
4233

43-
const shouldShowUncertaintyNotice = useHasStayedTrueForMs(
34+
const result = useHasStayedTrueForMs(
4435
// See note in `SessionState` for what this means.
4536
isOnline === null,
4637

@@ -59,7 +50,7 @@ export default function OfflineNotice(props: Props): Node {
5950
);
6051

6152
useEffect(() => {
62-
if (shouldShowUncertaintyNotice) {
53+
if (result) {
6354
NetInfo.fetch().then(state => {
6455
logging.warn(
6556
'Failed to determine Internet reachability in a reasonable time',
@@ -71,7 +62,23 @@ export default function OfflineNotice(props: Props): Node {
7162
);
7263
});
7364
}
74-
}, [shouldShowUncertaintyNotice]);
65+
}, [result]);
66+
67+
return result;
68+
}
69+
70+
/**
71+
* Shows a notice if the app is working in offline mode.
72+
*
73+
* Shows a different notice if we've taken longer than we expect to
74+
* determine Internet reachability. IOW, if the user sees this, there's a
75+
* bug.
76+
*
77+
* Shows nothing if the Internet is reachable.
78+
*/
79+
export default function OfflineNotice(props: Props): Node {
80+
const isOnline = useGlobalSelector(state => getGlobalSession(state).isOnline);
81+
const shouldShowUncertaintyNotice = useShouldShowUncertaintyNotice();
7582

7683
if (shouldShowUncertaintyNotice) {
7784
return (

0 commit comments

Comments
 (0)