Fix pinned feeds re-ordering (#2014)

zio/stable
Eric Bailey 2023-11-28 11:04:15 -06:00 committed by GitHub
parent bdabfa9d38
commit 0b2c85b967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -40,6 +40,12 @@ function HomeScreenReady({
const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled() const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled()
const [selectedPage, setSelectedPage] = React.useState(0) const [selectedPage, setSelectedPage] = React.useState(0)
/**
* Used to ensure that we re-compute `customFeeds` AND force a re-render of
* the pager with the new order of feeds.
*/
const pinnedFeedOrderKey = JSON.stringify(preferences.feeds.pinned)
const customFeeds = React.useMemo(() => { const customFeeds = React.useMemo(() => {
const pinned = preferences.feeds.pinned const pinned = preferences.feeds.pinned
const feeds: FeedDescriptor[] = [] const feeds: FeedDescriptor[] = []
@ -51,7 +57,9 @@ function HomeScreenReady({
} }
} }
return feeds return feeds
}, [preferences.feeds.pinned]) // TODO careful, needed to disabled this -esb
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [preferences.feeds.pinned, pinnedFeedOrderKey])
const homeFeedParams = React.useMemo<FeedParams>(() => { const homeFeedParams = React.useMemo<FeedParams>(() => {
return { return {
@ -83,7 +91,6 @@ function HomeScreenReady({
emitSoftReset() emitSoftReset()
}, []) }, [])
// TODO(pwi) may need this in public view
const onPageScrollStateChanged = React.useCallback( const onPageScrollStateChanged = React.useCallback(
(state: 'idle' | 'dragging' | 'settling') => { (state: 'idle' | 'dragging' | 'settling') => {
if (state === 'dragging') { if (state === 'dragging') {
@ -118,6 +125,7 @@ function HomeScreenReady({
return hasSession ? ( return hasSession ? (
<Pager <Pager
key={pinnedFeedOrderKey}
testID="homeScreen" testID="homeScreen"
onPageSelected={onPageSelected} onPageSelected={onPageSelected}
onPageScrollStateChanged={onPageScrollStateChanged} onPageScrollStateChanged={onPageScrollStateChanged}