Force stats refresh works better now on pause/unpause

This commit is contained in:
Igor Katson 2023-11-25 01:29:20 +00:00
parent 79bd41a552
commit e467787c38
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
2 changed files with 17 additions and 14 deletions

File diff suppressed because one or more lines are too long

View file

@ -241,6 +241,11 @@ const Column: React.FC<{
const Torrent = ({ id, torrent }) => { const Torrent = ({ id, torrent }) => {
const [detailsResponse, updateDetailsResponse] = useState<TorrentDetails>(null); const [detailsResponse, updateDetailsResponse] = useState<TorrentDetails>(null);
const [statsResponse, updateStatsResponse] = useState<TorrentStats>(null); const [statsResponse, updateStatsResponse] = useState<TorrentStats>(null);
const [forceStatsRefresh, setForceStatsRefresh] = useState(0);
const forceStatsRefreshCallback = () => {
setForceStatsRefresh(forceStatsRefresh + 1);
}
// Update details once. // Update details once.
useEffect(() => { useEffect(() => {
@ -251,11 +256,6 @@ const Torrent = ({ id, torrent }) => {
} }
}, [detailsResponse]); }, [detailsResponse]);
const refreshStats = () => API.getTorrentStats(torrent.id).then((stats) => {
updateStatsResponse(stats);
return stats;
});
// Update stats once then forever. // Update stats once then forever.
useEffect(() => customSetInterval((async () => { useEffect(() => customSetInterval((async () => {
const errorInterval = 10000; const errorInterval = 10000;
@ -263,7 +263,10 @@ const Torrent = ({ id, torrent }) => {
const finishedInterval = 10000; const finishedInterval = 10000;
const nonLiveInterval = 10000; const nonLiveInterval = 10000;
return refreshStats().then((stats) => { return API.getTorrentStats(torrent.id).then((stats) => {
updateStatsResponse(stats);
return stats;
}).then((stats) => {
if (stats.finished) { if (stats.finished) {
return finishedInterval; return finishedInterval;
} }
@ -274,9 +277,9 @@ const Torrent = ({ id, torrent }) => {
}, (e) => { }, (e) => {
return errorInterval; return errorInterval;
}); });
}), 0), []); }), 0), [forceStatsRefresh]);
return <RefreshTorrentStatsContext.Provider value={{ refresh: refreshStats }}> return <RefreshTorrentStatsContext.Provider value={{ refresh: forceStatsRefreshCallback }}>
<TorrentRow id={id} detailsResponse={detailsResponse} statsResponse={statsResponse} /> <TorrentRow id={id} detailsResponse={detailsResponse} statsResponse={statsResponse} />
</RefreshTorrentStatsContext.Provider > </RefreshTorrentStatsContext.Provider >
} }