6dd29c571f
Consolidate duplicated infinite-scroll boilerplate (auto-fetch page 2, IntersectionObserver, scroll trigger) into a shared useInfiniteScroll hook, and extract the flatten+dedup pattern into deduplicateEvents. Also migrate BadgesPage and ThemesPage to use useFeedTab for consistent tab persistence across all feed pages.
18 lines
526 B
TypeScript
18 lines
526 B
TypeScript
import type { NostrEvent } from '@nostrify/nostrify';
|
|
|
|
/**
|
|
* Flatten paginated Nostr event arrays and deduplicate by event ID.
|
|
*
|
|
* Accepts the `pages` property from a TanStack `useInfiniteQuery` result
|
|
* where each page is a `NostrEvent[]`.
|
|
*/
|
|
export function deduplicateEvents(pages: NostrEvent[][] | undefined): NostrEvent[] {
|
|
if (!pages) return [];
|
|
const seen = new Set<string>();
|
|
return pages.flat().filter((event) => {
|
|
if (seen.has(event.id)) return false;
|
|
seen.add(event.id);
|
|
return true;
|
|
});
|
|
}
|