mirror of
https://github.com/dergigi/boris.git
synced 2026-02-16 20:45:01 +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
36 lines
1023 B
TypeScript
36 lines
1023 B
TypeScript
import { Highlight } from '../types/highlights'
|
|
import { BlogPostPreview } from '../services/exploreService'
|
|
|
|
/**
|
|
* Deduplicate highlights by ID
|
|
*/
|
|
export function dedupeHighlightsById(highlights: Highlight[]): Highlight[] {
|
|
const byId = new Map<string, Highlight>()
|
|
for (const highlight of highlights) {
|
|
byId.set(highlight.id, highlight)
|
|
}
|
|
return Array.from(byId.values())
|
|
}
|
|
|
|
/**
|
|
* Deduplicate blog posts by replaceable event key (author:d-tag)
|
|
* Keeps the newest version when duplicates exist
|
|
*/
|
|
export function dedupeWritingsByReplaceable(posts: BlogPostPreview[]): BlogPostPreview[] {
|
|
const byKey = new Map<string, BlogPostPreview>()
|
|
|
|
for (const post of posts) {
|
|
const dTag = post.event.tags.find(t => t[0] === 'd')?.[1] || ''
|
|
const key = `${post.author}:${dTag}`
|
|
const existing = byKey.get(key)
|
|
|
|
// Keep the newer version
|
|
if (!existing || post.event.created_at > existing.event.created_at) {
|
|
byKey.set(key, post)
|
|
}
|
|
}
|
|
|
|
return Array.from(byKey.values())
|
|
}
|
|
|