2017-08-10 01:56:27 +00:00
|
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
2017-08-15 18:43:58 +00:00
|
|
|
|
import {Tab, TabList, TabPanel, Tabs} from 'react-tabs';
|
2017-03-03 01:44:07 +00:00
|
|
|
|
import autobind from 'autobind-decorator';
|
2017-03-08 05:52:17 +00:00
|
|
|
|
import Modal from '../base/modal';
|
|
|
|
|
import Button from '../base/button';
|
|
|
|
|
import ModalBody from '../base/modal-body';
|
|
|
|
|
import ModalHeader from '../base/modal-header';
|
|
|
|
|
import SettingsShortcuts from '../settings/shortcuts';
|
|
|
|
|
import About from '../settings/about';
|
|
|
|
|
import General from '../settings/general';
|
|
|
|
|
import ImportExport from '../settings/import-export';
|
2017-03-29 02:21:49 +00:00
|
|
|
|
import Account from '../settings/account';
|
2017-06-01 02:04:27 +00:00
|
|
|
|
import Plugins from '../settings/plugins';
|
2017-03-08 05:52:17 +00:00
|
|
|
|
import Theme from '../settings/theme';
|
2017-01-20 17:51:18 +00:00
|
|
|
|
import * as models from '../../../models/index';
|
2017-08-16 02:17:35 +00:00
|
|
|
|
import {Curl} from 'insomnia-node-libcurl';
|
2017-08-15 18:43:58 +00:00
|
|
|
|
import {getAppName, getAppVersion} from '../../../common/constants';
|
2016-11-11 01:36:23 +00:00
|
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2017-02-08 00:31:48 +00:00
|
|
|
|
import * as session from '../../../sync/session';
|
2017-07-21 18:59:17 +00:00
|
|
|
|
import Tooltip from '../tooltip';
|
2016-05-07 17:29:24 +00:00
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
|
export const TAB_INDEX_EXPORT = 1;
|
2017-08-04 16:54:11 +00:00
|
|
|
|
export const TAB_INDEX_SHORTCUTS = 3;
|
2016-07-19 04:01:31 +00:00
|
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
|
@autobind
|
2017-02-28 21:32:23 +00:00
|
|
|
|
class SettingsModal extends PureComponent {
|
2016-08-17 20:58:44 +00:00
|
|
|
|
constructor (props) {
|
|
|
|
|
super(props);
|
2017-03-03 01:44:07 +00:00
|
|
|
|
this.state = {};
|
2016-08-17 20:58:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
|
_setModalRef (n) {
|
|
|
|
|
this.modal = n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_handleUpdateSetting (key, value) {
|
2017-02-13 08:12:02 +00:00
|
|
|
|
models.settings.update(this.props.settings, {[key]: value});
|
2017-03-03 20:09:08 +00:00
|
|
|
|
trackEvent('Setting', 'Change', key);
|
2017-03-03 01:44:07 +00:00
|
|
|
|
}
|
2017-02-13 08:12:02 +00:00
|
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
|
_handleExportAllToFile () {
|
2017-02-13 08:12:02 +00:00
|
|
|
|
this.props.handleExportAllToFile();
|
2017-03-03 20:09:08 +00:00
|
|
|
|
this.modal.hide();
|
2017-03-03 01:44:07 +00:00
|
|
|
|
}
|
2017-02-13 08:12:02 +00:00
|
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
|
_handleExportWorkspace () {
|
2017-02-13 08:12:02 +00:00
|
|
|
|
this.props.handleExportWorkspaceToFile();
|
2017-03-03 20:09:08 +00:00
|
|
|
|
this.modal.hide();
|
2017-03-03 01:44:07 +00:00
|
|
|
|
}
|
2017-02-13 08:12:02 +00:00
|
|
|
|
|
2017-05-03 17:48:23 +00:00
|
|
|
|
_handleImportFile () {
|
2017-02-13 08:12:02 +00:00
|
|
|
|
this.props.handleImportFile();
|
2017-03-03 20:09:08 +00:00
|
|
|
|
this.modal.hide();
|
2017-03-03 01:44:07 +00:00
|
|
|
|
}
|
2017-02-13 08:12:02 +00:00
|
|
|
|
|
2017-05-03 17:48:23 +00:00
|
|
|
|
_handleImportUri (uri) {
|
|
|
|
|
this.props.handleImportUri(uri);
|
|
|
|
|
this.modal.hide();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
|
_handleChangeTheme (theme, persist = true) {
|
2017-01-20 21:54:03 +00:00
|
|
|
|
document.body.setAttribute('theme', theme);
|
2017-01-24 06:08:21 +00:00
|
|
|
|
|
2017-02-15 20:32:15 +00:00
|
|
|
|
if (persist) {
|
|
|
|
|
trackEvent('Setting', 'Change Theme', theme);
|
|
|
|
|
models.settings.update(this.props.settings, {theme});
|
2017-01-24 06:08:21 +00:00
|
|
|
|
}
|
2017-03-03 01:44:07 +00:00
|
|
|
|
}
|
2016-11-29 20:55:31 +00:00
|
|
|
|
|
2017-01-23 22:41:31 +00:00
|
|
|
|
componentDidMount () {
|
|
|
|
|
// Hacky way to set theme on launch
|
|
|
|
|
// TODO: move somewhere else
|
2017-01-24 06:08:21 +00:00
|
|
|
|
this._handleChangeTheme(this.props.settings.theme, false);
|
2017-01-23 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render () {
|
2017-02-13 08:12:02 +00:00
|
|
|
|
const {settings} = this.props;
|
2016-11-16 17:18:39 +00:00
|
|
|
|
const {currentTabIndex} = this.state;
|
2017-02-08 00:31:48 +00:00
|
|
|
|
const email = session.isLoggedIn() ? session.getEmail() : null;
|
2016-07-19 04:01:31 +00:00
|
|
|
|
|
2016-05-07 17:29:24 +00:00
|
|
|
|
return (
|
2017-03-12 09:03:57 +00:00
|
|
|
|
<Modal ref={this._setModalRef} tall freshState {...this.props}>
|
2016-07-19 22:28:29 +00:00
|
|
|
|
<ModalHeader>
|
2016-11-29 20:55:31 +00:00
|
|
|
|
{getAppName()} Preferences
|
2017-02-08 00:31:48 +00:00
|
|
|
|
<span className="faint txt-sm">
|
|
|
|
|
–
|
2017-02-13 08:12:02 +00:00
|
|
|
|
v{getAppVersion()}
|
2017-07-21 18:59:17 +00:00
|
|
|
|
<Tooltip position="bottom" message={Curl.getVersion()}>
|
|
|
|
|
<i className="fa fa-info-circle"/>
|
|
|
|
|
</Tooltip>
|
2017-02-13 08:12:02 +00:00
|
|
|
|
{email ? ` – ${email}` : null}
|
2017-02-08 00:31:48 +00:00
|
|
|
|
</span>
|
2016-07-19 22:28:29 +00:00
|
|
|
|
</ModalHeader>
|
2017-03-01 21:15:56 +00:00
|
|
|
|
<ModalBody noScroll>
|
2017-08-10 01:56:27 +00:00
|
|
|
|
<Tabs className="react-tabs" defaultIndex={currentTabIndex}>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
<TabList>
|
2017-08-04 16:54:11 +00:00
|
|
|
|
<Tab>
|
2017-08-15 18:43:58 +00:00
|
|
|
|
<Button value="General">
|
2017-01-20 21:54:03 +00:00
|
|
|
|
General
|
2017-02-13 08:12:02 +00:00
|
|
|
|
</Button>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</Tab>
|
2017-08-04 16:54:11 +00:00
|
|
|
|
<Tab>
|
2017-08-15 18:43:58 +00:00
|
|
|
|
<Button value="Import/Export">
|
2017-06-01 02:04:27 +00:00
|
|
|
|
Data
|
2017-02-13 08:12:02 +00:00
|
|
|
|
</Button>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</Tab>
|
2017-08-04 16:54:11 +00:00
|
|
|
|
<Tab>
|
2017-08-15 18:43:58 +00:00
|
|
|
|
<Button value="Themes">
|
2017-01-23 22:41:31 +00:00
|
|
|
|
Themes
|
2017-02-13 08:12:02 +00:00
|
|
|
|
</Button>
|
2017-01-20 21:54:03 +00:00
|
|
|
|
</Tab>
|
2017-08-04 16:54:11 +00:00
|
|
|
|
<Tab>
|
2017-08-15 18:43:58 +00:00
|
|
|
|
<Button value="Shortcuts">
|
2017-08-04 16:54:11 +00:00
|
|
|
|
Keyboard
|
2017-02-13 08:12:02 +00:00
|
|
|
|
</Button>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</Tab>
|
2017-08-04 16:54:11 +00:00
|
|
|
|
<Tab>
|
2017-08-15 18:43:58 +00:00
|
|
|
|
<Button value="Account">
|
2017-03-29 02:21:49 +00:00
|
|
|
|
Account
|
|
|
|
|
</Button>
|
|
|
|
|
</Tab>
|
2017-08-04 16:54:11 +00:00
|
|
|
|
<Tab>
|
2017-08-15 18:43:58 +00:00
|
|
|
|
<Button value="Plugins">
|
2017-06-01 02:04:27 +00:00
|
|
|
|
Plugins
|
|
|
|
|
</Button>
|
|
|
|
|
</Tab>
|
2017-08-04 16:54:11 +00:00
|
|
|
|
<Tab>
|
2017-08-15 18:43:58 +00:00
|
|
|
|
<Button value="About">
|
2017-01-20 21:54:03 +00:00
|
|
|
|
About
|
2017-02-13 08:12:02 +00:00
|
|
|
|
</Button>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</Tab>
|
|
|
|
|
</TabList>
|
2017-08-10 01:56:27 +00:00
|
|
|
|
<TabPanel className="react-tabs__tab-panel pad scrollable">
|
2017-03-08 05:52:17 +00:00
|
|
|
|
<General
|
2016-11-16 17:18:39 +00:00
|
|
|
|
settings={settings}
|
2017-05-17 16:35:44 +00:00
|
|
|
|
handleToggleMenuBar={this.props.handleToggleMenuBar}
|
2017-02-13 08:12:02 +00:00
|
|
|
|
updateSetting={this._handleUpdateSetting}
|
2016-11-16 17:18:39 +00:00
|
|
|
|
/>
|
|
|
|
|
</TabPanel>
|
2017-08-10 01:56:27 +00:00
|
|
|
|
<TabPanel className="react-tabs__tab-panel pad scrollable">
|
2017-03-08 05:52:17 +00:00
|
|
|
|
<ImportExport
|
2017-02-13 08:12:02 +00:00
|
|
|
|
handleExportAll={this._handleExportAllToFile}
|
|
|
|
|
handleExportWorkspace={this._handleExportWorkspace}
|
2017-05-03 17:48:23 +00:00
|
|
|
|
handleImportFile={this._handleImportFile}
|
|
|
|
|
handleImportUri={this._handleImportUri}
|
2016-11-16 17:18:39 +00:00
|
|
|
|
/>
|
|
|
|
|
</TabPanel>
|
2017-08-10 01:56:27 +00:00
|
|
|
|
<TabPanel className="react-tabs__tab-panel scrollable">
|
2017-03-08 05:52:17 +00:00
|
|
|
|
<Theme
|
2017-01-20 21:54:03 +00:00
|
|
|
|
handleChangeTheme={this._handleChangeTheme}
|
|
|
|
|
activeTheme={settings.theme}
|
|
|
|
|
/>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</TabPanel>
|
2017-08-10 01:56:27 +00:00
|
|
|
|
<TabPanel className="react-tabs__tab-panel pad scrollable"><SettingsShortcuts/></TabPanel>
|
|
|
|
|
<TabPanel className="react-tabs__tab-panel pad scrollable"><Account/></TabPanel>
|
|
|
|
|
<TabPanel className="react-tabs__tab-panel pad scrollable"><Plugins/></TabPanel>
|
|
|
|
|
<TabPanel className="react-tabs__tab-panel pad scrollable"><About/></TabPanel>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</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,
|
2017-05-03 17:48:23 +00:00
|
|
|
|
handleImportUri: PropTypes.func.isRequired,
|
2017-05-17 16:35:44 +00:00
|
|
|
|
handleToggleMenuBar: PropTypes.func.isRequired,
|
2016-11-16 17:18:39 +00:00
|
|
|
|
|
|
|
|
|
// Properties
|
2017-03-03 20:09:08 +00:00
|
|
|
|
settings: PropTypes.object.isRequired
|
2016-11-16 17:18:39 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-05-07 17:29:24 +00:00
|
|
|
|
export default SettingsModal;
|