Implement torrent removal
This commit is contained in:
parent
f21215bc67
commit
f566414259
|
@ -11,8 +11,10 @@ export default function subscribe(state = [], action) {
|
||||||
const { ids } = action;
|
const { ids } = action;
|
||||||
return state.filter(sub => ids.indexOf(sub.id) === -1);
|
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.filter(sub => ids.indexOf(sub.id) === -1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,8 @@ export default function ws_send(type, body, callback = null) {
|
||||||
|
|
||||||
const handlers = {
|
const handlers = {
|
||||||
RESOURCES_EXTANT: msg => dispatch(subscribe(...msg.ids)),
|
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) {
|
function ws_recv(e) {
|
||||||
|
|
|
@ -13,7 +13,12 @@ import {
|
||||||
Progress
|
Progress
|
||||||
} from 'reactstrap';
|
} from 'reactstrap';
|
||||||
import ws_send from '../socket';
|
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 }) {
|
function File({ file }) {
|
||||||
// TODO: show progress bar
|
// TODO: show progress bar
|
||||||
|
@ -64,7 +69,7 @@ class Torrent extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { torrent, files } = this.props;
|
const { dispatch, torrent, files } = this.props;
|
||||||
const status = s => s[0].toUpperCase() + s.slice(1);
|
const status = s => s[0].toUpperCase() + s.slice(1);
|
||||||
|
|
||||||
if (!torrent || !files) {
|
if (!torrent || !files) {
|
||||||
|
@ -100,7 +105,12 @@ class Torrent extends Component {
|
||||||
Remove
|
Remove
|
||||||
</DropdownToggle>
|
</DropdownToggle>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownItem>Remove</DropdownItem>
|
<DropdownItem
|
||||||
|
onClick={() => {
|
||||||
|
dispatch(selectTorrent([torrent.id], SUBTRACT));
|
||||||
|
ws_send("REMOVE_RESOURCE", { id: torrent.id });
|
||||||
|
}}
|
||||||
|
>Remove</DropdownItem>
|
||||||
<DropdownItem>Remove and delete files</DropdownItem>
|
<DropdownItem>Remove and delete files</DropdownItem>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</ButtonDropdown>
|
</ButtonDropdown>
|
||||||
|
@ -171,7 +181,8 @@ class TorrentDetails extends Component {
|
||||||
dispatch(selectTorrent([], EXCLUSIVE, false));
|
dispatch(selectTorrent([], EXCLUSIVE, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
renderHeader(selection) {
|
renderHeader() {
|
||||||
|
const { dispatch, selection } = this.props;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h3>
|
<h3>
|
||||||
|
@ -201,7 +212,12 @@ class TorrentDetails extends Component {
|
||||||
Remove all
|
Remove all
|
||||||
</DropdownToggle>
|
</DropdownToggle>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownItem>Remove selected torrents</DropdownItem>
|
<DropdownItem
|
||||||
|
onClick={() => {
|
||||||
|
dispatch(selectTorrent(selection, SUBTRACT));
|
||||||
|
selection.forEach(id => ws_send("REMOVE_RESOURCE", { id }));
|
||||||
|
}}
|
||||||
|
>Remove selected torrents</DropdownItem>
|
||||||
<DropdownItem>Remove selected torrents and delete files</DropdownItem>
|
<DropdownItem>Remove selected torrents and delete files</DropdownItem>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</ButtonDropdown>
|
</ButtonDropdown>
|
||||||
|
@ -212,14 +228,15 @@ class TorrentDetails extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { torrents, files, selection } = this.props;
|
const { torrents, files, selection, dispatch } = this.props;
|
||||||
const _files = Object.values(files).reduce((s, f) => ({
|
const _files = Object.values(files).reduce((s, f) => ({
|
||||||
...s, [f.torrent_id]: [...(s[f.torrent_id] || []), f]
|
...s, [f.torrent_id]: [...(s[f.torrent_id] || []), f]
|
||||||
}), {});
|
}), {});
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{selection.length > 1 ? this.renderHeader(selection) : null}
|
{selection.length > 1 ? this.renderHeader.bind(this)() : null}
|
||||||
{selection.slice(0, 3).map(id => <Torrent
|
{selection.slice(0, 3).map(id => <Torrent
|
||||||
|
dispatch={dispatch}
|
||||||
torrent={torrents[id]}
|
torrent={torrents[id]}
|
||||||
files={_files[id] || []}
|
files={_files[id] || []}
|
||||||
/>)}
|
/>)}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user