diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-12-08 16:30:19 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-08 16:30:19 -0800 |
commit | 102094b10aeeed996cae5a522a497ee4848d27e6 (patch) | |
tree | 6a2e436f0fdcd7605c416bf47f3a6516dd46eea9 | |
parent | 9c0c18d5d08db6433fbee8412c2c4da400a31afa (diff) | |
download | voidsky-102094b10aeeed996cae5a522a497ee4848d27e6.tar.zst |
Poll for new posts on app foreground (#2152)
-rw-r--r-- | src/view/com/posts/Feed.tsx | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/view/com/posts/Feed.tsx b/src/view/com/posts/Feed.tsx index fe619ab30..c4f859e04 100644 --- a/src/view/com/posts/Feed.tsx +++ b/src/view/com/posts/Feed.tsx @@ -1,6 +1,7 @@ import React, {memo, MutableRefObject} from 'react' import { ActivityIndicator, + AppState, Dimensions, RefreshControl, StyleProp, @@ -142,12 +143,23 @@ let Feed = ({ } }, [enabled]) React.useEffect(() => { - if (!pollInterval) { - return + let cleanup1: () => void | undefined, cleanup2: () => void | undefined + const subscription = AppState.addEventListener('change', nextAppState => { + // check for new on app foreground + if (nextAppState === 'active') { + checkForNewRef.current?.() + } + }) + cleanup1 = () => subscription.remove() + if (pollInterval) { + // check for new on interval + const i = setInterval(() => checkForNewRef.current?.(), pollInterval) + cleanup2 = () => clearInterval(i) + } + return () => { + cleanup1?.() + cleanup2?.() } - // check for new on interval - const i = setInterval(() => checkForNewRef.current?.(), pollInterval) - return () => clearInterval(i) }, [pollInterval]) const feedItems = React.useMemo(() => { |