diff options
author | dan <dan.abramov@gmail.com> | 2024-06-24 21:34:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-24 21:34:42 +0100 |
commit | f64245c1fb0b590edf1959ea0f30ec3bee507ad1 (patch) | |
tree | 6fe1846d14a18e59e3335f73e5b1753214b41b19 | |
parent | 873d91d4664403577fff0438bfc81304f1fafe5b (diff) | |
download | voidsky-f64245c1fb0b590edf1959ea0f30ec3bee507ad1.tar.zst |
Fix crash in Feeds and Starter Packs (#4616)
* Remove useless check * Fix the bug by only adding resolved feeds/lists * Clarify the purpose of the count field
-rw-r--r-- | src/screens/StarterPack/Wizard/StepFeeds.tsx | 10 | ||||
-rw-r--r-- | src/state/queries/feed.ts | 44 |
2 files changed, 31 insertions, 23 deletions
diff --git a/src/screens/StarterPack/Wizard/StepFeeds.tsx b/src/screens/StarterPack/Wizard/StepFeeds.tsx index fbd8e7389..46c4d4404 100644 --- a/src/screens/StarterPack/Wizard/StepFeeds.tsx +++ b/src/screens/StarterPack/Wizard/StepFeeds.tsx @@ -41,13 +41,9 @@ export function StepFeeds({moderationOpts}: {moderationOpts: ModerationOpts}) { limit: 30, }) const popularFeeds = popularFeedsPages?.pages.flatMap(p => p.feeds) ?? [] - - const suggestedFeeds = - savedFeeds.length === 0 - ? popularFeeds - : savedFeeds.concat( - popularFeeds.filter(f => !savedFeeds.some(sf => sf.uri === f.uri)), - ) + const suggestedFeeds = savedFeeds.concat( + popularFeeds.filter(f => !savedFeeds.some(sf => sf.uri === f.uri)), + ) const {data: searchedFeeds, isLoading: isLoadingSearch} = useSearchPopularFeedsQuery({q: throttledQuery}) diff --git a/src/state/queries/feed.ts b/src/state/queries/feed.ts index dea6f5d77..36555c181 100644 --- a/src/state/queries/feed.ts +++ b/src/state/queries/feed.ts @@ -509,6 +509,7 @@ export function useSavedFeeds() { placeholderData: previousData => { return ( previousData || { + // The likely count before we try to resolve them. count: savedItems.length, feeds: [], } @@ -556,28 +557,39 @@ export function useSavedFeeds() { precacheList(queryClient, list) }) - const res: SavedFeedItem[] = savedItems.map(s => { - if (s.type === 'timeline') { - return { + const result: SavedFeedItem[] = [] + for (let savedItem of savedItems) { + if (savedItem.type === 'timeline') { + result.push({ type: 'timeline', - config: s, + config: savedItem, view: undefined, + }) + } else if (savedItem.type === 'feed') { + const resolvedFeed = resolvedFeeds.get(savedItem.value) + if (resolvedFeed) { + result.push({ + type: 'feed', + config: savedItem, + view: resolvedFeed, + }) + } + } else if (savedItem.type === 'list') { + const resolvedList = resolvedLists.get(savedItem.value) + if (resolvedList) { + result.push({ + type: 'list', + config: savedItem, + view: resolvedList, + }) } } - - return { - type: s.type, - config: s, - view: - s.type === 'feed' - ? resolvedFeeds.get(s.value) - : resolvedLists.get(s.value), - } - }) as SavedFeedItem[] + } return { - count: savedItems.length, - feeds: res, + // By this point we know the real count. + count: result.length, + feeds: result, } }, }) |