From f56641425916ee701ea05ceedd9986acaa63db70 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 8 Sep 2017 17:27:00 +0900 Subject: [PATCH] Implement torrent removal --- src/reducers/subscribe.js | 4 +++- src/socket.js | 3 ++- src/ui/torrent_details.js | 31 ++++++++++++++++++++++++------- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/reducers/subscribe.js b/src/reducers/subscribe.js index 09e6194..97fc85f 100644 --- a/src/reducers/subscribe.js +++ b/src/reducers/subscribe.js @@ -11,8 +11,10 @@ export default function subscribe(state = [], action) { const { ids } = action; return state.filter(sub => ids.indexOf(sub.id) === -1); } - case RESOURCES_REMOVED: + case RESOURCES_REMOVED: { + const { ids } = action; return state.filter(sub => ids.indexOf(sub.id) === -1); + } } return state; } diff --git a/src/socket.js b/src/socket.js index b961c46..261c326 100644 --- a/src/socket.js +++ b/src/socket.js @@ -29,7 +29,8 @@ export default function ws_send(type, body, callback = null) { const handlers = { RESOURCES_EXTANT: msg => dispatch(subscribe(...msg.ids)), - UPDATE_RESOURCES: msg => dispatch(msg) + UPDATE_RESOURCES: msg => dispatch(msg), + RESOURCES_REMOVED: msg => dispatch(msg), }; function ws_recv(e) { diff --git a/src/ui/torrent_details.js b/src/ui/torrent_details.js index 980042c..27a059c 100644 --- a/src/ui/torrent_details.js +++ b/src/ui/torrent_details.js @@ -13,7 +13,12 @@ import { Progress } from 'reactstrap'; import ws_send from '../socket'; -import selectTorrent, { EXCLUSIVE, UNION, NONE } from '../actions/selection'; +import selectTorrent, { + EXCLUSIVE, + UNION, + SUBTRACT, + NONE +} from '../actions/selection'; function File({ file }) { // TODO: show progress bar @@ -64,7 +69,7 @@ class Torrent extends Component { } render() { - const { torrent, files } = this.props; + const { dispatch, torrent, files } = this.props; const status = s => s[0].toUpperCase() + s.slice(1); if (!torrent || !files) { @@ -100,7 +105,12 @@ class Torrent extends Component { Remove - Remove + { + dispatch(selectTorrent([torrent.id], SUBTRACT)); + ws_send("REMOVE_RESOURCE", { id: torrent.id }); + }} + >Remove Remove and delete files @@ -171,7 +181,8 @@ class TorrentDetails extends Component { dispatch(selectTorrent([], EXCLUSIVE, false)); } - renderHeader(selection) { + renderHeader() { + const { dispatch, selection } = this.props; return (

@@ -201,7 +212,12 @@ class TorrentDetails extends Component { Remove all - Remove selected torrents + { + dispatch(selectTorrent(selection, SUBTRACT)); + selection.forEach(id => ws_send("REMOVE_RESOURCE", { id })); + }} + >Remove selected torrents Remove selected torrents and delete files @@ -212,14 +228,15 @@ class TorrentDetails extends Component { } render() { - const { torrents, files, selection } = this.props; + const { torrents, files, selection, dispatch } = this.props; const _files = Object.values(files).reduce((s, f) => ({ ...s, [f.torrent_id]: [...(s[f.torrent_id] || []), f] }), {}); return (
- {selection.length > 1 ? this.renderHeader(selection) : null} + {selection.length > 1 ? this.renderHeader.bind(this)() : null} {selection.slice(0, 3).map(id => )}