mirror of
https://github.com/dergigi/boris.git
synced 2026-01-08 17:34:52 +01:00
feat: fetch and cache author profiles in explore page
- Create profileService to fetch and cache kind:0 metadata - Fetch profiles for all blog post authors on explore page - Store profiles in event store for immediate access - Rebroadcast profiles to local/all relays per user settings - Fixes 'Unknown' author names by ensuring profiles are cached - Uses mapEventsToStore to automatically populate event store
This commit is contained in:
@@ -305,7 +305,7 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
|
||||
onCreateHighlight={handleCreateHighlight}
|
||||
hasActiveAccount={!!(activeAccount && relayPool)}
|
||||
explore={showExplore ? (
|
||||
relayPool ? <Explore relayPool={relayPool} activeTab={exploreTab} /> : null
|
||||
relayPool ? <Explore relayPool={relayPool} eventStore={eventStore} settings={settings} activeTab={exploreTab} /> : null
|
||||
) : undefined}
|
||||
me={showMe ? (
|
||||
relayPool ? <Me relayPool={relayPool} activeTab={meTab} /> : null
|
||||
|
||||
@@ -3,12 +3,15 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import { faSpinner, faExclamationCircle, faNewspaper, faPenToSquare, faHighlighter } from '@fortawesome/free-solid-svg-icons'
|
||||
import { Hooks } from 'applesauce-react'
|
||||
import { RelayPool } from 'applesauce-relay'
|
||||
import { IEventStore } from 'applesauce-core'
|
||||
import { nip19 } from 'nostr-tools'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { fetchContacts } from '../services/contactService'
|
||||
import { fetchBlogPostsFromAuthors, BlogPostPreview } from '../services/exploreService'
|
||||
import { fetchHighlightsFromAuthors } from '../services/highlightService'
|
||||
import { fetchProfiles } from '../services/profileService'
|
||||
import { Highlight } from '../types/highlights'
|
||||
import { UserSettings } from '../services/settingsService'
|
||||
import BlogPostCard from './BlogPostCard'
|
||||
import { HighlightItem } from './HighlightItem'
|
||||
import { getCachedPosts, upsertCachedPost, setCachedPosts, getCachedHighlights, upsertCachedHighlight, setCachedHighlights } from '../services/exploreCache'
|
||||
@@ -18,12 +21,14 @@ import { classifyHighlights } from '../utils/highlightClassification'
|
||||
|
||||
interface ExploreProps {
|
||||
relayPool: RelayPool
|
||||
eventStore: IEventStore
|
||||
settings?: UserSettings
|
||||
activeTab?: TabType
|
||||
}
|
||||
|
||||
type TabType = 'writings' | 'highlights'
|
||||
|
||||
const Explore: React.FC<ExploreProps> = ({ relayPool, activeTab: propActiveTab }) => {
|
||||
const Explore: React.FC<ExploreProps> = ({ relayPool, eventStore, settings, activeTab: propActiveTab }) => {
|
||||
const activeAccount = Hooks.useActiveAccount()
|
||||
const navigate = useNavigate()
|
||||
const [activeTab, setActiveTab] = useState<TabType>(propActiveTab || 'highlights')
|
||||
@@ -152,6 +157,14 @@ const Explore: React.FC<ExploreProps> = ({ relayPool, activeTab: propActiveTab }
|
||||
fetchHighlightsFromAuthors(relayPool, contactsArray)
|
||||
])
|
||||
|
||||
// Fetch profiles for all blog post authors to cache them
|
||||
if (posts.length > 0) {
|
||||
const authorPubkeys = Array.from(new Set(posts.map(p => p.author)))
|
||||
fetchProfiles(relayPool, eventStore, authorPubkeys, settings).catch(err => {
|
||||
console.error('Failed to fetch author profiles:', err)
|
||||
})
|
||||
}
|
||||
|
||||
if (posts.length === 0 && userHighlights.length === 0) {
|
||||
setError('No content found from your friends yet')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user