From 17fdd928279df5d902295c5968bed40f6ded63b8 Mon Sep 17 00:00:00 2001 From: Gigi Date: Sun, 19 Oct 2025 01:35:00 +0200 Subject: [PATCH] fix(profile): fetch all writings for profile pages by removing limit - Make limit parameter configurable in fetchBlogPostsFromAuthors - Default limit is 100 for Explore page (multiple authors) - Pass null limit for Profile pages to fetch all writings - Fixes issue where only 1 writing was shown instead of all --- src/components/Profile.tsx | 4 ++-- src/services/exploreService.ts | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/components/Profile.tsx b/src/components/Profile.tsx index 71d2d5ec..2d366740 100644 --- a/src/components/Profile.tsx +++ b/src/components/Profile.tsx @@ -73,8 +73,8 @@ const Profile: React.FC = ({ console.warn('⚠️ [Profile] Failed to fetch highlights:', err) }) - // Fetch writings in background - fetchBlogPostsFromAuthors(relayPool, [pubkey], RELAYS) + // Fetch writings in background (no limit for single user profile) + fetchBlogPostsFromAuthors(relayPool, [pubkey], RELAYS, undefined, null) .then(writings => { writings.forEach(w => eventStore.add(w.event)) console.log('✅ [Profile] Fetched', writings.length, 'writings') diff --git a/src/services/exploreService.ts b/src/services/exploreService.ts index ff486c7a..0ce762a5 100644 --- a/src/services/exploreService.ts +++ b/src/services/exploreService.ts @@ -20,13 +20,16 @@ export interface BlogPostPreview { * @param relayPool - The relay pool to query * @param pubkeys - Array of pubkeys to fetch posts from * @param relayUrls - Array of relay URLs to query + * @param onPost - Optional callback for streaming posts + * @param limit - Limit for number of events to fetch (default: 100, pass null for no limit) * @returns Array of blog post previews */ export const fetchBlogPostsFromAuthors = async ( relayPool: RelayPool, pubkeys: string[], relayUrls: string[], - onPost?: (post: BlogPostPreview) => void + onPost?: (post: BlogPostPreview) => void, + limit: number | null = 100 ): Promise => { try { if (pubkeys.length === 0) { @@ -34,15 +37,19 @@ export const fetchBlogPostsFromAuthors = async ( return [] } - console.log('📚 Fetching blog posts (kind 30023) from', pubkeys.length, 'authors') + console.log('📚 Fetching blog posts (kind 30023) from', pubkeys.length, 'authors', limit ? `(limit: ${limit})` : '(no limit)') // Deduplicate replaceable events by keeping the most recent version // Group by author + d-tag identifier const uniqueEvents = new Map() + const filter = limit !== null + ? { kinds: [KINDS.BlogPost], authors: pubkeys, limit } + : { kinds: [KINDS.BlogPost], authors: pubkeys } + await queryEvents( relayPool, - { kinds: [KINDS.BlogPost], authors: pubkeys, limit: 100 }, + filter, { relayUrls, onEvent: (event: NostrEvent) => {