diff --git a/src/components/home/ThisWeekSection.tsx b/src/components/home/ThisWeekSection.tsx index 30ebfe4c..d83f5cf1 100644 --- a/src/components/home/ThisWeekSection.tsx +++ b/src/components/home/ThisWeekSection.tsx @@ -20,7 +20,6 @@ import { useLibrary } from '../../hooks/useLibrary'; import { RootStackParamList } from '../../navigation/AppNavigator'; import { parseISO, isThisWeek, format, isAfter, isBefore } from 'date-fns'; import Animated, { FadeIn, FadeInRight } from 'react-native-reanimated'; -import { catalogService } from '../../services/catalogService'; const { width } = Dimensions.get('window'); const ITEM_WIDTH = width * 0.85; @@ -128,22 +127,13 @@ export const ThisWeekSection = () => { } }, [libraryItems]); - // Subscribe to library updates - useEffect(() => { - const unsubscribe = catalogService.subscribeToLibraryUpdates(() => { - console.log('[ThisWeekSection] Library updated, refreshing episodes'); - fetchThisWeekEpisodes(); - }); - - return () => unsubscribe(); - }, [fetchThisWeekEpisodes]); - - // Initial load + // Load episodes when library items change useEffect(() => { if (!libraryLoading) { + console.log('[ThisWeekSection] Library items changed, refreshing episodes. Items count:', libraryItems.length); fetchThisWeekEpisodes(); } - }, [libraryLoading, fetchThisWeekEpisodes]); + }, [libraryLoading, libraryItems, fetchThisWeekEpisodes]); const handleEpisodePress = (episode: ThisWeekEpisode) => { // For upcoming episodes, go to the metadata screen diff --git a/src/hooks/useLibrary.ts b/src/hooks/useLibrary.ts index 0f8e656e..51643591 100644 --- a/src/hooks/useLibrary.ts +++ b/src/hooks/useLibrary.ts @@ -1,6 +1,7 @@ import { useState, useEffect, useCallback } from 'react'; import AsyncStorage from '@react-native-async-storage/async-storage'; import { StreamingContent } from '../types/metadata'; +import { catalogService } from '../services/catalogService'; const LIBRARY_STORAGE_KEY = 'stremio-library'; @@ -83,6 +84,17 @@ export const useLibrary = () => { loadLibraryItems(); }, [loadLibraryItems]); + // Subscribe to catalogService library updates + useEffect(() => { + const unsubscribe = catalogService.subscribeToLibraryUpdates((items) => { + console.log('[useLibrary] Received library update from catalogService:', items.length, 'items'); + setLibraryItems(items); + setLoading(false); + }); + + return () => unsubscribe(); + }, []); + return { libraryItems, loading,