mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-05-22 06:17:29 +08:00
fix: potentially ref problem
This commit is contained in:
@@ -74,6 +74,7 @@ function PlayPageClient() {
|
|||||||
const currentSourceRef = useRef(currentSource);
|
const currentSourceRef = useRef(currentSource);
|
||||||
const currentIdRef = useRef(currentId);
|
const currentIdRef = useRef(currentId);
|
||||||
const videoTitleRef = useRef(videoTitle);
|
const videoTitleRef = useRef(videoTitle);
|
||||||
|
const videoYearRef = useRef(videoYear);
|
||||||
const detailRef = useRef<VideoDetail | null>(detail);
|
const detailRef = useRef<VideoDetail | null>(detail);
|
||||||
const currentEpisodeIndexRef = useRef(currentEpisodeIndex);
|
const currentEpisodeIndexRef = useRef(currentEpisodeIndex);
|
||||||
|
|
||||||
@@ -84,7 +85,15 @@ function PlayPageClient() {
|
|||||||
detailRef.current = detail;
|
detailRef.current = detail;
|
||||||
currentEpisodeIndexRef.current = currentEpisodeIndex;
|
currentEpisodeIndexRef.current = currentEpisodeIndex;
|
||||||
videoTitleRef.current = videoTitle;
|
videoTitleRef.current = videoTitle;
|
||||||
}, [currentSource, currentId, detail, currentEpisodeIndex, videoTitle]);
|
videoYearRef.current = videoYear;
|
||||||
|
}, [
|
||||||
|
currentSource,
|
||||||
|
currentId,
|
||||||
|
detail,
|
||||||
|
currentEpisodeIndex,
|
||||||
|
videoTitle,
|
||||||
|
videoYear,
|
||||||
|
]);
|
||||||
|
|
||||||
// 视频播放地址
|
// 视频播放地址
|
||||||
const [videoUrl, setVideoUrl] = useState('');
|
const [videoUrl, setVideoUrl] = useState('');
|
||||||
@@ -276,12 +285,12 @@ function PlayPageClient() {
|
|||||||
const detailData = await fetchVideoDetail({
|
const detailData = await fetchVideoDetail({
|
||||||
source: currentSource,
|
source: currentSource,
|
||||||
id: currentId,
|
id: currentId,
|
||||||
fallbackTitle: videoTitle.trim(),
|
fallbackTitle: videoTitleRef.current.trim(),
|
||||||
fallbackYear: videoYear,
|
fallbackYear: videoYearRef.current,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 更新状态保存详情
|
// 更新状态保存详情
|
||||||
setVideoTitle(detailData.title || videoTitle);
|
setVideoTitle(detailData.title || videoTitleRef.current);
|
||||||
setVideoCover(detailData.poster);
|
setVideoCover(detailData.poster);
|
||||||
setDetail(detailData);
|
setDetail(detailData);
|
||||||
|
|
||||||
@@ -421,14 +430,16 @@ function PlayPageClient() {
|
|||||||
// 只选择和当前视频标题完全匹配的结果,如果有年份,还需要年份完全匹配
|
// 只选择和当前视频标题完全匹配的结果,如果有年份,还需要年份完全匹配
|
||||||
const exactMatchs = results.filter(
|
const exactMatchs = results.filter(
|
||||||
(result) =>
|
(result) =>
|
||||||
result.title.toLowerCase() === videoTitle.toLowerCase() &&
|
result.title.toLowerCase() ===
|
||||||
(videoYear
|
videoTitleRef.current.toLowerCase() &&
|
||||||
? result.year.toLowerCase() === videoYear.toLowerCase()
|
(videoYearRef.current
|
||||||
|
? result.year.toLowerCase() === videoYearRef.current.toLowerCase()
|
||||||
: true) &&
|
: true) &&
|
||||||
(detail
|
(detailRef.current
|
||||||
? (detail.episodes.length === 1 &&
|
? (detailRef.current.episodes.length === 1 &&
|
||||||
result.episodes.length === 1) ||
|
result.episodes.length === 1) ||
|
||||||
(detail.episodes.length > 1 && result.episodes.length > 1)
|
(detailRef.current.episodes.length > 1 &&
|
||||||
|
result.episodes.length > 1)
|
||||||
: true)
|
: true)
|
||||||
);
|
);
|
||||||
if (exactMatchs.length > 0) {
|
if (exactMatchs.length > 0) {
|
||||||
@@ -462,9 +473,12 @@ function PlayPageClient() {
|
|||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
// 清除前一个历史记录
|
// 清除前一个历史记录
|
||||||
if (currentSource && currentId) {
|
if (currentSourceRef.current && currentIdRef.current) {
|
||||||
try {
|
try {
|
||||||
await deletePlayRecord(currentSource, currentId);
|
await deletePlayRecord(
|
||||||
|
currentSourceRef.current,
|
||||||
|
currentIdRef.current
|
||||||
|
);
|
||||||
console.log('已清除前一个播放记录');
|
console.log('已清除前一个播放记录');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('清除播放记录失败:', err);
|
console.error('清除播放记录失败:', err);
|
||||||
@@ -476,7 +490,7 @@ function PlayPageClient() {
|
|||||||
source: newSource,
|
source: newSource,
|
||||||
id: newId,
|
id: newId,
|
||||||
fallbackTitle: newTitle.trim(),
|
fallbackTitle: newTitle.trim(),
|
||||||
fallbackYear: videoYear,
|
fallbackYear: videoYearRef.current,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 尝试跳转到当前正在播放的集数
|
// 尝试跳转到当前正在播放的集数
|
||||||
|
|||||||
Reference in New Issue
Block a user