diff --git a/components/SyncProgressBar.tsx b/components/SyncProgressBar.tsx index 369274a..4bac335 100644 --- a/components/SyncProgressBar.tsx +++ b/components/SyncProgressBar.tsx @@ -37,6 +37,7 @@ export function SyncProgressBar(): React.ReactElement | null { // Check connection state const checkConnection = (): void => { const state = nostrAuthService.getState() + console.log('[SyncProgressBar] Initial connection check:', { connected: state.connected, pubkey: state.pubkey }) setConnectionState({ connected: state.connected ?? false, pubkey: state.pubkey ?? null }) setIsInitialized(true) } @@ -46,6 +47,7 @@ export function SyncProgressBar(): React.ReactElement | null { // Listen to connection changes const unsubscribe = nostrAuthService.subscribe((state) => { + console.log('[SyncProgressBar] Connection state changed:', { connected: state.connected, pubkey: state.pubkey }) setConnectionState({ connected: state.connected ?? false, pubkey: state.pubkey ?? null }) }) @@ -55,11 +57,25 @@ export function SyncProgressBar(): React.ReactElement | null { }, []) useEffect(() => { - if (!isInitialized || !connectionState.connected || !connectionState.pubkey) { + console.log('[SyncProgressBar] Effect triggered:', { isInitialized, connected: connectionState.connected, pubkey: connectionState.pubkey, isSyncing }) + + if (!isInitialized) { + console.log('[SyncProgressBar] Not initialized yet') + return + } + + if (!connectionState.connected) { + console.log('[SyncProgressBar] Not connected') + return + } + + if (!connectionState.pubkey) { + console.log('[SyncProgressBar] No pubkey') return } void (async () => { + console.log('[SyncProgressBar] Starting sync check...') await loadSyncStatus() // Auto-start sync if not recently synced @@ -67,8 +83,11 @@ export function SyncProgressBar(): React.ReactElement | null { const currentTimestamp = getCurrentTimestamp() const isRecentlySynced = storedLastSyncDate >= currentTimestamp - 3600 + console.log('[SyncProgressBar] Sync status:', { storedLastSyncDate, currentTimestamp, isRecentlySynced, isSyncing }) + // Only auto-start if not recently synced if (!isRecentlySynced && !isSyncing && connectionState.pubkey) { + console.log('[SyncProgressBar] Starting auto-sync...') setIsSyncing(true) setSyncProgress({ currentStep: 0, totalSteps: 6, completed: false }) @@ -83,13 +102,15 @@ export function SyncProgressBar(): React.ReactElement | null { // Check if sync completed successfully (if it didn't, isSyncing should still be false) setIsSyncing(false) } catch (error) { - console.error('Error during auto-sync:', error) + console.error('[SyncProgressBar] Error during auto-sync:', error) setIsSyncing(false) setError(error instanceof Error ? error.message : 'Erreur de synchronisation') } + } else { + console.log('[SyncProgressBar] Skipping auto-sync:', { isRecentlySynced, isSyncing, hasPubkey: Boolean(connectionState.pubkey) }) } })() - }, [isInitialized, connectionState.connected, connectionState.pubkey]) + }, [isInitialized, connectionState.connected, connectionState.pubkey, isSyncing]) async function resynchronize(): Promise { try { @@ -136,9 +157,12 @@ export function SyncProgressBar(): React.ReactElement | null { // Don't show if not initialized or not connected if (!isInitialized || !connectionState.connected || !connectionState.pubkey) { + console.log('[SyncProgressBar] Not rendering:', { isInitialized, connected: connectionState.connected, pubkey: connectionState.pubkey }) return null } + console.log('[SyncProgressBar] Rendering component') + // Check if sync is recently completed (within last hour) const isRecentlySynced = lastSyncDate !== null && lastSyncDate >= getCurrentTimestamp() - 3600 diff --git a/hooks/useDocs.ts b/hooks/useDocs.ts index ede1dd0..e8c7cde 100644 --- a/hooks/useDocs.ts +++ b/hooks/useDocs.ts @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react' +import { useState, useEffect, useCallback } from 'react' import { getLocale } from '@/lib/i18n' export type DocSection = 'user-guide' | 'faq' | 'publishing' | 'payment' | 'fees-and-contributions' @@ -19,7 +19,7 @@ export function useDocs(docs: DocLink[]): { const [docContent, setDocContent] = useState('') const [loading, setLoading] = useState(false) - const loadDoc = async (docId: DocSection): Promise => { + const loadDoc = useCallback(async (docId: DocSection): Promise => { const doc = docs.find((d) => d.id === docId) if (!doc) {return} @@ -45,12 +45,11 @@ export function useDocs(docs: DocLink[]): { } finally { setLoading(false) } - } + }, [docs]) useEffect(() => { loadDoc('user-guide') - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []) + }, [loadDoc]) return { selectedDoc,