Save settings more reasonably

This commit is contained in:
John Furrow
2016-05-03 20:44:47 -07:00
parent 5e8640457f
commit 2eac7fb035
20 changed files with 207 additions and 193 deletions

View File

@@ -2,8 +2,30 @@ import React from 'react';
import LoadingIndicatorDots from '../icons/LoadingIndicatorDots';
import ModalActions from './ModalActions';
import SettingsStore from '../../stores/SettingsStore';
const METHODS_TO_BIND = ['handleStartTorrentsToggle'];
export default class AddTorrents extends React.Component {
constructor() {
super();
this.state = {
startTorrentsOnLoad: true
};
METHODS_TO_BIND.forEach((method) => {
this[method] = this[method].bind(this);
});
}
componentWillMount() {
let startTorrentsOnLoad = SettingsStore.getSettings('startTorrentsOnLoad');
if (startTorrentsOnLoad !== true) {
this.setState({startTorrentsOnLoad: false});
}
}
getActions() {
let icon = null;
let primaryButtonText = 'Add Torrent';
@@ -15,8 +37,8 @@ export default class AddTorrents extends React.Component {
return [
{
checked: true,
clickHandler: this.props.onStartTorrentsToggle,
checked: this.state.startTorrentsOnLoad,
clickHandler: this.handleStartTorrentsToggle,
content: 'Start Torrent',
triggerDismiss: false,
type: 'checkbox'
@@ -42,6 +64,13 @@ export default class AddTorrents extends React.Component {
];
}
handleStartTorrentsToggle(value) {
SettingsStore.saveSettings({id: 'startTorrentsOnLoad', data: value});
if (!!this.props.onStartTorrentsToggle) {
this.props.onStartTorrentsToggle(value);
}
}
render() {
return (
<ModalActions actions={this.getActions()} dismiss={this.props.dismiss} />