debug: add extensive logging to track bookmark flow

Simplified to only show unencrypted bookmarks:
- Skip encrypted events entirely (no decrypt for now)
- This eliminates all parse errors

Added comprehensive logging:
- Controller: log when building, how many items, how many listeners, when emitting
- App: log when subscribing, when receiving bookmarks, when loading state changes

This will help identify where the disconnect is between controller and sidebar.
This commit is contained in:
Gigi
2025-10-17 23:27:04 +02:00
parent 8dbb18b1c8
commit 51b7e53385
2 changed files with 14 additions and 9 deletions

View File

@@ -42,10 +42,18 @@ function AppRoutes({
// Subscribe to bookmark controller
useEffect(() => {
const unsubBookmarks = bookmarkController.onBookmarks(setBookmarks)
const unsubLoading = bookmarkController.onLoading(setBookmarksLoading)
console.log('[app] 🎧 Subscribing to bookmark controller')
const unsubBookmarks = bookmarkController.onBookmarks((bookmarks) => {
console.log('[app] 📥 Received bookmarks:', bookmarks.length)
setBookmarks(bookmarks)
})
const unsubLoading = bookmarkController.onLoading((loading) => {
console.log('[app] 📥 Loading state:', loading)
setBookmarksLoading(loading)
})
return () => {
console.log('[app] 🔇 Unsubscribing from bookmark controller')
unsubBookmarks()
unsubLoading()
}

View File

@@ -106,14 +106,10 @@ class BookmarkController {
): Promise<void> {
const allEvents = Array.from(this.currentEvents.values())
// Only process events that are ready (unencrypted or already decrypted)
const readyEvents = allEvents.filter(evt => {
const isEncrypted = hasEncryptedContent(evt)
if (!isEncrypted) return true // Unencrypted - ready
return this.decryptedEvents.has(evt.id) // Encrypted - only if decrypted
})
// Only process unencrypted events for now (skip encrypted entirely)
const readyEvents = allEvents.filter(evt => !hasEncryptedContent(evt))
console.log('[controller] 📋 Building bookmarks:', readyEvents.length, 'ready of', allEvents.length, 'total')
console.log('[controller] 📋 Building bookmarks:', readyEvents.length, 'unencrypted of', allEvents.length, 'total')
if (readyEvents.length === 0) {
this.bookmarksListeners.forEach(cb => cb([]))
@@ -231,6 +227,7 @@ class BookmarkController {
}
console.log('[controller] 📋 Built bookmark with', sortedBookmarks.length, 'items')
console.log('[controller] 📤 Emitting to', this.bookmarksListeners.length, 'listeners')
this.bookmarksListeners.forEach(cb => cb([bookmark]))
} catch (error) {
console.error('[controller] ❌ Failed to build bookmarks:', error)