diff --git a/src/hooks/useMarkdownToHTML.ts b/src/hooks/useMarkdownToHTML.ts
index a04873ff..7e8248d2 100644
--- a/src/hooks/useMarkdownToHTML.ts
+++ b/src/hooks/useMarkdownToHTML.ts
@@ -24,7 +24,7 @@ export const useMarkdownToHTML = (
console.log('[useMarkdownToHTML] Hook called, markdown length:', markdown?.length || 0, 'hasRelayPool:', !!relayPool)
// Resolve profile labels progressively as profiles load
- const profileLabels = useProfileLabels(markdown || '')
+ const profileLabels = useProfileLabels(markdown || '', relayPool)
console.log('[useMarkdownToHTML] Profile labels size:', profileLabels.size)
// Fetch article titles
diff --git a/src/hooks/useProfileLabels.ts b/src/hooks/useProfileLabels.ts
index 37bef275..0b93d642 100644
--- a/src/hooks/useProfileLabels.ts
+++ b/src/hooks/useProfileLabels.ts
@@ -1,7 +1,9 @@
-import { useMemo } from 'react'
-import { useEventModel } from 'applesauce-react/hooks'
-import { Models, Helpers } from 'applesauce-core'
+import { useMemo, useState, useEffect } from 'react'
+import { Hooks } from 'applesauce-react'
+import { Helpers, IEventStore } from 'applesauce-core'
import { getContentPointers } from 'applesauce-factory/helpers'
+import { RelayPool } from 'applesauce-relay'
+import { fetchProfiles } from '../services/profileService'
const { getPubkeyFromDecodeResult, encodeDecodeResult } = Helpers
@@ -9,7 +11,9 @@ const { getPubkeyFromDecodeResult, encodeDecodeResult } = Helpers
* Hook to resolve profile labels from content containing npub/nprofile identifiers
* Returns a Map of encoded identifier -> display name that updates progressively as profiles load
*/
-export function useProfileLabels(content: string): Map {
+export function useProfileLabels(content: string, relayPool?: RelayPool | null): Map {
+ const eventStore = Hooks.useEventStore()
+
// Extract profile pointers (npub and nprofile) using applesauce helpers
const profileData = useMemo(() => {
console.log('[useProfileLabels] Processing content, length:', content?.length || 0)
@@ -18,19 +22,18 @@ export function useProfileLabels(content: string): Map {
console.log('[useProfileLabels] Found pointers:', pointers.length, 'types:', pointers.map(p => p.type))
const filtered = pointers.filter(p => p.type === 'npub' || p.type === 'nprofile')
console.log('[useProfileLabels] Profile pointers:', filtered.length)
- const result = filtered
- .map(pointer => {
- try {
- return {
- pubkey: getPubkeyFromDecodeResult(pointer),
- encoded: encodeDecodeResult(pointer)
- }
- } catch (err) {
- console.error('[useProfileLabels] Error processing pointer:', err, pointer)
- return null
+ const result: Array<{ pubkey: string; encoded: string }> = []
+ filtered.forEach(pointer => {
+ try {
+ const pubkey = getPubkeyFromDecodeResult(pointer)
+ const encoded = encodeDecodeResult(pointer)
+ if (pubkey && encoded) {
+ result.push({ pubkey, encoded: encoded as string })
}
- })
- .filter((p): p is { pubkey: string; encoded: string } => p !== null && !!p.pubkey)
+ } catch (err) {
+ console.error('[useProfileLabels] Error processing pointer:', err, pointer)
+ }
+ })
console.log('[useProfileLabels] Profile data after filtering:', result.length)
return result
} catch (err) {
@@ -39,27 +42,76 @@ export function useProfileLabels(content: string): Map {
}
}, [content])
- // Fetch profiles for all found pubkeys (progressive loading)
- const profiles = profileData.map(({ pubkey }) =>
- useEventModel(Models.ProfileModel, pubkey ? [pubkey] : null)
- )
+ const [profileLabels, setProfileLabels] = useState