From be9e6a621d9e0b895d601011337d49be22eaa92d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 25 Aug 2017 19:37:28 -0400 Subject: [PATCH] Unselect all torrents when navigating away --- src/actions/selection.js | 1 + src/reducers/selection.js | 4 +++- src/ui/torrent_details.js | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/actions/selection.js b/src/actions/selection.js index 06e2c72..b709c85 100644 --- a/src/actions/selection.js +++ b/src/actions/selection.js @@ -5,6 +5,7 @@ import { push } from 'react-router-redux'; export const UNION = 'UNION'; export const SUBTRACT = 'SUBTRACT'; export const EXCLUSIVE = 'EXCLUSIVE'; +export const NONE = 'NONE'; Set.prototype.difference = function(set) { var diff = new Set(this); diff --git a/src/reducers/selection.js b/src/reducers/selection.js index 6c83c39..cc16cd6 100644 --- a/src/reducers/selection.js +++ b/src/reducers/selection.js @@ -1,4 +1,4 @@ -import { UNION, SUBTRACT, EXCLUSIVE } from '../actions/selection'; +import { UNION, SUBTRACT, EXCLUSIVE, NONE } from '../actions/selection'; export default function selection(state = [], action) { const { id } = action; @@ -9,6 +9,8 @@ export default function selection(state = [], action) { return state.filter(t => t !== id); case EXCLUSIVE: return [id]; + case NONE: + return []; } return state; } diff --git a/src/ui/torrent_details.js b/src/ui/torrent_details.js index 32bc93c..47ed021 100644 --- a/src/ui/torrent_details.js +++ b/src/ui/torrent_details.js @@ -13,7 +13,7 @@ import { Progress } from 'reactstrap'; import ws_send from '../socket'; -import selectTorrent, { UNION } from '../actions/selection'; +import selectTorrent, { UNION, NONE } from '../actions/selection'; // TODO: fix navigating directly to torrent pages @@ -158,6 +158,11 @@ class TorrentDetails extends Component { _ids.forEach(id => dispatch(selectTorrent(id, UNION))); } + componentWillUnmount() { + const { dispatch } = this.props; + dispatch(selectTorrent(null, NONE)); + } + renderHeader(selection) { return (