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

193 lines
5.7 KiB
JavaScript
Raw Normal View History

2017-08-10 01:56:27 +00:00
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
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';
2017-08-16 02:17:35 +00:00
import {Curl} from 'insomnia-node-libcurl';
import {getAppName, getAppVersion} from '../../../common/constants';
2016-11-11 01:36:23 +00:00
import {trackEvent} from '../../../analytics/index';
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
export const TAB_INDEX_EXPORT = 1;
export const TAB_INDEX_SHORTCUTS = 3;
@autobind
class SettingsModal extends PureComponent {
constructor (props) {
super(props);
this.state = {};
}
_setModalRef (n) {
this.modal = n;
}
_handleUpdateSetting (key, value) {
2017-02-13 08:12:02 +00:00
models.settings.update(this.props.settings, {[key]: value});
trackEvent('Setting', 'Change', key);
}
2017-02-13 08:12:02 +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
_handleExportWorkspace () {
2017-02-13 08:12:02 +00:00
this.props.handleExportWorkspaceToFile();
this.modal.hide();
}
2017-02-13 08:12:02 +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
_handleImportUri (uri) {
this.props.handleImportUri(uri);
this.modal.hide();
}
_handleChangeTheme (theme, persist = true) {
document.body.setAttribute('theme', theme);
2017-01-24 06:08:21 +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-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
}
show (currentTabIndex = 0) {
this.setState({currentTabIndex});
this.modal.show();
}
hide () {
this.modal.hide();
}
toggle (currentTabIndex = 0) {
this.setState({currentTabIndex});
this.modal.toggle();
}
render () {
2017-02-13 08:12:02 +00:00
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">
&nbsp;&nbsp;&nbsp;
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}
</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>
<Button value="General">
General
2017-02-13 08:12:02 +00:00
</Button>
</Tab>
<Tab>
<Button value="Import/Export">
Data
2017-02-13 08:12:02 +00:00
</Button>
</Tab>
<Tab>
<Button value="Themes">
2017-01-23 22:41:31 +00:00
Themes
2017-02-13 08:12:02 +00:00
</Button>
</Tab>
<Tab>
<Button value="Shortcuts">
Keyboard
2017-02-13 08:12:02 +00:00
</Button>
</Tab>
<Tab>
<Button value="Account">
2017-03-29 02:21:49 +00:00
Account
</Button>
</Tab>
<Tab>
<Button value="Plugins">
Plugins
</Button>
</Tab>
<Tab>
<Button value="About">
About
2017-02-13 08:12:02 +00:00
</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}
/>
</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">
<Theme
handleChangeTheme={this._handleChangeTheme}
activeTheme={settings.theme}
/>
</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>
</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;