fix: searchXrel via detailRef statt detail-State, Cache-Load mit Titeln nach TMDb-Response
This commit is contained in:
@@ -462,33 +462,47 @@ function MovieModal({ tmdbId, onClose, mobile, onHasXrel }) {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
// detail als Ref damit searchXrel immer den aktuellen Wert hat
|
||||
const detailRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true); setDetail(null); setXrel(null); setError('');
|
||||
detailRef.current = null;
|
||||
api(`/tools/media/movie/${tmdbId}`)
|
||||
.then(d => { setDetail(d); setLoading(false); })
|
||||
.catch(e => { setError(e.message); setLoading(false); });
|
||||
// Gecachte Releases laden – ohne refresh, nur befüllte Einträge
|
||||
api(`/tools/media/movie/${tmdbId}/xrel`)
|
||||
.then(d => { if (d.xrel?.length > 0) { setXrel(d.xrel); onHasXrel?.(tmdbId); } })
|
||||
.then(d => {
|
||||
setDetail(d);
|
||||
detailRef.current = d;
|
||||
setLoading(false);
|
||||
// Gecachte Releases laden sobald wir den Titel kennen
|
||||
const params = new URLSearchParams({
|
||||
title: d.title || '',
|
||||
orig: d.original_title || '',
|
||||
imdb_id: d.imdb_id || '',
|
||||
});
|
||||
api(`/tools/media/movie/${tmdbId}/xrel?${params}`)
|
||||
.then(r => { if (r.xrel?.length > 0) { setXrel(r.xrel); onHasXrel?.(tmdbId); } })
|
||||
.catch(() => {});
|
||||
})
|
||||
.catch(e => { setError(e.message); setLoading(false); });
|
||||
const prev = document.body.style.overflow;
|
||||
document.body.style.overflow = 'hidden';
|
||||
return () => { document.body.style.overflow = prev; };
|
||||
}, [tmdbId]);
|
||||
|
||||
const searchXrel = async (forceRefresh = false) => {
|
||||
if (!detail) return;
|
||||
const d = detailRef.current;
|
||||
if (!d) return;
|
||||
setXrelLoading(true);
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
title: detail.title || '',
|
||||
orig: detail.original_title || '',
|
||||
imdb_id: detail.imdb_id || '',
|
||||
title: d.title || '',
|
||||
orig: d.original_title || '',
|
||||
imdb_id: d.imdb_id || '',
|
||||
});
|
||||
if (forceRefresh) params.set('refresh', '1');
|
||||
const d = await api(`/tools/media/movie/${tmdbId}/xrel?${params}`);
|
||||
setXrel(d.xrel || []);
|
||||
if (d.has_xrel) onHasXrel?.(tmdbId);
|
||||
const r = await api(`/tools/media/movie/${tmdbId}/xrel?${params}`);
|
||||
setXrel(r.xrel || []);
|
||||
if (r.has_xrel) onHasXrel?.(tmdbId);
|
||||
} catch(_) { setXrel([]); }
|
||||
finally { setXrelLoading(false); }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user