catalogscreen optimziation

This commit is contained in:
tapframe 2025-09-21 16:39:08 +05:30
parent c1503f0614
commit 0b3a36c76f

View file

@ -10,6 +10,7 @@ import {
RefreshControl, RefreshControl,
Dimensions, Dimensions,
Platform, Platform,
InteractionManager
} from 'react-native'; } from 'react-native';
import { FlashList } from '@shopify/flash-list'; import { FlashList } from '@shopify/flash-list';
import { RouteProp } from '@react-navigation/native'; import { RouteProp } from '@react-navigation/native';
@ -226,6 +227,7 @@ const CatalogScreen: React.FC<CatalogScreenProps> = ({ route, navigation }) => {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false); const [refreshing, setRefreshing] = useState(false);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [hasMore, setHasMore] = useState(false);
const [dataSource, setDataSource] = useState<DataSource>(DataSource.STREMIO_ADDONS); const [dataSource, setDataSource] = useState<DataSource>(DataSource.STREMIO_ADDONS);
const [actualCatalogName, setActualCatalogName] = useState<string | null>(null); const [actualCatalogName, setActualCatalogName] = useState<string | null>(null);
const [screenData, setScreenData] = useState(() => { const [screenData, setScreenData] = useState(() => {
@ -403,24 +405,30 @@ const CatalogScreen: React.FC<CatalogScreenProps> = ({ route, navigation }) => {
index === self.findIndex((t) => t.id === item.id) index === self.findIndex((t) => t.id === item.id)
); );
setItems(uniqueItems); InteractionManager.runAfterInteractions(() => {
setHasMore(false); // TMDB already returns a full set setItems(uniqueItems);
setLoading(false); setHasMore(false); // TMDB already returns a full set
setRefreshing(false); setLoading(false);
setRefreshing(false);
});
return; return;
} else { } else {
setError("No content found for the selected filters"); InteractionManager.runAfterInteractions(() => {
setItems([]); setError("No content found for the selected filters");
setLoading(false); setItems([]);
setRefreshing(false); setLoading(false);
setRefreshing(false);
});
return; return;
} }
} catch (error) { } catch (error) {
logger.error('Failed to get TMDB catalog:', error); logger.error('Failed to get TMDB catalog:', error);
setError('Failed to load content from TMDB'); InteractionManager.runAfterInteractions(() => {
setItems([]); setError('Failed to load content from TMDB');
setLoading(false); setItems([]);
setRefreshing(false); setLoading(false);
setRefreshing(false);
});
return; return;
} }
} }
@ -448,7 +456,9 @@ const CatalogScreen: React.FC<CatalogScreenProps> = ({ route, navigation }) => {
if (catalogItems.length > 0) { if (catalogItems.length > 0) {
foundItems = true; foundItems = true;
setItems(catalogItems); InteractionManager.runAfterInteractions(() => {
setItems(catalogItems);
});
} }
} else if (effectiveGenreFilter) { } else if (effectiveGenreFilter) {
// Get all addons that have catalogs of the specified type // Get all addons that have catalogs of the specified type
@ -527,19 +537,27 @@ const CatalogScreen: React.FC<CatalogScreenProps> = ({ route, navigation }) => {
if (uniqueItems.length > 0) { if (uniqueItems.length > 0) {
foundItems = true; foundItems = true;
setItems(uniqueItems); InteractionManager.runAfterInteractions(() => {
setItems(uniqueItems);
});
} }
} }
if (!foundItems) { if (!foundItems) {
setError("No content found for the selected filters"); InteractionManager.runAfterInteractions(() => {
setError("No content found for the selected filters");
});
} }
} catch (err) { } catch (err) {
setError(err instanceof Error ? err.message : 'Failed to load catalog items'); InteractionManager.runAfterInteractions(() => {
setError(err instanceof Error ? err.message : 'Failed to load catalog items');
});
logger.error('Failed to load catalog:', err); logger.error('Failed to load catalog:', err);
} finally { } finally {
setLoading(false); InteractionManager.runAfterInteractions(() => {
setRefreshing(false); setLoading(false);
setRefreshing(false);
});
} }
}, [addonId, type, id, genreFilter, dataSource]); }, [addonId, type, id, genreFilter, dataSource]);
@ -651,7 +669,7 @@ const CatalogScreen: React.FC<CatalogScreenProps> = ({ route, navigation }) => {
</Text> </Text>
<TouchableOpacity <TouchableOpacity
style={styles.button} style={styles.button}
onPress={() => loadItems(1)} onPress={() => loadItems(true)}
> >
<Text style={styles.buttonText}>Retry</Text> <Text style={styles.buttonText}>Retry</Text>
</TouchableOpacity> </TouchableOpacity>
@ -736,7 +754,6 @@ const CatalogScreen: React.FC<CatalogScreenProps> = ({ route, navigation }) => {
} }
contentContainerStyle={styles.list} contentContainerStyle={styles.list}
showsVerticalScrollIndicator={false} showsVerticalScrollIndicator={false}
estimatedItemSize={effectiveItemWidth * 1.5 + SPACING.lg}
/> />
) : renderEmptyState()} ) : renderEmptyState()}
</SafeAreaView> </SafeAreaView>