2018-06-25 17:42:50 +00:00
|
|
|
|
import React, { PureComponent } from 'react';
|
2017-08-10 01:56:27 +00:00
|
|
|
|
import PropTypes from 'prop-types';
|
2018-06-25 17:42:50 +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';
|
2018-06-25 17:42:50 +00:00
|
|
|
|
import { Curl } from 'insomnia-libcurl';
|
|
|
|
|
import { getAppName, getAppVersion } from '../../../common/constants';
|
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';
|
2018-07-18 00:48:10 +00:00
|
|
|
|
import { setTheme } from '../../../plugins/misc';
|
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 {
|
2018-06-25 17:42:50 +00:00
|
|
|
|
constructor(props) {
|
2016-08-17 20:58:44 +00:00
|
|
|
|
super(props);
|
2017-03-03 01:44:07 +00:00
|
|
|
|
this.state = {};
|
2016-08-17 20:58:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
|
_setModalRef(n) {
|
2017-03-03 01:44:07 +00:00
|
|
|
|
this.modal = n;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 18:20:46 +00:00
|
|
|
|
async _handleUpdateSetting(key, value) {
|
|
|
|
|
return models.settings.update(this.props.settings, { [key]: value });
|
2017-03-03 01:44:07 +00:00
|
|
|
|
}
|
2017-02-13 08:12:02 +00:00
|
|
|
|
|
2018-06-25 17:42:50 +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
|
|
|
|
|
2018-06-25 17:42:50 +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
|
|
|
|
|
2018-06-25 17:42:50 +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
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
|
_handleImportUri(uri) {
|
2017-05-03 17:48:23 +00:00
|
|
|
|
this.props.handleImportUri(uri);
|
|
|
|
|
this.modal.hide();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-17 23:34:28 +00:00
|
|
|
|
async _handleChangeTheme(theme, persist = true) {
|
2018-07-18 00:48:10 +00:00
|
|
|
|
setTheme(theme);
|
2017-01-24 06:08:21 +00:00
|
|
|
|
|
2017-02-15 20:32:15 +00:00
|
|
|
|
if (persist) {
|
2018-06-25 17:42:50 +00:00
|
|
|
|
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
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
|
show(currentTabIndex = 0) {
|
|
|
|
|
this.setState({ currentTabIndex });
|
2016-11-16 17:18:39 +00:00
|
|
|
|
this.modal.show();
|
2016-07-19 04:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
|
hide() {
|
2016-11-16 17:18:39 +00:00
|
|
|
|
this.modal.hide();
|
2016-08-17 20:58:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
|
render() {
|
|
|
|
|
const { settings } = this.props;
|
|
|
|
|
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">
|
2018-06-25 17:42:50 +00:00
|
|
|
|
– v{getAppVersion()}
|
2017-07-21 18:59:17 +00:00
|
|
|
|
<Tooltip position="bottom" message={Curl.getVersion()}>
|
2018-06-25 17:42:50 +00:00
|
|
|
|
<i className="fa fa-info-circle" />
|
2017-07-21 18:59:17 +00:00
|
|
|
|
</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>
|
2018-12-12 15:35:44 +00:00
|
|
|
|
<Tab tabIndex="-1">
|
2018-06-25 17:42:50 +00:00
|
|
|
|
<Button value="General">General</Button>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</Tab>
|
2018-12-12 15:35:44 +00:00
|
|
|
|
<Tab tabIndex="-1">
|
2018-06-25 17:42:50 +00:00
|
|
|
|
<Button value="Import/Export">Data</Button>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</Tab>
|
2018-12-12 15:35:44 +00:00
|
|
|
|
<Tab tabIndex="-1">
|
2018-06-25 17:42:50 +00:00
|
|
|
|
<Button value="Themes">Themes</Button>
|
2017-01-20 21:54:03 +00:00
|
|
|
|
</Tab>
|
2018-12-12 15:35:44 +00:00
|
|
|
|
<Tab tabIndex="-1">
|
2018-06-25 17:42:50 +00:00
|
|
|
|
<Button value="Shortcuts">Keyboard</Button>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</Tab>
|
2018-12-12 15:35:44 +00:00
|
|
|
|
<Tab tabIndex="-1">
|
2018-06-25 17:42:50 +00:00
|
|
|
|
<Button value="Account">Account</Button>
|
2017-03-29 02:21:49 +00:00
|
|
|
|
</Tab>
|
2018-12-12 15:35:44 +00:00
|
|
|
|
<Tab tabIndex="-1">
|
2018-06-25 17:42:50 +00:00
|
|
|
|
<Button value="Plugins">Plugins</Button>
|
2017-06-01 02:04:27 +00:00
|
|
|
|
</Tab>
|
2018-12-12 15:35:44 +00:00
|
|
|
|
<Tab tabIndex="-1">
|
2018-06-25 17:42:50 +00:00
|
|
|
|
<Button value="About">About</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}
|
2018-10-17 17:26:19 +00:00
|
|
|
|
handleRootCssChange={this._handleRootCssChange}
|
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">
|
2018-10-17 16:42:33 +00:00
|
|
|
|
<Theme handleChangeTheme={this._handleChangeTheme} activeTheme={settings.theme} />
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</TabPanel>
|
2018-06-25 17:42:50 +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
|
2018-12-12 17:36:11 +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;
|