mirror of
https://github.com/dergigi/boris.git
synced 2026-01-31 12:44:37 +01:00
fix(bookmarks): dedupe individual bookmarks by id to avoid duplicates in UI
This commit is contained in:
@@ -119,4 +119,16 @@ export function hasNip04Decrypt(obj: unknown): obj is { nip04: { decrypt: Decryp
|
||||
return typeof nip04?.decrypt === 'function'
|
||||
}
|
||||
|
||||
export function dedupeBookmarksById(bookmarks: IndividualBookmark[]): IndividualBookmark[] {
|
||||
const seen = new Set<string>()
|
||||
const result: IndividualBookmark[] = []
|
||||
for (const b of bookmarks) {
|
||||
if (!seen.has(b.id)) {
|
||||
seen.add(b.id)
|
||||
result.push(b)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ import {
|
||||
isAccountWithExtension,
|
||||
isHexId,
|
||||
hasNip04Decrypt,
|
||||
hasNip44Decrypt
|
||||
hasNip44Decrypt,
|
||||
dedupeBookmarksById
|
||||
} from './bookmarkHelpers'
|
||||
import { Bookmark } from '../types/bookmarks'
|
||||
import { collectBookmarksFromEvents } from './bookmarkProcessing.ts'
|
||||
@@ -106,10 +107,10 @@ export const fetchBookmarks = async (
|
||||
console.warn('Failed to fetch events for hydration:', error)
|
||||
}
|
||||
}
|
||||
const allBookmarks = [
|
||||
const allBookmarks = dedupeBookmarksById([
|
||||
...hydrateItems(publicItemsAll, idToEvent),
|
||||
...hydrateItems(privateItemsAll, idToEvent)
|
||||
]
|
||||
])
|
||||
|
||||
// Sort individual bookmarks by timestamp (newest first)
|
||||
const sortedBookmarks = allBookmarks.sort((a, b) => (b.created_at || 0) - (a.created_at || 0))
|
||||
|
||||
Reference in New Issue
Block a user