mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 00:51:20 +00:00
refactor: use reduce for stale group filtering
Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -333,12 +333,13 @@ export class FeedEngine<TItems extends FeedItem = FeedItem> {
|
||||
|
||||
// Remove stale item IDs from groups and drop empty groups
|
||||
const itemIds = new Set(currentItems.map((item) => item.id))
|
||||
const validGroups = allGroupedItems
|
||||
.map((group) => ({
|
||||
...group,
|
||||
itemIds: group.itemIds.filter((id) => itemIds.has(id)),
|
||||
}))
|
||||
.filter((group) => group.itemIds.length > 0)
|
||||
const validGroups = allGroupedItems.reduce<ItemGroup[]>((acc, group) => {
|
||||
const ids = group.itemIds.filter((id) => itemIds.has(id))
|
||||
if (ids.length > 0) {
|
||||
acc.push({ ...group, itemIds: ids })
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
|
||||
return { items: currentItems, groupedItems: validGroups, errors: allErrors }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user