mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 14:44:26 +01:00
feat(bookmarks): sort by added_at (recently added first), fallback to event time\n\n- Track synthetic added_at on processed items\n- Keep order aligned with append semantics from Kind 10003 guidance (newest at end)\n- Cite: https://nostrbook.dev/kinds/10003
This commit is contained in:
@@ -66,7 +66,8 @@ export const processApplesauceBookmarks = (
|
|||||||
tags: bookmark.tags || [],
|
tags: bookmark.tags || [],
|
||||||
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
|
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
|
||||||
type: 'event' as const,
|
type: 'event' as const,
|
||||||
isPrivate
|
isPrivate,
|
||||||
|
added_at: Math.floor(Date.now() / 1000)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +81,8 @@ export const processApplesauceBookmarks = (
|
|||||||
tags: bookmark.tags || [],
|
tags: bookmark.tags || [],
|
||||||
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
|
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
|
||||||
type: 'event' as const,
|
type: 'event' as const,
|
||||||
isPrivate
|
isPrivate,
|
||||||
|
added_at: Math.floor(Date.now() / 1000)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,8 @@ export const fetchBookmarks = async (
|
|||||||
...hydrateItems(privateItemsAll, idToEvent)
|
...hydrateItems(privateItemsAll, idToEvent)
|
||||||
])
|
])
|
||||||
|
|
||||||
// Sort individual bookmarks by timestamp (newest first)
|
// Sort individual bookmarks by "added" timestamp first (most recently added first),
|
||||||
|
// falling back to event created_at when unknown.
|
||||||
const enriched = allBookmarks.map(b => ({
|
const enriched = allBookmarks.map(b => ({
|
||||||
...b,
|
...b,
|
||||||
tags: b.tags || [],
|
tags: b.tags || [],
|
||||||
@@ -121,7 +122,7 @@ export const fetchBookmarks = async (
|
|||||||
}))
|
}))
|
||||||
const sortedBookmarks = enriched
|
const sortedBookmarks = enriched
|
||||||
.map(b => ({ ...b, urlReferences: extractUrlsFromContent(b.content) }))
|
.map(b => ({ ...b, urlReferences: extractUrlsFromContent(b.content) }))
|
||||||
.sort((a, b) => (b.created_at || 0) - (a.created_at || 0))
|
.sort((a, b) => ((b.added_at || 0) - (a.added_at || 0)) || ((b.created_at || 0) - (a.created_at || 0)))
|
||||||
|
|
||||||
const bookmark: Bookmark = {
|
const bookmark: Bookmark = {
|
||||||
id: `${activeAccount.pubkey}-bookmarks`,
|
id: `${activeAccount.pubkey}-bookmarks`,
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ export interface IndividualBookmark {
|
|||||||
type: 'event' | 'article'
|
type: 'event' | 'article'
|
||||||
isPrivate?: boolean
|
isPrivate?: boolean
|
||||||
encryptedContent?: string
|
encryptedContent?: string
|
||||||
|
// When the item was added to the bookmark list (synthetic, for sorting)
|
||||||
|
added_at?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ActiveAccount {
|
export interface ActiveAccount {
|
||||||
|
|||||||
Reference in New Issue
Block a user