From f6646451b2906b9cebe2f9063aa7902d217f9adf Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 29 Dec 2017 01:19:24 -0500 Subject: [PATCH] Implement peer list --- scss/main.scss | 40 ++++++++++++++++++++------------------- src/actions/selection.js | 14 +++++++------- src/ui/torrent_details.js | 35 +++++++++++++++++++++++++++++----- 3 files changed, 58 insertions(+), 31 deletions(-) diff --git a/scss/main.scss b/scss/main.scss index 23e8391..cce229a 100644 --- a/scss/main.scss +++ b/scss/main.scss @@ -203,8 +203,8 @@ fieldset .form-check-input:only-child { } } -.files { - .file { +.flex-table { + & > div { display: flex; padding: 0.1rem 0.25rem; @@ -212,7 +212,7 @@ fieldset .form-check-input:only-child { background: #dfdfdf; } - div { + & > div { margin: 0 0.5rem; &:first-child { @@ -223,27 +223,29 @@ fieldset .form-check-input:only-child { margin-right: 0; } } + } +} - .progress { - min-width: 3rem; - align-self: center; +.files .file { + .progress { + min-width: 3rem; + align-self: center; - .progress-bar { - height: 100%; - } + .progress-bar { + height: 100%; } + } - .path { - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; - flex-grow: 1; - line-height: 1.7; - } + .path { + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + flex-grow: 1; + line-height: 1.7; + } - select { - min-width: 5rem; - } + select { + min-width: 5rem; } } diff --git a/src/actions/selection.js b/src/actions/selection.js index 810edf5..f6595da 100644 --- a/src/actions/selection.js +++ b/src/actions/selection.js @@ -39,13 +39,13 @@ export default function selectTorrent(ids, action, navigate=true) { const _ids = [ ...Object.values(files) .filter(file => file.torrent_id === t) - .map(file => file.id) - //...Object.values(peers) - // .filter(peer => peer.torrent_id === t) - // .map(peer => peer.id), - //...Object.values(trackers) - // .filter(tracker => tracker.torrent_id === t) - // .map(tracker => tracker.id), + .map(file => file.id), + ...Object.values(peers) + .filter(peer => peer.torrent_id === t) + .map(peer => peer.id), + ...Object.values(trackers) + .filter(tracker => tracker.torrent_id === t) + .map(tracker => tracker.id) ]; if (_ids.length > 0) { dispatch(unsubscribe(..._ids)); diff --git a/src/ui/torrent_details.js b/src/ui/torrent_details.js index 62a15fe..1d1d63c 100644 --- a/src/ui/torrent_details.js +++ b/src/ui/torrent_details.js @@ -26,6 +26,7 @@ import selectTorrent, { NONE } from '../actions/selection'; import { updateResource } from '../actions/resources'; +import { formatBitrate } from '../bitrate'; const dlURI = (uri, password, id) => `${uri.replace('ws', 'http')}/dl/${id}?password=${encodeURIComponent(password)}`; @@ -35,7 +36,6 @@ function basename(path) { } function File({ dispatch, file }) { - // TODO: edit priority const { uri, password } = store.getState().socket; return (
@@ -43,11 +43,11 @@ function File({ dispatch, file }) { value={file.progress * 100} color={file.progress != 1.0 ? "success" : "primary"} > - {file.progress == 1.0 ? + {file.progress === 1.0 ? "done" : `${(file.progress * 100).toFixed(0)}%`}
- {file.progress == 1.0 ? + {file.progress === 1.0 ? {basename(file.path)} : basename(file.path)} @@ -62,6 +62,7 @@ function File({ dispatch, file }) { priority: parseInt(e.target.value) }))} > + @@ -73,6 +74,17 @@ function File({ dispatch, file }) { ); } +function Peer({ peer }) { + return ( +
+
{peer.ip}
+
{formatBitrate(peer.rate_up)} up
+
{formatBitrate(peer.rate_down)} down
+
has {`${(peer.availability * 100).toFixed(0)}%`}
+
+ ); +} + // TODO: move to separate component function CollapseToggle({ text, onToggle, open }) { return ( @@ -110,7 +122,7 @@ class Torrent extends Component { } render() { - const { dispatch, torrent, files, trackers } = this.props; + const { dispatch, torrent, files, trackers, peers } = this.props; const status = s => s[0].toUpperCase() + s.slice(1); if (!torrent || !files) { @@ -203,7 +215,7 @@ class Torrent extends Component { -
+
{files.slice().sort((a, b) => a.path.localeCompare(b.path)).map(file => )} @@ -240,6 +252,19 @@ class Torrent extends Component { + + + +
+ {peers.map(peer => )} +
+ {peers.length === 0 && +
+

No connected peers.

} +
} +
+
+
); }