import _ from 'lodash';
import classnames from 'classnames';
import React from 'react';
import TextboxRepeater from '../forms/TextboxRepeater';
import TorrentActions from '../../actions/TorrentActions';
const methodsToBind = [
'getContent',
'handleDestinationChange',
'handleUrlAdd',
'handleUrlChange',
'handleUrlRemove',
'handleAddTorrents'
];
export default class AddTorrents extends React.Component {
constructor() {
super();
this.state = {
destination: null,
isExpanded: false,
urlTextboxes: [{value: null}]
};
methodsToBind.forEach((method) => {
this[method] = this[method].bind(this);
});
}
getContent() {
return (
);
}
handleAddTorrents() {
let torrentUrls = _.pluck(this.state.urlTextboxes, 'value');
TorrentActions.addTorrents(torrentUrls, this.state.destination);
}
handleDestinationChange(event) {
this.setState({
destination: event.target.value
})
}
handleMenuWrapperClick(event) {
event.stopPropagation();
}
handleUrlRemove(index) {
let urlTextboxes = Object.assign([], this.state.urlTextboxes);
urlTextboxes.splice(index, 1);
this.setState({
urlTextboxes
});
}
handleUrlAdd(index) {
let urlTextboxes = Object.assign([], this.state.urlTextboxes);
urlTextboxes.splice(index + 1, 0, {value: null});
this.setState({urlTextboxes});
}
handleUrlChange(index, value) {
let urlTextboxes = Object.assign([], this.state.urlTextboxes);
urlTextboxes[index].value = value;
this.setState({urlTextboxes});
}
render() {
return this.getContent();
}
}