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 [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
|
// detail als Ref damit searchXrel immer den aktuellen Wert hat
|
||||||
|
const detailRef = useRef(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLoading(true); setDetail(null); setXrel(null); setError('');
|
setLoading(true); setDetail(null); setXrel(null); setError('');
|
||||||
|
detailRef.current = null;
|
||||||
api(`/tools/media/movie/${tmdbId}`)
|
api(`/tools/media/movie/${tmdbId}`)
|
||||||
.then(d => { setDetail(d); setLoading(false); })
|
.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); });
|
.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); } })
|
|
||||||
.catch(() => {});
|
|
||||||
const prev = document.body.style.overflow;
|
const prev = document.body.style.overflow;
|
||||||
document.body.style.overflow = 'hidden';
|
document.body.style.overflow = 'hidden';
|
||||||
return () => { document.body.style.overflow = prev; };
|
return () => { document.body.style.overflow = prev; };
|
||||||
}, [tmdbId]);
|
}, [tmdbId]);
|
||||||
|
|
||||||
const searchXrel = async (forceRefresh = false) => {
|
const searchXrel = async (forceRefresh = false) => {
|
||||||
if (!detail) return;
|
const d = detailRef.current;
|
||||||
|
if (!d) return;
|
||||||
setXrelLoading(true);
|
setXrelLoading(true);
|
||||||
try {
|
try {
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
title: detail.title || '',
|
title: d.title || '',
|
||||||
orig: detail.original_title || '',
|
orig: d.original_title || '',
|
||||||
imdb_id: detail.imdb_id || '',
|
imdb_id: d.imdb_id || '',
|
||||||
});
|
});
|
||||||
if (forceRefresh) params.set('refresh', '1');
|
if (forceRefresh) params.set('refresh', '1');
|
||||||
const d = await api(`/tools/media/movie/${tmdbId}/xrel?${params}`);
|
const r = await api(`/tools/media/movie/${tmdbId}/xrel?${params}`);
|
||||||
setXrel(d.xrel || []);
|
setXrel(r.xrel || []);
|
||||||
if (d.has_xrel) onHasXrel?.(tmdbId);
|
if (r.has_xrel) onHasXrel?.(tmdbId);
|
||||||
} catch(_) { setXrel([]); }
|
} catch(_) { setXrel([]); }
|
||||||
finally { setXrelLoading(false); }
|
finally { setXrelLoading(false); }
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user