Unselect all torrents when navigating away

This commit is contained in:
Drew DeVault 2017-08-25 19:37:28 -04:00
parent d939ca662e
commit be9e6a621d
3 changed files with 10 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import { push } from 'react-router-redux';
export const UNION = 'UNION'; export const UNION = 'UNION';
export const SUBTRACT = 'SUBTRACT'; export const SUBTRACT = 'SUBTRACT';
export const EXCLUSIVE = 'EXCLUSIVE'; export const EXCLUSIVE = 'EXCLUSIVE';
export const NONE = 'NONE';
Set.prototype.difference = function(set) { Set.prototype.difference = function(set) {
var diff = new Set(this); var diff = new Set(this);

View File

@ -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) { export default function selection(state = [], action) {
const { id } = action; const { id } = action;
@ -9,6 +9,8 @@ export default function selection(state = [], action) {
return state.filter(t => t !== id); return state.filter(t => t !== id);
case EXCLUSIVE: case EXCLUSIVE:
return [id]; return [id];
case NONE:
return [];
} }
return state; return state;
} }

View File

@ -13,7 +13,7 @@ import {
Progress Progress
} from 'reactstrap'; } from 'reactstrap';
import ws_send from '../socket'; 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 // TODO: fix navigating directly to torrent pages
@ -158,6 +158,11 @@ class TorrentDetails extends Component {
_ids.forEach(id => dispatch(selectTorrent(id, UNION))); _ids.forEach(id => dispatch(selectTorrent(id, UNION)));
} }
componentWillUnmount() {
const { dispatch } = this.props;
dispatch(selectTorrent(null, NONE));
}
renderHeader(selection) { renderHeader(selection) {
return ( return (
<div> <div>