Use torrent destination component as source of truth

This commit is contained in:
John Furrow
2017-02-04 13:22:40 -08:00
parent 32e7fe1798
commit 12ef922007
3 changed files with 51 additions and 61 deletions
@@ -28,7 +28,6 @@ const messages = defineMessages({
const METHODS_TO_BIND = [
'handleAddTorrents',
'handleDestinationChange',
'handleFileDrop',
'handleFileRemove',
'handleStartTorrentsToggle',
@@ -40,7 +39,6 @@ class AddTorrentsByFile extends React.Component {
super();
this.state = {
destination: SettingsStore.getFloodSettings('torrentDestination'),
errors: {},
isAddingTorrents: false,
files: null,
@@ -153,7 +151,9 @@ class AddTorrentsByFile extends React.Component {
if (this.isFormValid()) {
this.setState({isAddingTorrents: true});
let fileData = new FormData();
const destination = this.torrentDestinationRef.getWrappedInstance()
.getValue();
const fileData = new FormData();
this.state.files.forEach(file => {
fileData.append('torrents', file);
@@ -163,17 +163,13 @@ class AddTorrentsByFile extends React.Component {
fileData.append('tags', tag);
});
fileData.append('destination', this.state.destination);
fileData.append('destination', destination);
fileData.append('start', this.state.startTorrents);
TorrentActions.addTorrentsByFiles(fileData, this.state.destination);
TorrentActions.addTorrentsByFiles(fileData, destination);
}
}
handleDestinationChange(destination) {
this.setState({destination});
}
handleStartTorrentsToggle(value) {
this.setState({startTorrents: value});
}
@@ -183,7 +179,7 @@ class AddTorrentsByFile extends React.Component {
}
isFormValid() {
const {destination, files} = this.state;
const {files} = this.state;
const nextErrorsState = {};
const areFilesSelected = files != null
@@ -192,7 +188,7 @@ class AddTorrentsByFile extends React.Component {
return this.validatedFields.files.isValid(file);
});
const isDestinationValid = this.validatedFields.destination
.isValid(destination);
.isValid(this.torrentDestinationRef.getWrappedInstance().getValue());
if (!areFilesSelected) {
nextErrorsState.files = this.validatedFields.files.error;
@@ -231,7 +227,7 @@ class AddTorrentsByFile extends React.Component {
defaultMessage="Destination"
/>
</FormLabel>
<TorrentDestination onChange={this.handleDestinationChange} />
<TorrentDestination ref={ref => this.torrentDestinationRef = ref} />
</FormColumn>
</div>
<div className="form__row">
@@ -256,4 +252,4 @@ class AddTorrentsByFile extends React.Component {
}
}
export default injectIntl(AddTorrentsByFile);
export default injectIntl(AddTorrentsByFile, {withRef: true});
@@ -23,7 +23,6 @@ const messages = defineMessages({
const METHODS_TO_BIND = [
'handleAddTorrents',
'handleDestinationChange',
'handleStartTorrentsToggle',
'handleTagsChange',
'handleUrlAdd',
@@ -37,7 +36,6 @@ class AddTorrentsByURL extends React.Component {
this.state = {
addTorrentsError: null,
destination: SettingsStore.getFloodSettings('torrentDestination'),
errors: {},
isAddingTorrents: false,
tags: '',
@@ -68,17 +66,13 @@ class AddTorrentsByURL extends React.Component {
TorrentActions.addTorrentsByUrls({
urls: torrentURLs,
destination: this.state.destination,
destination: this.torrentDestinationRef.getWrappedInstance().getValue(),
start: this.state.startTorrents,
tags: this.state.tags.split(',')
});
}
}
handleDestinationChange(destination) {
this.setState({destination});
}
handleStartTorrentsToggle(value) {
this.setState({startTorrents: value});
}
@@ -110,7 +104,7 @@ class AddTorrentsByURL extends React.Component {
return this.validatedFields.urls.isValid(value);
});
const isDestinationValid = this.validatedFields.destination
.isValid(this.state.destination);
.isValid(this.torrentDestinationRef.getWrappedInstance().getValue());
const nextErrorsState = {};
if (!areURLsDefined) {
@@ -170,7 +164,7 @@ class AddTorrentsByURL extends React.Component {
defaultMessage="Destination"
/>
</FormLabel>
<TorrentDestination onChange={this.handleDestinationChange} />
<TorrentDestination ref={ref => this.torrentDestinationRef = ref} />
</FormColumn>
</div>
<div className="form__row">
@@ -195,4 +189,4 @@ class AddTorrentsByURL extends React.Component {
}
}
export default injectIntl(AddTorrentsByURL);
export default injectIntl(AddTorrentsByURL, {withRef: true});