import _ from 'lodash';
import classnames from 'classnames';
import React from 'react';
import AddTorrentsDestination from './AddTorrentsDestination';
import AppDispatcher from '../../dispatcher/AppDispatcher';
import Checkbox from '../forms/Checkbox';
import EventTypes from '../../constants/EventTypes';
import LoadingIndicatorDots from '../icons/LoadingIndicatorDots';
import Modal from './Modal';
import ModalActions from './ModalActions';
import TorrentActions from '../../actions/TorrentActions';
import TorrentStore from '../../stores/TorrentStore';
const METHODS_TO_BIND = [
'confirmMoveTorrents',
'handleCheckboxChange',
'handleDestinationChange',
'handleTextboxChange',
'onMoveError'
];
export default class AddTorrents extends React.Component {
constructor() {
super();
this.state = {
moveTorrentsError: null,
destination: null,
isExpanded: false,
isSettingDownloadPath: false,
moveTorrents: false,
originalSource: null
};
METHODS_TO_BIND.forEach((method) => {
this[method] = this[method].bind(this);
});
}
componentWillMount() {
let filenames = TorrentStore.getSelectedTorrentsFilename();
let sources = TorrentStore.getSelectedTorrentsDownloadLocations();
if (sources.length === 1) {
let originalSource = this.removeTrailingFilename(sources[0], filenames[0]);
this.setState({originalSource, destination: originalSource});
}
}
componentDidMount() {
TorrentStore.listen(EventTypes.CLIENT_MOVE_TORRENTS_REQUEST_ERROR, this.onMoveError);
}
componentWillUnmount() {
TorrentStore.unlisten(EventTypes.CLIENT_MOVE_TORRENTS_REQUEST_ERROR, this.onMoveError);
}
onMoveError() {
this.setState({isSettingDownloadPath: false});
}
confirmMoveTorrents() {
let filenames = TorrentStore.getSelectedTorrentsFilename();
let sources = TorrentStore.getSelectedTorrentsDownloadLocations();
if (sources.length) {
this.setState({isSettingDownloadPath: true});
TorrentActions.moveTorrents(TorrentStore.getSelectedTorrents(), {
destination: this.state.destination,
filenames,
moveFiles: this.state.moveTorrents,
sources
});
}
}
getActions() {
let icon = null;
let primaryButtonText = 'Set Location';
if (this.state.isSettingDownloadPath) {
icon =