Add torrent fetching on the torrent page

This commit is contained in:
Grégoire Delattre 2019-05-19 17:50:11 +02:00
parent f54b741c71
commit 8fc952b33c

View File

@ -1,4 +1,4 @@
import React, { useState } from "react" import React, { useState, useEffect } from "react"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { Map, List } from "immutable" import { Map, List } from "immutable"
import { connect } from "react-redux" import { connect } from "react-redux"
@ -11,9 +11,19 @@ const mapDispatchToProps = {
fetchTorrents, addTorrent, removeTorrent, fetchTorrents, addTorrent, removeTorrent,
}; };
// TODO: fecth every x seconds
const TorrentList = (props) => { const TorrentList = (props) => {
const [fetched, setIsFetched] = useState(false); const [fetched, setIsFetched] = useState(false);
useEffect(() => {
const intervalID = setInterval(() => {
props.fetchTorrents();
}, 10000);
return () => {
clearInterval(intervalID);
};
});
if (!fetched) { if (!fetched) {
props.fetchTorrents(); props.fetchTorrents();
setIsFetched(true); setIsFetched(true);