From 8fc952b33c334adce12b37a1d85dbc40f0f46379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Delattre?= Date: Sun, 19 May 2019 17:50:11 +0200 Subject: [PATCH] Add torrent fetching on the torrent page --- frontend/js/components/torrents/list.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend/js/components/torrents/list.js b/frontend/js/components/torrents/list.js index 8f39c46..a20d5b3 100644 --- a/frontend/js/components/torrents/list.js +++ b/frontend/js/components/torrents/list.js @@ -1,4 +1,4 @@ -import React, { useState } from "react" +import React, { useState, useEffect } from "react" import PropTypes from "prop-types" import { Map, List } from "immutable" import { connect } from "react-redux" @@ -11,9 +11,19 @@ const mapDispatchToProps = { fetchTorrents, addTorrent, removeTorrent, }; -// TODO: fecth every x seconds const TorrentList = (props) => { const [fetched, setIsFetched] = useState(false); + + useEffect(() => { + const intervalID = setInterval(() => { + props.fetchTorrents(); + }, 10000); + + return () => { + clearInterval(intervalID); + }; + }); + if (!fetched) { props.fetchTorrents(); setIsFetched(true);