From 1e6718fe1e2eba8d4220823efa1dd6966958c376 Mon Sep 17 00:00:00 2001 From: Gigi Date: Sat, 18 Oct 2025 20:56:53 +0200 Subject: [PATCH] fix: improve Load Friends button behavior in Debug - Add local loading state for button (friendsButtonLoading) - Clear friends list before loading to show streaming - Set final result after controller completes - Add error handling and logging - Remove unused global friendsLoading subscription - Button now properly shows loading state and results --- src/components/Debug.tsx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/components/Debug.tsx b/src/components/Debug.tsx index 43ea5b78..de2b8c73 100644 --- a/src/components/Debug.tsx +++ b/src/components/Debug.tsx @@ -105,18 +105,12 @@ const Debug: React.FC = ({ // Web of Trust state const [friendsPubkeys, setFriendsPubkeys] = useState>(new Set()) - const [friendsLoading, setFriendsLoading] = useState(false) + const [friendsButtonLoading, setFriendsButtonLoading] = useState(false) useEffect(() => { return DebugBus.subscribe((e) => setLogs(prev => [...prev, e].slice(-300))) }, []) - // Subscribe to contacts controller for friends list display - useEffect(() => { - const unsubLoading = contactsController.onLoading(setFriendsLoading) - return unsubLoading - }, []) - // Live timer effect - triggers re-renders for live timing updates useEffect(() => { const interval = setInterval(() => { @@ -554,10 +548,16 @@ const Debug: React.FC = ({ DebugBus.warn('debug', 'Please log in to load friends list') return } + + setFriendsButtonLoading(true) DebugBus.info('debug', 'Loading friends list via controller...') - // Subscribe to controller updates + // Clear current list + setFriendsPubkeys(new Set()) + + // Subscribe to controller updates to see streaming const unsubscribe = contactsController.onContacts((contacts) => { + console.log('[debug] Received contacts update:', contacts.size) setFriendsPubkeys(new Set(contacts)) }) @@ -565,9 +565,14 @@ const Debug: React.FC = ({ // Force reload to see streaming behavior await contactsController.start({ relayPool, pubkey: activeAccount.pubkey, force: true }) const final = contactsController.getContacts() + setFriendsPubkeys(new Set(final)) DebugBus.info('debug', `Loaded ${final.size} friends from controller`) + } catch (err) { + console.error('[debug] Failed to load friends:', err) + DebugBus.error('debug', `Failed to load friends: ${err instanceof Error ? err.message : String(err)}`) } finally { unsubscribe() + setFriendsButtonLoading(false) } } @@ -1079,9 +1084,9 @@ const Debug: React.FC = ({