diff --git a/client/source/scripts/components/modals/AddTorrent.js b/client/source/scripts/components/modals/AddTorrent.js deleted file mode 100644 index 73982a2c..00000000 --- a/client/source/scripts/components/modals/AddTorrent.js +++ /dev/null @@ -1,93 +0,0 @@ -import classnames from 'classnames'; -import React from 'react'; - -const methodsToBind = [ - 'getContent', - 'handleDestinationChange', - 'handleUrlChange', - 'handleAddTorrent', - 'handleButtonClick' -]; - -export default class AddTorrentPanel extends React.Component { - - constructor() { - super(); - - this.state = { - isExpanded: false - }; - - methodsToBind.forEach((method) => { - this[method] = this[method].bind(this); - }); - } - - getContent() { - return ( -
-
Add Torrent
-
-
- - -
-
- - -
-
- -
-
-
- ); - } - - handleAddTorrent() { - // TorrentActions.add({ - // url: this.state.url, - // destination: this.state.destination - // }); - } - - handleButtonClick(evt) { - evt.stopPropagation(); - this.setState({ - isExpanded: !this.state.isExpanded - }); - } - - handleDestinationChange(event) { - this.setState({ - destination: event.target.value - }) - } - - handleMenuWrapperClick(evt) { - evt.stopPropagation(); - } - - handleUrlChange(event) { - this.setState({ - url: event.target.value - }) - } - - render() { - return this.getContent(); - } - -} diff --git a/client/source/scripts/components/modals/AddTorrents.js b/client/source/scripts/components/modals/AddTorrents.js new file mode 100644 index 00000000..9d871e94 --- /dev/null +++ b/client/source/scripts/components/modals/AddTorrents.js @@ -0,0 +1,114 @@ +import _ from 'underscore'; +import classnames from 'classnames'; +import React from 'react'; + +import { addTorrents } from '../../actions/ClientActions'; +import TextboxRepeater from '../forms/TextboxRepeater'; + +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 ( +
+
Add Torrents
+
+
+ +
+
+ +
+
+ + +
+
+
+ ); + } + + handleAddTorrents() { + let torrentUrls = _.pluck(this.state.urlTextboxes, 'value'); + this.props.dispatch( + 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(); + } + +}