insomnia/packages/insomnia-app/app/ui/components/modals/settings-modal.js

171 lines
5.3 KiB
JavaScript
Raw Normal View History

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';
import autobind from 'autobind-decorator';
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';
import Plugins from '../settings/plugins';
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';
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
export const TAB_INDEX_EXPORT = 1;
export const TAB_INDEX_SHORTCUTS = 3;
@autobind
class SettingsModal extends PureComponent {
2018-06-25 17:42:50 +00:00
constructor(props) {
super(props);
this.state = {};
}
2018-06-25 17:42:50 +00:00
_setModalRef(n) {
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-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();
this.modal.hide();
}
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();
this.modal.hide();
}
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();
this.modal.hide();
}
2017-02-13 08:12:02 +00:00
2018-06-25 17:42:50 +00:00
_handleImportUri(uri) {
this.props.handleImportUri(uri);
this.modal.hide();
}
async _handleChangeTheme(theme, persist = true) {
2018-07-18 00:48:10 +00:00
setTheme(theme);
2017-01-24 06:08:21 +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
}
}
2018-06-25 17:42:50 +00:00
show(currentTabIndex = 0) {
this.setState({ currentTabIndex });
this.modal.show();
}
2018-06-25 17:42:50 +00:00
hide() {
this.modal.hide();
}
2018-06-25 17:42:50 +00:00
render() {
const { settings } = this.props;
const { currentTabIndex } = this.state;
const email = session.isLoggedIn() ? session.getEmail() : null;
2016-05-07 17:29:24 +00:00
return (
<Modal ref={this._setModalRef} tall freshState {...this.props}>
2016-07-19 22:28:29 +00:00
<ModalHeader>
{getAppName()} Preferences
<span className="faint txt-sm">
2018-06-25 17:42:50 +00:00
&nbsp;&nbsp;&nbsp; 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}
</span>
2016-07-19 22:28:29 +00:00
</ModalHeader>
<ModalBody noScroll>
2017-08-10 01:56:27 +00:00
<Tabs className="react-tabs" defaultIndex={currentTabIndex}>
<TabList>
<Tab tabIndex="-1">
2018-06-25 17:42:50 +00:00
<Button value="General">General</Button>
</Tab>
<Tab tabIndex="-1">
2018-06-25 17:42:50 +00:00
<Button value="Import/Export">Data</Button>
</Tab>
<Tab tabIndex="-1">
2018-06-25 17:42:50 +00:00
<Button value="Themes">Themes</Button>
</Tab>
<Tab tabIndex="-1">
2018-06-25 17:42:50 +00:00
<Button value="Shortcuts">Keyboard</Button>
</Tab>
<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>
<Tab tabIndex="-1">
2018-06-25 17:42:50 +00:00
<Button value="Plugins">Plugins</Button>
</Tab>
<Tab tabIndex="-1">
2018-06-25 17:42:50 +00:00
<Button value="About">About</Button>
</Tab>
</TabList>
2017-08-10 01:56:27 +00:00
<TabPanel className="react-tabs__tab-panel pad scrollable">
<General
settings={settings}
handleToggleMenuBar={this.props.handleToggleMenuBar}
2017-02-13 08:12:02 +00:00
updateSetting={this._handleUpdateSetting}
handleRootCssChange={this._handleRootCssChange}
/>
</TabPanel>
2017-08-10 01:56:27 +00:00
<TabPanel className="react-tabs__tab-panel pad scrollable">
<ImportExport
2017-02-13 08:12:02 +00:00
handleExportAll={this._handleExportAllToFile}
handleExportWorkspace={this._handleExportWorkspace}
handleImportFile={this._handleImportFile}
handleImportUri={this._handleImportUri}
/>
</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} />
</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>
</Tabs>
2016-05-07 17:29:24 +00:00
</ModalBody>
</Modal>
);
}
}
SettingsModal.propTypes = {
// Functions
handleExportWorkspaceToFile: PropTypes.func.isRequired,
handleExportAllToFile: PropTypes.func.isRequired,
handleImportFile: PropTypes.func.isRequired,
handleImportUri: PropTypes.func.isRequired,
handleToggleMenuBar: PropTypes.func.isRequired,
// Properties
settings: PropTypes.object.isRequired,
};
2016-05-07 17:29:24 +00:00
export default SettingsModal;