mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-01-11 20:10:25 +00:00
small cahnges
This commit is contained in:
parent
de6c74bee9
commit
f76df498f2
4 changed files with 32 additions and 6 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
||||
import React, { createContext, useContext, useEffect, useMemo, useState, useRef } from 'react';
|
||||
import { InteractionManager } from 'react-native';
|
||||
import accountService, { AuthUser } from '../services/AccountService';
|
||||
import supabase from '../services/supabaseClient';
|
||||
|
|
@ -19,6 +19,7 @@ const AccountContext = createContext<AccountContextValue | undefined>(undefined)
|
|||
export const AccountProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const [user, setUser] = useState<AuthUser | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const loadingTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
// Initial session (load full profile)
|
||||
|
|
@ -69,6 +70,10 @@ export const AccountProvider: React.FC<{ children: React.ReactNode }> = ({ child
|
|||
return () => {
|
||||
subscription.subscription.unsubscribe();
|
||||
task.cancel();
|
||||
if (loadingTimeoutRef.current) {
|
||||
clearTimeout(loadingTimeoutRef.current);
|
||||
loadingTimeoutRef.current = null;
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
|
@ -88,11 +93,27 @@ export const AccountProvider: React.FC<{ children: React.ReactNode }> = ({ child
|
|||
setUser(null);
|
||||
},
|
||||
refreshCurrentUser: async () => {
|
||||
// Don't set loading if already loading to avoid conflicts
|
||||
if (loading) return;
|
||||
|
||||
setLoading(true);
|
||||
|
||||
// Set a timeout to prevent loading from getting stuck
|
||||
loadingTimeoutRef.current = setTimeout(() => {
|
||||
console.warn('Account loading timeout, forcing loading to false');
|
||||
setLoading(false);
|
||||
}, 10000); // 10 second timeout
|
||||
|
||||
try {
|
||||
const u = await accountService.getCurrentUser();
|
||||
setUser(u);
|
||||
} catch (error) {
|
||||
console.error('Failed to refresh current user:', error);
|
||||
} finally {
|
||||
if (loadingTimeoutRef.current) {
|
||||
clearTimeout(loadingTimeoutRef.current);
|
||||
loadingTimeoutRef.current = null;
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ export const CatalogProvider: React.FC<{ children: React.ReactNode }> = ({ child
|
|||
|
||||
const refreshCatalogs = useCallback(() => {
|
||||
setLastUpdate(Date.now());
|
||||
logger.info('Refreshing catalogs, timestamp:', Date.now());
|
||||
}, []);
|
||||
|
||||
// Listen for addon changes to update catalog data
|
||||
|
|
|
|||
|
|
@ -377,7 +377,11 @@ const CatalogSettingsScreen = () => {
|
|||
settingsObj[key] = setting.enabled;
|
||||
});
|
||||
await AsyncStorage.setItem(CATALOG_SETTINGS_KEY, JSON.stringify(settingsObj));
|
||||
refreshCatalogs(); // Trigger catalog refresh after saving settings
|
||||
|
||||
// Small delay to ensure AsyncStorage has fully persisted before triggering refresh
|
||||
setTimeout(() => {
|
||||
refreshCatalogs(); // Trigger catalog refresh after saving settings
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
logger.error('Failed to save catalog enabled settings:', error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -261,12 +261,14 @@ const SettingsScreen: React.FC = () => {
|
|||
if (__DEV__) console.log('SettingsScreen focused, refreshing auth status. Current state:', { isAuthenticated, userProfile: userProfile?.username });
|
||||
}
|
||||
refreshAuthStatus();
|
||||
// Also refresh account user in case we returned from auth flow
|
||||
refreshCurrentUser();
|
||||
// Only refresh account user if we don't have a user or if we're not already loading
|
||||
if (!user && !accountLoading) {
|
||||
refreshCurrentUser();
|
||||
}
|
||||
});
|
||||
|
||||
return unsubscribe;
|
||||
}, [navigation, isAuthenticated, userProfile, refreshAuthStatus, refreshCurrentUser]);
|
||||
}, [navigation, isAuthenticated, userProfile, refreshAuthStatus, refreshCurrentUser, user, accountLoading]);
|
||||
|
||||
// States for dynamic content
|
||||
const [addonCount, setAddonCount] = useState<number>(0);
|
||||
|
|
|
|||
Loading…
Reference in a new issue