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.
This commit is contained in:
tapframe 2025-06-20 02:24:27 +05:30
parent 00491c83e5
commit d3061bf83f
2 changed files with 10 additions and 54 deletions

View file

@ -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;

View file

@ -401,57 +401,7 @@ const TraktSettingsScreen: React.FC = () => {
)}
</TouchableOpacity>
<TouchableOpacity
style={[
styles.button,
{
backgroundColor: isDarkMode ? '#FF6B35' + '40' : '#FF6B35' + '20',
marginTop: 8
}
]}
onPress={async () => {
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' }]
);
}}
>
<Text style={[
styles.buttonText,
{ color: '#FF6B35' }
]}>
Debug Trakt Progress
</Text>
</TouchableOpacity>
<TouchableOpacity
style={[
styles.button,
{
backgroundColor: isDarkMode ? '#9B59B6' + '40' : '#9B59B6' + '20',
marginTop: 8
}
]}
onPress={async () => {
const result = await traktService.debugTraktConnection();
Alert.alert(
'Connection Test',
result.authenticated
? `Connection successful! User: ${result.user?.username || 'Unknown'}`
: `Connection failed: ${result.error}`,
[{ text: 'OK' }]
);
}}
>
<Text style={[
styles.buttonText,
{ color: '#9B59B6' }
]}>
Test API Connection
</Text>
</TouchableOpacity>
</View>
</View>
)}