mirror of
https://github.com/dergigi/boris.git
synced 2025-12-22 17:14:20 +01:00
debug: add comprehensive logging for reading position calculation and event publishing
- Add logs in useReadingPosition: scroll position calculation (throttled to 5% changes) - Add logs for scheduling and triggering auto-save - Add detailed logs in ContentPanel handleSavePosition - Add logs in saveReadingPosition: event creation, signing, publishing - Add logs in publishEvent: event store addition, relay status, publishing - All logs prefixed with [progress] for easy filtering - Shows complete flow from scroll → calculate → save → create event → publish to relays
This commit is contained in:
@@ -151,7 +151,7 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
// Callback to save reading position
|
// Callback to save reading position
|
||||||
const handleSavePosition = useCallback(async (position: number) => {
|
const handleSavePosition = useCallback(async (position: number) => {
|
||||||
if (!activeAccount || !relayPool || !eventStore || !articleIdentifier) {
|
if (!activeAccount || !relayPool || !eventStore || !articleIdentifier) {
|
||||||
console.log('⏭️ [ContentPanel] Skipping save - missing requirements:', {
|
console.log('[progress] ⏭️ ContentPanel: Skipping save - missing requirements:', {
|
||||||
hasAccount: !!activeAccount,
|
hasAccount: !!activeAccount,
|
||||||
hasRelayPool: !!relayPool,
|
hasRelayPool: !!relayPool,
|
||||||
hasEventStore: !!eventStore,
|
hasEventStore: !!eventStore,
|
||||||
@@ -160,11 +160,18 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!settings?.syncReadingPosition) {
|
if (!settings?.syncReadingPosition) {
|
||||||
console.log('⏭️ [ContentPanel] Sync disabled in settings')
|
console.log('[progress] ⏭️ ContentPanel: Sync disabled in settings')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('💾 [ContentPanel] Saving position:', Math.round(position * 100) + '%', 'for article:', selectedUrl?.slice(0, 50))
|
const scrollTop = window.pageYOffset || document.documentElement.scrollTop
|
||||||
|
console.log('[progress] 💾 ContentPanel: Saving position:', {
|
||||||
|
position,
|
||||||
|
percentage: Math.round(position * 100) + '%',
|
||||||
|
scrollTop,
|
||||||
|
articleIdentifier: articleIdentifier.slice(0, 50) + '...',
|
||||||
|
url: selectedUrl?.slice(0, 50)
|
||||||
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const factory = new EventFactory({ signer: activeAccount })
|
const factory = new EventFactory({ signer: activeAccount })
|
||||||
@@ -176,11 +183,12 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
{
|
{
|
||||||
position,
|
position,
|
||||||
timestamp: Math.floor(Date.now() / 1000),
|
timestamp: Math.floor(Date.now() / 1000),
|
||||||
scrollTop: window.pageYOffset || document.documentElement.scrollTop
|
scrollTop
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
console.log('[progress] ✅ ContentPanel: Save completed successfully')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ [ContentPanel] Failed to save reading position:', error)
|
console.error('[progress] ❌ ContentPanel: Failed to save reading position:', error)
|
||||||
}
|
}
|
||||||
}, [activeAccount, relayPool, eventStore, articleIdentifier, settings?.syncReadingPosition, selectedUrl])
|
}, [activeAccount, relayPool, eventStore, articleIdentifier, settings?.syncReadingPosition, selectedUrl])
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,9 @@ export const useReadingPosition = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Schedule new save
|
// Schedule new save
|
||||||
|
console.log('[progress] ⏰ Scheduling save in', autoSaveInterval + 'ms for position:', Math.round(currentPosition * 100) + '%')
|
||||||
saveTimerRef.current = setTimeout(() => {
|
saveTimerRef.current = setTimeout(() => {
|
||||||
|
console.log('[progress] 💾 Auto-saving position:', Math.round(currentPosition * 100) + '%')
|
||||||
lastSavedPosition.current = currentPosition
|
lastSavedPosition.current = currentPosition
|
||||||
onSave(currentPosition)
|
onSave(currentPosition)
|
||||||
}, autoSaveInterval)
|
}, autoSaveInterval)
|
||||||
@@ -63,8 +65,11 @@ export const useReadingPosition = ({
|
|||||||
|
|
||||||
// Save if position is meaningful (>= 5%)
|
// Save if position is meaningful (>= 5%)
|
||||||
if (position >= 0.05) {
|
if (position >= 0.05) {
|
||||||
|
console.log('[progress] 💾 Immediate save triggered for position:', Math.round(position * 100) + '%')
|
||||||
lastSavedPosition.current = position
|
lastSavedPosition.current = position
|
||||||
onSave(position)
|
onSave(position)
|
||||||
|
} else {
|
||||||
|
console.log('[progress] ⏭️ Skipping save - position too low:', Math.round(position * 100) + '%')
|
||||||
}
|
}
|
||||||
}, [syncEnabled, onSave, position])
|
}, [syncEnabled, onSave, position])
|
||||||
|
|
||||||
@@ -89,6 +94,17 @@ export const useReadingPosition = ({
|
|||||||
const isAtBottom = scrollTop + windowHeight >= documentHeight - 5
|
const isAtBottom = scrollTop + windowHeight >= documentHeight - 5
|
||||||
const clampedProgress = isAtBottom ? 1 : Math.max(0, Math.min(1, scrollProgress))
|
const clampedProgress = isAtBottom ? 1 : Math.max(0, Math.min(1, scrollProgress))
|
||||||
|
|
||||||
|
// Only log on significant changes (every 5%) to avoid flooding console
|
||||||
|
const prevPercent = Math.floor(position * 20) // Groups by 5%
|
||||||
|
const newPercent = Math.floor(clampedProgress * 20)
|
||||||
|
if (prevPercent !== newPercent) {
|
||||||
|
console.log('[progress] 📏 useReadingPosition:', Math.round(clampedProgress * 100) + '%', {
|
||||||
|
scrollTop,
|
||||||
|
documentHeight,
|
||||||
|
isAtBottom
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
setPosition(clampedProgress)
|
setPosition(clampedProgress)
|
||||||
onPositionChange?.(clampedProgress)
|
onPositionChange?.(clampedProgress)
|
||||||
|
|
||||||
|
|||||||
@@ -114,8 +114,8 @@ export async function saveReadingPosition(
|
|||||||
articleIdentifier: string,
|
articleIdentifier: string,
|
||||||
position: ReadingPosition
|
position: ReadingPosition
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
console.log('💾 [ReadingProgress] Saving position:', {
|
console.log('[progress] 💾 saveReadingPosition: Starting save:', {
|
||||||
identifier: articleIdentifier.slice(0, 32) + '...',
|
identifier: articleIdentifier.slice(0, 50) + '...',
|
||||||
position: position.position,
|
position: position.position,
|
||||||
positionPercent: Math.round(position.position * 100) + '%',
|
positionPercent: Math.round(position.position * 100) + '%',
|
||||||
timestamp: position.timestamp,
|
timestamp: position.timestamp,
|
||||||
@@ -133,6 +133,13 @@ export async function saveReadingPosition(
|
|||||||
|
|
||||||
const tags = generateProgressTags(articleIdentifier)
|
const tags = generateProgressTags(articleIdentifier)
|
||||||
|
|
||||||
|
console.log('[progress] 📝 Creating event with:', {
|
||||||
|
kind: READING_PROGRESS_KIND,
|
||||||
|
content: progressContent,
|
||||||
|
tags: tags.map(t => `[${t.join(', ')}]`).join(', '),
|
||||||
|
created_at: now
|
||||||
|
})
|
||||||
|
|
||||||
const draft = await factory.create(async () => ({
|
const draft = await factory.create(async () => ({
|
||||||
kind: READING_PROGRESS_KIND,
|
kind: READING_PROGRESS_KIND,
|
||||||
content: JSON.stringify(progressContent),
|
content: JSON.stringify(progressContent),
|
||||||
@@ -140,10 +147,20 @@ export async function saveReadingPosition(
|
|||||||
created_at: now
|
created_at: now
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
console.log('[progress] ✍️ Signing event...')
|
||||||
const signed = await factory.sign(draft)
|
const signed = await factory.sign(draft)
|
||||||
|
|
||||||
|
console.log('[progress] 📡 Publishing event:', {
|
||||||
|
id: signed.id,
|
||||||
|
kind: signed.kind,
|
||||||
|
pubkey: signed.pubkey.slice(0, 8) + '...',
|
||||||
|
content: signed.content,
|
||||||
|
tags: signed.tags
|
||||||
|
})
|
||||||
|
|
||||||
await publishEvent(relayPool, eventStore, signed)
|
await publishEvent(relayPool, eventStore, signed)
|
||||||
|
|
||||||
console.log('✅ [ReadingProgress] Saved, event ID:', signed.id.slice(0, 8))
|
console.log('[progress] ✅ Event published successfully, ID:', signed.id.slice(0, 16))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,9 +14,12 @@ export async function publishEvent(
|
|||||||
eventStore: IEventStore,
|
eventStore: IEventStore,
|
||||||
event: NostrEvent
|
event: NostrEvent
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
const isProgressEvent = event.kind === 39802
|
||||||
|
const logPrefix = isProgressEvent ? '[progress]' : ''
|
||||||
|
|
||||||
// Store the event in the local EventStore FIRST for immediate UI display
|
// Store the event in the local EventStore FIRST for immediate UI display
|
||||||
eventStore.add(event)
|
eventStore.add(event)
|
||||||
console.log('💾 Stored event in EventStore:', event.id.slice(0, 8), `(kind ${event.kind})`)
|
console.log(`${logPrefix} 💾 Stored event in EventStore:`, event.id.slice(0, 8), `(kind ${event.kind})`)
|
||||||
|
|
||||||
// Check current connection status - are we online or in flight mode?
|
// Check current connection status - are we online or in flight mode?
|
||||||
const connectedRelays = Array.from(relayPool.relays.values())
|
const connectedRelays = Array.from(relayPool.relays.values())
|
||||||
@@ -32,12 +35,13 @@ export async function publishEvent(
|
|||||||
|
|
||||||
const isLocalOnly = areAllRelaysLocal(expectedSuccessRelays)
|
const isLocalOnly = areAllRelaysLocal(expectedSuccessRelays)
|
||||||
|
|
||||||
console.log('📍 Event relay status:', {
|
console.log(`${logPrefix} 📍 Event relay status:`, {
|
||||||
targetRelays: RELAYS.length,
|
targetRelays: RELAYS.length,
|
||||||
expectedSuccessRelays: expectedSuccessRelays.length,
|
expectedSuccessRelays: expectedSuccessRelays.length,
|
||||||
isLocalOnly,
|
isLocalOnly,
|
||||||
hasRemoteConnection,
|
hasRemoteConnection,
|
||||||
eventId: event.id.slice(0, 8)
|
eventId: event.id.slice(0, 8),
|
||||||
|
connectedRelays: connectedRelays.length
|
||||||
})
|
})
|
||||||
|
|
||||||
// If we're in local-only mode, mark this event for later sync
|
// If we're in local-only mode, mark this event for later sync
|
||||||
@@ -46,12 +50,13 @@ export async function publishEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Publish to all configured relays in the background (non-blocking)
|
// Publish to all configured relays in the background (non-blocking)
|
||||||
|
console.log(`${logPrefix} 📤 Publishing to relays:`, RELAYS)
|
||||||
relayPool.publish(RELAYS, event)
|
relayPool.publish(RELAYS, event)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('✅ Event published to', RELAYS.length, 'relay(s):', event.id.slice(0, 8))
|
console.log(`${logPrefix} ✅ Event published to`, RELAYS.length, 'relay(s):', event.id.slice(0, 8))
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.warn('⚠️ Failed to publish event to relays (event still saved locally):', error)
|
console.warn(`${logPrefix} ⚠️ Failed to publish event to relays (event still saved locally):`, error)
|
||||||
|
|
||||||
// Surface common bunker signing errors for debugging
|
// Surface common bunker signing errors for debugging
|
||||||
if (error instanceof Error && error.message.includes('permission')) {
|
if (error instanceof Error && error.message.includes('permission')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user