mirror of
https://github.com/dergigi/boris.git
synced 2025-12-19 23:54:23 +01:00
refactor: use applesauce helpers for highlight parsing
- Replace manual tag parsing with applesauce-core helper functions - Use getHighlightText, getHighlightContext, getHighlightComment, etc. - Add support for highlight comments in UI - Extract author from attributions using proper helper - Handle both event and address pointers correctly - Add styling for highlight comments This follows applesauce best practices and makes the code more robust.
This commit is contained in:
@@ -37,6 +37,12 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({ highlight, onSelec
|
|||||||
{highlight.content}
|
{highlight.content}
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
{highlight.comment && (
|
||||||
|
<div className="highlight-comment">
|
||||||
|
{highlight.comment}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{highlight.context && (
|
{highlight.context && (
|
||||||
<details className="highlight-context">
|
<details className="highlight-context">
|
||||||
<summary>Show context</summary>
|
<summary>Show context</summary>
|
||||||
|
|||||||
@@ -1229,6 +1229,17 @@ body {
|
|||||||
font-size: 0.95rem;
|
font-size: 0.95rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.highlight-comment {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
padding: 0.75rem;
|
||||||
|
background: rgba(100, 108, 255, 0.1);
|
||||||
|
border-left: 3px solid #646cff;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: #ddd;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
.highlight-context {
|
.highlight-context {
|
||||||
margin-top: 0.5rem;
|
margin-top: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import { RelayPool, completeOnEose } from 'applesauce-relay'
|
import { RelayPool, completeOnEose } from 'applesauce-relay'
|
||||||
import { lastValueFrom, takeUntil, timer, toArray } from 'rxjs'
|
import { lastValueFrom, takeUntil, timer, toArray } from 'rxjs'
|
||||||
|
import { NostrEvent } from 'nostr-tools'
|
||||||
|
import {
|
||||||
|
getHighlightText,
|
||||||
|
getHighlightContext,
|
||||||
|
getHighlightComment,
|
||||||
|
getHighlightSourceEventPointer,
|
||||||
|
getHighlightSourceAddressPointer,
|
||||||
|
getHighlightSourceUrl,
|
||||||
|
getHighlightAttributions
|
||||||
|
} from 'applesauce-core/helpers'
|
||||||
import { Highlight } from '../types/highlights'
|
import { Highlight } from '../types/highlights'
|
||||||
|
|
||||||
interface NostrEvent {
|
|
||||||
id: string
|
|
||||||
pubkey: string
|
|
||||||
created_at: number
|
|
||||||
kind: number
|
|
||||||
tags: string[][]
|
|
||||||
content: string
|
|
||||||
sig: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deduplicate highlight events by ID
|
* Deduplicate highlight events by ID
|
||||||
* Since highlights can come from multiple relays, we need to ensure
|
* Since highlights can come from multiple relays, we need to ensure
|
||||||
@@ -51,22 +51,33 @@ export const fetchHighlights = async (
|
|||||||
console.log('📊 Unique highlight events after deduplication:', uniqueEvents.length)
|
console.log('📊 Unique highlight events after deduplication:', uniqueEvents.length)
|
||||||
|
|
||||||
const highlights: Highlight[] = uniqueEvents.map((event: NostrEvent) => {
|
const highlights: Highlight[] = uniqueEvents.map((event: NostrEvent) => {
|
||||||
// Extract relevant tags
|
// Use applesauce helpers to extract highlight data
|
||||||
const eventRef = event.tags.find(t => t[0] === 'e' || t[0] === 'a')?.[1]
|
const highlightText = getHighlightText(event)
|
||||||
const urlRef = event.tags.find(t => t[0] === 'r')?.[1]
|
const context = getHighlightContext(event)
|
||||||
const authorTag = event.tags.find(t => t[0] === 'p' && t[3] === 'author')
|
const comment = getHighlightComment(event)
|
||||||
const contextTag = event.tags.find(t => t[0] === 'context')
|
const sourceEventPointer = getHighlightSourceEventPointer(event)
|
||||||
|
const sourceAddressPointer = getHighlightSourceAddressPointer(event)
|
||||||
|
const sourceUrl = getHighlightSourceUrl(event)
|
||||||
|
const attributions = getHighlightAttributions(event)
|
||||||
|
|
||||||
|
// Get author from attributions
|
||||||
|
const author = attributions.find(a => a.role === 'author')?.pubkey
|
||||||
|
|
||||||
|
// Get event reference (prefer event pointer, fallback to address pointer)
|
||||||
|
const eventReference = sourceEventPointer?.id ||
|
||||||
|
(sourceAddressPointer ? `${sourceAddressPointer.kind}:${sourceAddressPointer.pubkey}:${sourceAddressPointer.identifier}` : undefined)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: event.id,
|
id: event.id,
|
||||||
pubkey: event.pubkey,
|
pubkey: event.pubkey,
|
||||||
created_at: event.created_at,
|
created_at: event.created_at,
|
||||||
content: event.content,
|
content: highlightText,
|
||||||
tags: event.tags,
|
tags: event.tags,
|
||||||
eventReference: eventRef,
|
eventReference,
|
||||||
urlReference: urlRef,
|
urlReference: sourceUrl,
|
||||||
author: authorTag?.[1],
|
author,
|
||||||
context: contextTag?.[1]
|
context,
|
||||||
|
comment
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -10,5 +10,6 @@ export interface Highlight {
|
|||||||
urlReference?: string // 'r' tag
|
urlReference?: string // 'r' tag
|
||||||
author?: string // 'p' tag with 'author' role
|
author?: string // 'p' tag with 'author' role
|
||||||
context?: string // surrounding text context
|
context?: string // surrounding text context
|
||||||
|
comment?: string // optional comment about the highlight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user