mirror of
https://github.com/dergigi/boris.git
synced 2026-01-16 21:34:21 +01:00
- Add useStoreTimeline hook for reactive EventStore queries - Add dedupe helpers for highlights and writings - Explore: seed highlights and writings from store instantly - Article sidebar: seed article-specific highlights from store - External URLs: seed URL-specific highlights from store - Profile pages: seed other-profile highlights and writings from store - Remove debug logging - All data loads from cache first, then updates with fresh data - Follows DRY principles with single reusable hook
34 lines
1004 B
TypeScript
34 lines
1004 B
TypeScript
import { useMemo } from 'react'
|
|
import { useObservableMemo } from 'applesauce-react/hooks'
|
|
import { startWith } from 'rxjs'
|
|
import type { IEventStore } from 'applesauce-core'
|
|
import type { Filter, NostrEvent } from 'nostr-tools'
|
|
|
|
/**
|
|
* Subscribe to EventStore timeline and map events to app types
|
|
* Provides instant cached results, then updates reactively
|
|
*
|
|
* @param eventStore - The applesauce event store
|
|
* @param filter - Nostr filter to query
|
|
* @param mapEvent - Function to transform NostrEvent to app type
|
|
* @param deps - Dependencies for memoization
|
|
* @returns Array of mapped results
|
|
*/
|
|
export function useStoreTimeline<T>(
|
|
eventStore: IEventStore | null,
|
|
filter: Filter,
|
|
mapEvent: (event: NostrEvent) => T,
|
|
deps: unknown[] = []
|
|
): T[] {
|
|
const events = useObservableMemo(
|
|
() => eventStore ? eventStore.timeline(filter).pipe(startWith([])) : undefined,
|
|
[eventStore, ...deps]
|
|
)
|
|
|
|
return useMemo(
|
|
() => events?.map(mapEvent) ?? [],
|
|
[events, mapEvent]
|
|
)
|
|
}
|
|
|