LEGACY hero carousal init

This commit is contained in:
tapframe 2025-11-05 13:33:12 +05:30
parent 5fe1db24c1
commit b17b492741
5 changed files with 683 additions and 529 deletions

13
package-lock.json generated
View file

@ -77,6 +77,7 @@
"react-native-nitro-modules": "^0.31.2",
"react-native-paper": "^5.14.5",
"react-native-reanimated": "^4.1.1",
"react-native-reanimated-carousel": "^4.0.3",
"react-native-safe-area-context": "~5.6.0",
"react-native-screens": "~4.16.0",
"react-native-svg": "15.12.1",
@ -10902,6 +10903,18 @@
"react-native-worklets": ">=0.5.0"
}
},
"node_modules/react-native-reanimated-carousel": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/react-native-reanimated-carousel/-/react-native-reanimated-carousel-4.0.3.tgz",
"integrity": "sha512-YZXlvZNghR5shFcI9hTA7h7bEhh97pfUSLZvLBAshpbkuYwJDKmQXejO/199T6hqGq0wCRwR0CWf2P4Vs6A4Fw==",
"license": "MIT",
"peerDependencies": {
"react": ">=18.0.0",
"react-native": ">=0.70.3",
"react-native-gesture-handler": ">=2.9.0",
"react-native-reanimated": ">=3.0.0"
}
},
"node_modules/react-native-reanimated/node_modules/semver": {
"version": "7.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz",

View file

@ -77,6 +77,7 @@
"react-native-nitro-modules": "^0.31.2",
"react-native-paper": "^5.14.5",
"react-native-reanimated": "^4.1.1",
"react-native-reanimated-carousel": "^4.0.3",
"react-native-safe-area-context": "~5.6.0",
"react-native-screens": "~4.16.0",
"react-native-svg": "15.12.1",

File diff suppressed because it is too large Load diff

View file

@ -475,35 +475,62 @@ export function useFeaturedContent() {
return () => cleanup();
}, [cleanup]);
const handleSaveToLibrary = useCallback(async () => {
if (!featuredContent) return;
try {
const currentSavedStatus = isSaved;
setIsSaved(!currentSavedStatus);
await Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
const handleSaveToLibrary = useCallback(async (item?: StreamingContent) => {
const contentToUse = item || featuredContent;
if (!contentToUse) return;
if (currentSavedStatus) {
await catalogService.removeFromLibrary(featuredContent.type, featuredContent.id);
try {
// For the legacy single item behavior
if (!item) {
const currentSavedStatus = isSaved;
setIsSaved(!currentSavedStatus);
await Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
if (currentSavedStatus) {
await catalogService.removeFromLibrary(contentToUse.type, contentToUse.id);
} else {
const itemToAdd = { ...contentToUse, inLibrary: true };
await catalogService.addToLibrary(itemToAdd);
}
} else {
const itemToAdd = { ...featuredContent, inLibrary: true };
await catalogService.addToLibrary(itemToAdd);
// For carousel items - check if saved and toggle
const isItemSaved = await catalogService.isInLibrary(contentToUse.type, contentToUse.id);
await Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
if (isItemSaved) {
await catalogService.removeFromLibrary(contentToUse.type, contentToUse.id);
} else {
const itemToAdd = { ...contentToUse, inLibrary: true };
await catalogService.addToLibrary(itemToAdd);
}
}
} catch (error) {
logger.error('Error updating library:', error);
setIsSaved(prev => !prev);
if (!item) {
setIsSaved(prev => !prev);
}
}
}, [featuredContent, isSaved]);
const isItemSaved = useCallback(async (item: StreamingContent) => {
try {
return await catalogService.isInLibrary(item.type, item.id);
} catch (error) {
logger.error('Error checking if item is saved:', error);
return false;
}
}, []);
// Function to force a refresh if needed
const refreshFeatured = useCallback(() => loadFeaturedContent(true), [loadFeaturedContent]);
return {
featuredContent,
return {
featuredContent,
allFeaturedContent,
loading,
isSaved,
handleSaveToLibrary,
loading,
isSaved,
handleSaveToLibrary,
isItemSaved,
refreshFeatured
};
}

View file

@ -142,13 +142,14 @@ const HomeScreen = () => {
return () => clearTimeout(timer);
}, [insets.top]);
const {
featuredContent,
const {
featuredContent,
allFeaturedContent,
loading: featuredLoading,
isSaved,
handleSaveToLibrary,
refreshFeatured
loading: featuredLoading,
isSaved,
handleSaveToLibrary,
isItemSaved,
refreshFeatured
} = useFeaturedContent();
// Progressive catalog loading function with performance optimizations
@ -635,13 +636,13 @@ const HomeScreen = () => {
/>
) : (
<FeaturedContent
featuredContent={featuredContent}
isSaved={isSaved}
featuredContent={allFeaturedContent || (featuredContent ? [featuredContent] : [])}
isSaved={isItemSaved}
handleSaveToLibrary={handleSaveToLibrary}
loading={featuredLoading}
/>
);
}, [isTablet, settings.heroStyle, showHeroSection, featuredContentSource, allFeaturedContent, featuredContent, isSaved, handleSaveToLibrary, featuredLoading]);
}, [isTablet, settings.heroStyle, showHeroSection, featuredContentSource, allFeaturedContent, featuredContent, isItemSaved, handleSaveToLibrary, featuredLoading]);
const memoizedThisWeekSection = useMemo(() => <ThisWeekSection />, []);
const memoizedContinueWatchingSection = useMemo(() => <ContinueWatchingSection ref={continueWatchingRef} />, []);