fixed: 页面销毁后没有停止refresh
This commit is contained in:
parent
c7d964965d
commit
fae2e9c4ae
@ -2,7 +2,7 @@ import {Checkbox, Empty, Space} from "antd";
|
||||
import React, {useEffect, useMemo, useRef, useState} from "react";
|
||||
import {DndContext} from "@dnd-kit/core";
|
||||
import {arrayMove, SortableContext} from "@dnd-kit/sortable";
|
||||
import {useSetState} from "ahooks";
|
||||
import {useSetState, useTimeout} from "ahooks";
|
||||
|
||||
import {VideoListItem} from "@/components/video/video-list-item.tsx";
|
||||
import ArticleEditModal from "@/components/article/edit-modal.tsx";
|
||||
@ -35,9 +35,15 @@ export default function VideoIndex() {
|
||||
loading:false
|
||||
})
|
||||
const [checkedIdArray, setCheckedIdArray] = useState<Id[]>([])
|
||||
const [refreshTimer,setTimer] = useState(0)
|
||||
|
||||
// 加载列表
|
||||
const loadList = (needReset = true) => {
|
||||
if(state.loading) return;
|
||||
if(refreshTimer) {
|
||||
clearTimeout(refreshTimer)
|
||||
setTimer(0)
|
||||
}
|
||||
setState({loading: true})
|
||||
getList().then((ret) => {
|
||||
const list = ret.list || []
|
||||
@ -49,12 +55,19 @@ export default function VideoIndex() {
|
||||
// 判断是否有生成中的视频
|
||||
if (list.filter(s => s.status == VideoStatus.Generating).length > 0) {
|
||||
// 每5s重新获取一次最新数据
|
||||
setTimeout(() => loadList(false), 5000)
|
||||
setTimer(()=>setTimeout(() => loadList(false), 5000) as number);
|
||||
}
|
||||
}).catch(showErrorToast)
|
||||
.finally(()=>{
|
||||
setState({loading: false})
|
||||
})
|
||||
return ()=>{
|
||||
if(refreshTimer){
|
||||
|
||||
clearTimeout(refreshTimer)
|
||||
}
|
||||
console.log('go out',refreshTimer)
|
||||
}
|
||||
}
|
||||
|
||||
// 播放视频
|
||||
|
Loading…
x
Reference in New Issue
Block a user