mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Only poll feed when feed page is focused (#2064)

* Do no poll when screen is not focused

* Avoid polling unless focused

* Handle homepage in background

* Fix the intl:check to ignore comments in diffs

---------

Co-authored-by: Paul Frazee <pfrazee@gmail.com>

authored by

Eric Bailey
Paul Frazee
and committed by
GitHub
9dec9d72 f80bd30e

+26 -13
+1 -1
package.json
··· 30 30 "perf:test:results": "NODE_ENV=test flashlight report .perf/results.json", 31 31 "perf:measure": "NODE_ENV=test flashlight measure", 32 32 "intl:build": "yarn intl:check && yarn intl:compile", 33 - "intl:check": "yarn intl:extract && git diff-index --quiet HEAD || (echo '\n⚠️ i18n detected un-extracted translations\n' && exit 1)", 33 + "intl:check": "yarn intl:extract && git diff-index -G'(^[^\\*# /])|(^#\\w)|(^\\s+[^\\*#/])' HEAD || (echo '\n⚠️ i18n detected un-extracted translations\n' && exit 1)", 34 34 "intl:extract": "lingui extract", 35 35 "intl:compile": "lingui compile" 36 36 },
+1 -1
src/view/com/feeds/FeedPage.tsx
··· 158 158 <View testID={testID} style={s.h100pct}> 159 159 <Feed 160 160 testID={testID ? `${testID}-feed` : undefined} 161 + enabled={isPageFocused} 161 162 feed={feed} 162 163 feedParams={feedParams} 163 - enabled={isPageFocused} 164 164 pollInterval={POLL_FREQ} 165 165 scrollElRef={scrollElRef} 166 166 onScroll={onMainScroll}
+2 -2
src/view/com/posts/Feed.tsx
··· 89 89 const isEmpty = !isFetching && !data?.pages[0]?.slices.length 90 90 91 91 const checkForNew = React.useCallback(async () => { 92 - if (!data?.pages[0] || isFetching || !onHasNew) { 92 + if (!data?.pages[0] || isFetching || !onHasNew || !enabled) { 93 93 return 94 94 } 95 95 try { ··· 99 99 } catch (e) { 100 100 logger.error('Poll latest failed', {feed, error: String(e)}) 101 101 } 102 - }, [feed, data, isFetching, onHasNew]) 102 + }, [feed, data, isFetching, onHasNew, enabled]) 103 103 104 104 React.useEffect(() => { 105 105 // we store the interval handler in a ref to avoid needless
+5 -4
src/view/screens/Home.tsx
··· 1 1 import React from 'react' 2 2 import {View, ActivityIndicator, StyleSheet} from 'react-native' 3 - import {useFocusEffect} from '@react-navigation/native' 3 + import {useFocusEffect, useIsFocused} from '@react-navigation/native' 4 4 import {NativeStackScreenProps, HomeTabNavigatorParams} from 'lib/routes/types' 5 5 import {FeedDescriptor, FeedParams} from '#/state/queries/post-feed' 6 6 import {FollowingEmptyState} from 'view/com/posts/FollowingEmptyState' ··· 39 39 const setMinimalShellMode = useSetMinimalShellMode() 40 40 const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled() 41 41 const [selectedPage, setSelectedPage] = React.useState(0) 42 + const isPageFocused = useIsFocused() 42 43 43 44 /** 44 45 * Used to ensure that we re-compute `customFeeds` AND force a re-render of ··· 132 133 <FeedPage 133 134 key="1" 134 135 testID="followingFeedPage" 135 - isPageFocused={selectedPage === 0} 136 + isPageFocused={selectedPage === 0 && isPageFocused} 136 137 feed={homeFeedParams.mergeFeedEnabled ? 'home' : 'following'} 137 138 feedParams={homeFeedParams} 138 139 renderEmptyState={renderFollowingEmptyState} ··· 143 144 <FeedPage 144 145 key={f} 145 146 testID="customFeedPage" 146 - isPageFocused={selectedPage === 1 + index} 147 + isPageFocused={selectedPage === 1 + index && isPageFocused} 147 148 feed={f} 148 149 renderEmptyState={renderCustomFeedEmptyState} 149 150 /> ··· 159 160 tabBarPosition="top"> 160 161 <FeedPage 161 162 testID="customFeedPage" 162 - isPageFocused 163 + isPageFocused={isPageFocused} 163 164 feed={`feedgen|at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot`} 164 165 renderEmptyState={renderCustomFeedEmptyState} 165 166 />
+1 -1
src/view/screens/Profile.tsx
··· 420 420 <View> 421 421 <Feed 422 422 testID="postsFeed" 423 + enabled={isFocused} 423 424 feed={feed} 424 425 pollInterval={30e3} 425 426 scrollElRef={scrollElRef} ··· 428 429 scrollEventThrottle={1} 429 430 renderEmptyState={renderPostsEmpty} 430 431 headerOffset={headerHeight} 431 - enabled={isFocused} 432 432 /> 433 433 {(isScrolledDown || hasNew) && ( 434 434 <LoadLatestBtn
+5 -2
src/view/screens/ProfileFeed.tsx
··· 402 402 isHeaderReady={true} 403 403 renderHeader={renderHeader} 404 404 onCurrentPageSelected={onCurrentPageSelected}> 405 - {({onScroll, headerHeight, isScrolledDown, scrollElRef}) => 405 + {({onScroll, headerHeight, isScrolledDown, scrollElRef, isFocused}) => 406 406 isPublic ? ( 407 407 <FeedSection 408 408 ref={feedSectionRef} ··· 413 413 scrollElRef={ 414 414 scrollElRef as React.MutableRefObject<FlatList<any> | null> 415 415 } 416 + isFocused={isFocused} 416 417 /> 417 418 ) : ( 418 419 <CenteredView sideBorders style={[{paddingTop: headerHeight}]}> ··· 492 493 headerHeight: number 493 494 isScrolledDown: boolean 494 495 scrollElRef: React.MutableRefObject<FlatList<any> | null> 496 + isFocused: boolean 495 497 } 496 498 const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>( 497 499 function FeedSectionImpl( 498 - {feed, onScroll, headerHeight, isScrolledDown, scrollElRef}, 500 + {feed, onScroll, headerHeight, isScrolledDown, scrollElRef, isFocused}, 499 501 ref, 500 502 ) { 501 503 const [hasNew, setHasNew] = React.useState(false) ··· 518 520 return ( 519 521 <View> 520 522 <Feed 523 + enabled={isFocused} 521 524 feed={feed} 522 525 pollInterval={30e3} 523 526 scrollElRef={scrollElRef}
+11 -2
src/view/screens/ProfileList.tsx
··· 159 159 isHeaderReady={true} 160 160 renderHeader={renderHeader} 161 161 onCurrentPageSelected={onCurrentPageSelected}> 162 - {({onScroll, headerHeight, isScrolledDown, scrollElRef}) => ( 162 + {({ 163 + onScroll, 164 + headerHeight, 165 + isScrolledDown, 166 + scrollElRef, 167 + isFocused, 168 + }) => ( 163 169 <FeedSection 164 170 ref={feedSectionRef} 165 171 feed={`list|${uri}`} ··· 169 175 onScroll={onScroll} 170 176 headerHeight={headerHeight} 171 177 isScrolledDown={isScrolledDown} 178 + isFocused={isFocused} 172 179 /> 173 180 )} 174 181 {({onScroll, headerHeight, isScrolledDown, scrollElRef}) => ( ··· 519 526 headerHeight: number 520 527 isScrolledDown: boolean 521 528 scrollElRef: React.MutableRefObject<FlatList<any> | null> 529 + isFocused: boolean 522 530 } 523 531 const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>( 524 532 function FeedSectionImpl( 525 - {feed, scrollElRef, onScroll, headerHeight, isScrolledDown}, 533 + {feed, scrollElRef, onScroll, headerHeight, isScrolledDown, isFocused}, 526 534 ref, 527 535 ) { 528 536 const queryClient = useQueryClient() ··· 545 553 <View> 546 554 <Feed 547 555 testID="listFeed" 556 + enabled={isFocused} 548 557 feed={feed} 549 558 pollInterval={30e3} 550 559 scrollElRef={scrollElRef}