Enhance useMetadata hook and MetadataScreen to include imdbId state; update RatingsSection to utilize imdbId for improved compatibility and functionality.

This commit is contained in:
Nayif Noushad 2025-04-20 11:59:14 +05:30
parent 2dfb8da36c
commit 221d5de368
2 changed files with 12 additions and 2 deletions

View file

@ -86,6 +86,7 @@ interface UseMetadataReturn {
recommendations: StreamingContent[]; recommendations: StreamingContent[];
loadingRecommendations: boolean; loadingRecommendations: boolean;
setMetadata: React.Dispatch<React.SetStateAction<StreamingContent | null>>; setMetadata: React.Dispatch<React.SetStateAction<StreamingContent | null>>;
imdbId: string | null;
} }
export const useMetadata = ({ id, type }: UseMetadataProps): UseMetadataReturn => { export const useMetadata = ({ id, type }: UseMetadataProps): UseMetadataReturn => {
@ -110,6 +111,7 @@ export const useMetadata = ({ id, type }: UseMetadataProps): UseMetadataReturn =
const [loadAttempts, setLoadAttempts] = useState(0); const [loadAttempts, setLoadAttempts] = useState(0);
const [recommendations, setRecommendations] = useState<StreamingContent[]>([]); const [recommendations, setRecommendations] = useState<StreamingContent[]>([]);
const [loadingRecommendations, setLoadingRecommendations] = useState(false); const [loadingRecommendations, setLoadingRecommendations] = useState(false);
const [imdbId, setImdbId] = useState<string | null>(null);
const processStremioSource = async (type: string, id: string, isEpisode = false) => { const processStremioSource = async (type: string, id: string, isEpisode = false) => {
const sourceStartTime = Date.now(); const sourceStartTime = Date.now();
@ -316,6 +318,7 @@ export const useMetadata = ({ id, type }: UseMetadataProps): UseMetadataReturn =
if (imdbId) { if (imdbId) {
// Use the imdbId for compatibility with the rest of the app // Use the imdbId for compatibility with the rest of the app
actualId = imdbId; actualId = imdbId;
setImdbId(imdbId);
// Also store the TMDB ID for later use // Also store the TMDB ID for later use
setTmdbId(parseInt(tmdbId)); setTmdbId(parseInt(tmdbId));
} else { } else {
@ -394,6 +397,7 @@ export const useMetadata = ({ id, type }: UseMetadataProps): UseMetadataReturn =
if (imdbId) { if (imdbId) {
// Use the imdbId for compatibility with the rest of the app // Use the imdbId for compatibility with the rest of the app
actualId = imdbId; actualId = imdbId;
setImdbId(imdbId);
// Also store the TMDB ID for later use // Also store the TMDB ID for later use
setTmdbId(parseInt(tmdbId)); setTmdbId(parseInt(tmdbId));
} else { } else {
@ -471,6 +475,10 @@ export const useMetadata = ({ id, type }: UseMetadataProps): UseMetadataReturn =
catalogService.getContentDetails(type, actualId), catalogService.getContentDetails(type, actualId),
API_TIMEOUT API_TIMEOUT
); );
// Store the actual ID used (could be IMDB)
if (actualId.startsWith('tt')) {
setImdbId(actualId);
}
return result; return result;
}), }),
// Start loading cast immediately in parallel // Start loading cast immediately in parallel
@ -1096,5 +1104,6 @@ export const useMetadata = ({ id, type }: UseMetadataProps): UseMetadataReturn =
recommendations, recommendations,
loadingRecommendations, loadingRecommendations,
setMetadata, setMetadata,
imdbId,
}; };
}; };

View file

@ -214,6 +214,7 @@ const MetadataScreen = () => {
recommendations, recommendations,
loadingRecommendations, loadingRecommendations,
setMetadata, setMetadata,
imdbId,
} = useMetadata({ id, type }); } = useMetadata({ id, type });
// Get genres from context // Get genres from context
@ -984,9 +985,9 @@ const MetadataScreen = () => {
</View> </View>
{/* Add RatingsSection right under the main metadata */} {/* Add RatingsSection right under the main metadata */}
{id && ( {imdbId && (
<RatingsSection <RatingsSection
imdbId={id} imdbId={imdbId}
type={type === 'series' ? 'show' : 'movie'} type={type === 'series' ? 'show' : 'movie'}
/> />
)} )}