Fix pinned feeds mutation issue (#2016)

zio/stable
Eric Bailey 2023-11-28 12:50:41 -06:00 committed by GitHub
parent 0b2c85b967
commit bb9d340d42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 13 deletions

View File

@ -252,7 +252,6 @@ export function usePinnedFeedsInfos(): FeedSourceInfo[] {
FOLLOWING_FEED_STUB,
])
const {data: preferences} = usePreferencesQuery()
const pinnedFeedsKey = JSON.stringify(preferences?.feeds?.pinned)
React.useEffect(() => {
if (!preferences?.feeds?.pinned) return
@ -299,13 +298,7 @@ export function usePinnedFeedsInfos(): FeedSourceInfo[] {
}
fetchFeedInfo()
}, [
queryClient,
setTabs,
preferences?.feeds?.pinned,
// ensure we react to re-ordering
pinnedFeedsKey,
])
}, [queryClient, setTabs, preferences?.feeds?.pinned])
return tabs
}

View File

@ -57,9 +57,7 @@ function HomeScreenReady({
}
}
return feeds
// TODO careful, needed to disabled this -esb
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [preferences.feeds.pinned, pinnedFeedOrderKey])
}, [preferences.feeds.pinned])
const homeFeedParams = React.useMemo<FeedParams>(() => {
return {

View File

@ -185,7 +185,8 @@ function ListItem({
queryClient.getQueryData<UsePreferencesQueryResponse>(
preferencesQueryKey,
)?.feeds
const pinned = feeds?.pinned ?? []
// create new array, do not mutate
const pinned = feeds?.pinned ? [...feeds.pinned] : []
const index = pinned.indexOf(feedUri)
if (index === -1 || index === 0) return
@ -210,7 +211,8 @@ function ListItem({
queryClient.getQueryData<UsePreferencesQueryResponse>(
preferencesQueryKey,
)?.feeds
const pinned = feeds?.pinned ?? []
// create new array, do not mutate
const pinned = feeds?.pinned ? [...feeds.pinned] : []
const index = pinned.indexOf(feedUri)
if (index === -1 || index >= pinned.length - 1) return