From f754ce3cfe4dda6d9263385b9ea4d0a510ae76d7 Mon Sep 17 00:00:00 2001 From: Gigi Date: Tue, 14 Oct 2025 11:04:24 +0200 Subject: [PATCH] fix: extract author pubkey directly from p tag in highlights - Pass full highlight object to HighlightCitation component - Extract author pubkey from p tag as fallback if highlight.author not set - Add debug logging to track author resolution - Fix TypeScript type errors with proper guards - Ensure author profile resolution works correctly --- src/components/HighlightCitation.tsx | 55 ++++++++++++++++------------ src/components/HighlightItem.tsx | 4 +- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/components/HighlightCitation.tsx b/src/components/HighlightCitation.tsx index 14e025c8..698889e5 100644 --- a/src/components/HighlightCitation.tsx +++ b/src/components/HighlightCitation.tsx @@ -1,45 +1,54 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect, useMemo } from 'react' import { RelayPool } from 'applesauce-relay' import { useEventModel } from 'applesauce-react/hooks' import { Models } from 'applesauce-core' import { nip19 } from 'nostr-tools' import { fetchArticleTitle } from '../services/articleTitleResolver' +import { Highlight } from '../types/highlights' interface HighlightCitationProps { - eventReference?: string - urlReference?: string - authorPubkey?: string + highlight: Highlight relayPool?: RelayPool | null } export const HighlightCitation: React.FC = ({ - eventReference, - urlReference, - authorPubkey, + highlight, relayPool }) => { const [articleTitle, setArticleTitle] = useState() + + // Extract author pubkey from p tag directly + const authorPubkey = useMemo(() => { + // First try the extracted author from highlight.author + if (highlight.author) { + return highlight.author + } + + // Fallback: extract directly from p tag + const pTag = highlight.tags.find(t => t[0] === 'p') + if (pTag && pTag[1]) { + console.log('📝 Found author from p tag:', pTag[1]) + return pTag[1] + } + + return undefined + }, [highlight.author, highlight.tags]) + const authorProfile = useEventModel(Models.ProfileModel, authorPubkey ? [authorPubkey] : null) - // Debug: log the authorPubkey and profile useEffect(() => { - if (authorPubkey) { - console.log('📝 HighlightCitation - authorPubkey:', authorPubkey) - console.log('📝 HighlightCitation - authorProfile:', authorProfile) - } - }, [authorPubkey, authorProfile]) - - useEffect(() => { - if (!eventReference || !relayPool) { + if (!highlight.eventReference || !relayPool) { return } const loadTitle = async () => { try { + if (!highlight.eventReference) return + // Convert eventReference to naddr if needed let naddr: string - if (eventReference.includes(':')) { - const parts = eventReference.split(':') + if (highlight.eventReference.includes(':')) { + const parts = highlight.eventReference.split(':') const kind = parseInt(parts[0]) const pubkey = parts[1] const identifier = parts[2] || '' @@ -50,7 +59,7 @@ export const HighlightCitation: React.FC = ({ identifier }) } else { - naddr = eventReference + naddr = highlight.eventReference } const title = await fetchArticleTitle(relayPool, naddr) @@ -63,12 +72,12 @@ export const HighlightCitation: React.FC = ({ } loadTitle() - }, [eventReference, relayPool]) + }, [highlight.eventReference, relayPool]) const authorName = authorProfile?.name || authorProfile?.display_name // For nostr-native content with article reference - if (eventReference && (authorName || articleTitle)) { + if (highlight.eventReference && (authorName || articleTitle)) { return (
— {authorName || 'Unknown'}{articleTitle ? `, ${articleTitle}` : ''} @@ -77,9 +86,9 @@ export const HighlightCitation: React.FC = ({ } // For web URLs - if (urlReference) { + if (highlight.urlReference) { try { - const url = new URL(urlReference) + const url = new URL(highlight.urlReference) return (
— {url.hostname} diff --git a/src/components/HighlightItem.tsx b/src/components/HighlightItem.tsx index 88319c1b..59f590e3 100644 --- a/src/components/HighlightItem.tsx +++ b/src/components/HighlightItem.tsx @@ -340,9 +340,7 @@ export const HighlightItem: React.FC = ({