2016-07-19 04:01:31 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-09-03 05:14:48 +00:00
|
|
|
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
|
2016-07-16 02:06:10 +00:00
|
|
|
import {shell} from 'electron';
|
2016-07-22 22:27:04 +00:00
|
|
|
import Modal from '../base/Modal';
|
|
|
|
import ModalBody from '../base/ModalBody';
|
|
|
|
import ModalHeader from '../base/ModalHeader';
|
2016-11-07 20:24:38 +00:00
|
|
|
import SettingsShortcuts from '../settings/SettingsShortcuts';
|
|
|
|
import SettingsAbout from '../settings/SettingsAbout';
|
|
|
|
import SettingsGeneral from '../settings/SettingsGeneral';
|
|
|
|
import SettingsImportExport from '../settings/SettingsImportExport';
|
|
|
|
import SettingsSync from '../settings/SettingsSync';
|
2017-01-20 17:51:18 +00:00
|
|
|
import * as models from '../../../models/index';
|
2016-11-29 20:55:31 +00:00
|
|
|
import {getAppVersion, getAppName} from '../../../common/constants';
|
2016-11-09 03:18:25 +00:00
|
|
|
import * as session from '../../../sync/session';
|
2017-01-20 17:51:18 +00:00
|
|
|
import * as sync from '../../../sync/index';
|
2016-11-11 01:36:23 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2016-05-07 17:29:24 +00:00
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
export const TAB_INDEX_EXPORT = 1;
|
2016-07-19 04:01:31 +00:00
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
class SettingsModal extends Component {
|
2016-08-17 20:58:44 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this._currentTabIndex = -1;
|
2016-11-16 17:18:39 +00:00
|
|
|
this.state = {}
|
2016-08-17 20:58:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 20:55:31 +00:00
|
|
|
_handleClose = () => {
|
|
|
|
this.hide();
|
|
|
|
};
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
show (currentTabIndex = 0) {
|
|
|
|
this.setState({currentTabIndex});
|
|
|
|
this.modal.show();
|
2016-07-19 04:01:31 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
hide () {
|
|
|
|
this.modal.hide();
|
2016-08-17 20:58:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
toggle (currentTabIndex = 0) {
|
|
|
|
this.setState({currentTabIndex});
|
|
|
|
this.modal.toggle();
|
2016-07-19 04:01:31 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
_handleTabSelect (currentTabIndex) {
|
|
|
|
this.setState({currentTabIndex});
|
2016-08-15 22:31:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 04:01:31 +00:00
|
|
|
render () {
|
2016-11-16 17:18:39 +00:00
|
|
|
const {
|
|
|
|
settings,
|
|
|
|
handleExportAllToFile,
|
|
|
|
handleExportWorkspaceToFile,
|
|
|
|
handleImportFile,
|
|
|
|
} = this.props;
|
2016-07-21 16:33:35 +00:00
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
const {currentTabIndex} = this.state;
|
2016-07-19 04:01:31 +00:00
|
|
|
|
2016-05-07 17:29:24 +00:00
|
|
|
return (
|
2016-08-15 17:04:36 +00:00
|
|
|
<Modal ref={m => this.modal = m} tall={true} {...this.props}>
|
2016-07-19 22:28:29 +00:00
|
|
|
<ModalHeader>
|
2016-11-29 20:55:31 +00:00
|
|
|
{getAppName()} Preferences
|
2016-07-21 22:26:51 +00:00
|
|
|
|
|
|
|
<span className="faint txt-sm">v{getAppVersion()}</span>
|
2016-07-19 22:28:29 +00:00
|
|
|
</ModalHeader>
|
2016-10-21 17:20:36 +00:00
|
|
|
<ModalBody noScroll={true}>
|
2016-11-16 17:18:39 +00:00
|
|
|
<Tabs onSelect={i => this._handleTabSelect(i)} selectedIndex={currentTabIndex}>
|
|
|
|
<TabList>
|
|
|
|
<Tab selected={this._currentTabIndex === 0}>
|
2016-11-23 19:33:24 +00:00
|
|
|
<button onClick={e => trackEvent('Setting', 'Tab General')}>General</button>
|
2016-11-16 17:18:39 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab selected={this._currentTabIndex === 1}>
|
2016-12-21 23:37:48 +00:00
|
|
|
<button onClick={e => trackEvent('Setting', 'Tab Import/Export')}>Import/Export
|
|
|
|
</button>
|
2016-11-16 17:18:39 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab selected={this._currentTabIndex === 3}>
|
2016-11-23 19:33:24 +00:00
|
|
|
<button onClick={e => trackEvent('Setting', 'Tab Shortcuts')}>Shortcuts</button>
|
2016-11-16 17:18:39 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab selected={this._currentTabIndex === 2}>
|
2016-11-23 19:33:24 +00:00
|
|
|
<button onClick={e => trackEvent('Setting', 'Tab Plus')}>Insomnia Plus</button>
|
2016-11-16 17:18:39 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab selected={this._currentTabIndex === 4}>
|
2016-11-23 19:33:24 +00:00
|
|
|
<button onClick={e => trackEvent('Setting', 'Tab About')}>About</button>
|
2016-11-16 17:18:39 +00:00
|
|
|
</Tab>
|
|
|
|
</TabList>
|
|
|
|
<TabPanel className="pad scrollable">
|
|
|
|
<SettingsGeneral
|
|
|
|
settings={settings}
|
2016-11-23 19:33:24 +00:00
|
|
|
updateSetting={(key, value) => {
|
|
|
|
models.settings.update(settings, {[key]: value});
|
|
|
|
trackEvent('Setting', 'Change', key)
|
|
|
|
}}
|
2016-11-16 17:18:39 +00:00
|
|
|
/>
|
|
|
|
</TabPanel>
|
|
|
|
<TabPanel className="pad scrollable">
|
|
|
|
<SettingsImportExport
|
|
|
|
handleExportAll={() => {
|
|
|
|
handleExportAllToFile();
|
|
|
|
this.modal.hide()
|
|
|
|
}}
|
|
|
|
handleExportWorkspace={() => {
|
|
|
|
handleExportWorkspaceToFile();
|
|
|
|
this.modal.hide()
|
|
|
|
}}
|
|
|
|
handleImport={() => {
|
|
|
|
handleImportFile();
|
|
|
|
this.modal.hide()
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</TabPanel>
|
|
|
|
<TabPanel className="pad scrollable">
|
|
|
|
<SettingsShortcuts />
|
|
|
|
</TabPanel>
|
|
|
|
<TabPanel className="pad scrollable">
|
|
|
|
<SettingsSync
|
|
|
|
loggedIn={session.isLoggedIn()}
|
|
|
|
firstName={session.getFirstName() || ''}
|
2016-12-21 23:37:48 +00:00
|
|
|
email={session.getEmail() || ''}
|
|
|
|
handleExit={this._handleClose}
|
2016-11-16 17:18:39 +00:00
|
|
|
handleLogout={sync.logout}
|
|
|
|
/>
|
|
|
|
</TabPanel>
|
|
|
|
<TabPanel className="pad scrollable">
|
|
|
|
<SettingsAbout/>
|
|
|
|
</TabPanel>
|
|
|
|
</Tabs>
|
2016-05-07 17:29:24 +00:00
|
|
|
</ModalBody>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-11-16 17:18:39 +00:00
|
|
|
|
|
|
|
SettingsModal.propTypes = {
|
|
|
|
// Functions
|
|
|
|
handleExportWorkspaceToFile: PropTypes.func.isRequired,
|
|
|
|
handleExportAllToFile: PropTypes.func.isRequired,
|
|
|
|
handleImportFile: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
settings: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
2016-05-07 17:29:24 +00:00
|
|
|
export default SettingsModal;
|