fix(bookmarks): dedupe individual bookmarks by id to avoid duplicates in UI

This commit is contained in:
Gigi
2025-10-02 22:28:47 +02:00
parent e0b042b6c0
commit 2696bdb57a
2 changed files with 16 additions and 3 deletions

View File

@@ -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
}

View File

@@ -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))