mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-03 16:59:08 +00:00
render loop fix usewatchprogress
This commit is contained in:
parent
dbbee06a55
commit
2e61617f83
1 changed files with 10 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { useState, useCallback, useEffect } from 'react';
|
import { useState, useCallback, useEffect, useRef } from 'react';
|
||||||
import { useFocusEffect } from '@react-navigation/native';
|
import { useFocusEffect } from '@react-navigation/native';
|
||||||
import { useTraktContext } from '../contexts/TraktContext';
|
import { useTraktContext } from '../contexts/TraktContext';
|
||||||
import { logger } from '../utils/logger';
|
import { logger } from '../utils/logger';
|
||||||
|
|
@ -22,14 +22,19 @@ export const useWatchProgress = (
|
||||||
const [watchProgress, setWatchProgress] = useState<WatchProgressData | null>(null);
|
const [watchProgress, setWatchProgress] = useState<WatchProgressData | null>(null);
|
||||||
const { isAuthenticated: isTraktAuthenticated } = useTraktContext();
|
const { isAuthenticated: isTraktAuthenticated } = useTraktContext();
|
||||||
|
|
||||||
|
// Use ref for episodes to avoid infinite loops - episodes array changes on every render
|
||||||
|
const episodesRef = useRef(episodes);
|
||||||
|
episodesRef.current = episodes;
|
||||||
|
|
||||||
// Function to get episode details from episodeId
|
// Function to get episode details from episodeId
|
||||||
const getEpisodeDetails = useCallback((episodeId: string): { seasonNumber: string; episodeNumber: string; episodeName: string } | null => {
|
const getEpisodeDetails = useCallback((episodeId: string): { seasonNumber: string; episodeNumber: string; episodeName: string } | null => {
|
||||||
|
const currentEpisodes = episodesRef.current;
|
||||||
// Try to parse from format "seriesId:season:episode"
|
// Try to parse from format "seriesId:season:episode"
|
||||||
const parts = episodeId.split(':');
|
const parts = episodeId.split(':');
|
||||||
if (parts.length === 3) {
|
if (parts.length === 3) {
|
||||||
const [, seasonNum, episodeNum] = parts;
|
const [, seasonNum, episodeNum] = parts;
|
||||||
// Find episode in our local episodes array
|
// Find episode in our local episodes array
|
||||||
const episode = episodes.find(
|
const episode = currentEpisodes.find(
|
||||||
ep => ep.season_number === parseInt(seasonNum) &&
|
ep => ep.season_number === parseInt(seasonNum) &&
|
||||||
ep.episode_number === parseInt(episodeNum)
|
ep.episode_number === parseInt(episodeNum)
|
||||||
);
|
);
|
||||||
|
|
@ -44,7 +49,7 @@ export const useWatchProgress = (
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not found by season/episode, try stremioId
|
// If not found by season/episode, try stremioId
|
||||||
const episodeByStremioId = episodes.find(ep => ep.stremioId === episodeId);
|
const episodeByStremioId = currentEpisodes.find(ep => ep.stremioId === episodeId);
|
||||||
if (episodeByStremioId) {
|
if (episodeByStremioId) {
|
||||||
return {
|
return {
|
||||||
seasonNumber: episodeByStremioId.season_number.toString(),
|
seasonNumber: episodeByStremioId.season_number.toString(),
|
||||||
|
|
@ -54,7 +59,7 @@ export const useWatchProgress = (
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}, [episodes]);
|
}, []); // Removed episodes dependency - using ref instead
|
||||||
|
|
||||||
// Enhanced load watch progress with Trakt integration
|
// Enhanced load watch progress with Trakt integration
|
||||||
const loadWatchProgress = useCallback(async () => {
|
const loadWatchProgress = useCallback(async () => {
|
||||||
|
|
@ -148,7 +153,7 @@ export const useWatchProgress = (
|
||||||
logger.error('[useWatchProgress] Error loading watch progress:', error);
|
logger.error('[useWatchProgress] Error loading watch progress:', error);
|
||||||
setWatchProgress(null);
|
setWatchProgress(null);
|
||||||
}
|
}
|
||||||
}, [id, type, episodeId, episodes]);
|
}, [id, type, episodeId]); // Removed episodes dependency - using ref instead
|
||||||
|
|
||||||
// Enhanced function to get play button text with Trakt awareness
|
// Enhanced function to get play button text with Trakt awareness
|
||||||
const getPlayButtonText = useCallback(() => {
|
const getPlayButtonText = useCallback(() => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue