From d3061bf83f7af285d9eca11aea6b6807d53585be Mon Sep 17 00:00:00 2001 From: tapframe Date: Fri, 20 Jun 2025 02:24:27 +0530 Subject: [PATCH] Refactor useTraktAutosyncSettings for improved manual sync logic and logging This update enhances the manual sync process in the useTraktAutosyncSettings hook by introducing a more comprehensive success condition. The sync is now considered successful if either fetching from Trakt or uploading local progress succeeds, improving user feedback. Additionally, unnecessary debug buttons have been removed from the TraktSettingsScreen, streamlining the UI and enhancing user experience. --- src/hooks/useTraktAutosyncSettings.ts | 14 +++++--- src/screens/TraktSettingsScreen.tsx | 50 --------------------------- 2 files changed, 10 insertions(+), 54 deletions(-) diff --git a/src/hooks/useTraktAutosyncSettings.ts b/src/hooks/useTraktAutosyncSettings.ts index 9bcac08e..29d32686 100644 --- a/src/hooks/useTraktAutosyncSettings.ts +++ b/src/hooks/useTraktAutosyncSettings.ts @@ -107,13 +107,19 @@ export function useTraktAutosyncSettings() { logger.log('[useTraktAutosyncSettings] Starting manual sync...'); // First, fetch and merge Trakt progress with local - await fetchAndMergeTraktProgress(); + const fetchSuccess = await fetchAndMergeTraktProgress(); // Then, sync any unsynced local progress to Trakt - const success = await syncAllProgress(); + const uploadSuccess = await syncAllProgress(); - logger.log(`[useTraktAutosyncSettings] Manual sync ${success ? 'completed' : 'failed'}`); - return success; + // Consider sync successful if either: + // 1. We successfully fetched from Trakt (main purpose of manual sync) + // 2. We successfully uploaded local progress to Trakt + // 3. Everything was already in sync (uploadSuccess = false is OK if fetchSuccess = true) + const overallSuccess = fetchSuccess || uploadSuccess; + + logger.log(`[useTraktAutosyncSettings] Manual sync ${overallSuccess ? 'completed' : 'failed'}`); + return overallSuccess; } catch (error) { logger.error('[useTraktAutosyncSettings] Error during manual sync:', error); return false; diff --git a/src/screens/TraktSettingsScreen.tsx b/src/screens/TraktSettingsScreen.tsx index ec3ad88e..d0cfa96d 100644 --- a/src/screens/TraktSettingsScreen.tsx +++ b/src/screens/TraktSettingsScreen.tsx @@ -401,57 +401,7 @@ const TraktSettingsScreen: React.FC = () => { )} - { - await traktService.debugPlaybackProgress(); - Alert.alert( - 'Debug Complete', - 'Check the app logs for current Trakt playback progress. Look for lines starting with "[TraktService] DEBUG".', - [{ text: 'OK' }] - ); - }} - > - - Debug Trakt Progress - - - { - const result = await traktService.debugTraktConnection(); - Alert.alert( - 'Connection Test', - result.authenticated - ? `Connection successful! User: ${result.user?.username || 'Unknown'}` - : `Connection failed: ${result.error}`, - [{ text: 'OK' }] - ); - }} - > - - Test API Connection - - )}