Skip to content

Commit

Permalink
Fix pinned feeds mutation issue (#2016)
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey authored Nov 28, 2023
1 parent 0b2c85b commit bb9d340
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
9 changes: 1 addition & 8 deletions src/state/queries/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
4 changes: 1 addition & 3 deletions src/view/screens/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions src/view/screens/SavedFeeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit bb9d340

Please sign in to comment.