insomnia/app/ui/components/modals/SettingsModal.js

166 lines
5.1 KiB
JavaScript
Raw Normal View History

import React, {Component, PropTypes} from 'react';
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
import {shell} from 'electron';
import Modal from '../base/Modal';
2017-02-13 08:12:02 +00:00
import Button from '../base/Button';
import ModalBody from '../base/ModalBody';
import ModalHeader from '../base/ModalHeader';
import SettingsShortcuts from '../settings/SettingsShortcuts';
import SettingsAbout from '../settings/SettingsAbout';
import SettingsGeneral from '../settings/SettingsGeneral';
import SettingsImportExport from '../settings/SettingsImportExport';
import SettingsTheme from '../settings/SettingsTheme';
2017-01-20 17:51:18 +00:00
import * as models from '../../../models/index';
import {getAppVersion, getAppName} from '../../../common/constants';
2016-11-11 01:36:23 +00:00
import {trackEvent} from '../../../analytics/index';
import * as session from '../../../sync/session';
2016-05-07 17:29:24 +00:00
export const TAB_INDEX_EXPORT = 1;
class SettingsModal extends Component {
constructor (props) {
super(props);
this._currentTabIndex = -1;
this.state = {}
}
2017-02-13 08:12:02 +00:00
_setModalRef = m => this.modal = m;
_trackTab = name => trackEvent('Setting', `Tab ${name}`);
_handleTabSelect = currentTabIndex => this.setState({currentTabIndex});
_handleUpdateSetting = (key, value) => {
models.settings.update(this.props.settings, {[key]: value});
trackEvent('Setting', 'Change', key)
};
_handleExportAllToFile = () => {
this.props.handleExportAllToFile();
this.modal.hide()
};
_handleExportWorkspace = () => {
this.props.handleExportWorkspaceToFile();
this.modal.hide()
};
_handleImport = () => {
this.props.handleImportFile();
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 (
2017-02-13 08:12:02 +00:00
<Modal ref={this._setModalRef} tall={true} {...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()}
{email ? ` ${email}` : null}
</span>
2016-07-19 22:28:29 +00:00
</ModalHeader>
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
<ModalBody noScroll={true}>
2017-02-13 08:12:02 +00:00
<Tabs onSelect={this._handleTabSelect} selectedIndex={currentTabIndex}>
<TabList>
<Tab selected={this._currentTabIndex === 0}>
2017-02-13 08:12:02 +00:00
<Button value="General" onClick={this._trackTab}>
General
2017-02-13 08:12:02 +00:00
</Button>
</Tab>
<Tab selected={this._currentTabIndex === 1}>
2017-02-13 08:12:02 +00:00
<Button value="Import/Export" onClick={this._trackTab}>
Import/Export
2017-02-13 08:12:02 +00:00
</Button>
</Tab>
<Tab selected={this._currentTabIndex === 2}>
2017-02-13 08:12:02 +00:00
<Button value="Themes" onClick={this._trackTab}>
2017-01-23 22:41:31 +00:00
Themes
2017-02-13 08:12:02 +00:00
</Button>
</Tab>
<Tab selected={this._currentTabIndex === 3}>
2017-02-13 08:12:02 +00:00
<Button value="shortcuts" onClick={this._trackTab}>
Shortcuts
2017-02-13 08:12:02 +00:00
</Button>
</Tab>
2017-02-13 08:12:02 +00:00
<Tab selected={this._currentTabIndex === 4}>
<Button value="About" onClick={this._trackTab}>
About
2017-02-13 08:12:02 +00:00
</Button>
</Tab>
</TabList>
<TabPanel className="pad scrollable">
<SettingsGeneral
settings={settings}
2017-02-13 08:12:02 +00:00
updateSetting={this._handleUpdateSetting}
/>
</TabPanel>
<TabPanel className="pad scrollable">
<SettingsImportExport
2017-02-13 08:12:02 +00:00
handleExportAll={this._handleExportAllToFile}
handleExportWorkspace={this._handleExportWorkspace}
handleImport={this._handleImport}
/>
</TabPanel>
<TabPanel className="pad scrollable">
<SettingsTheme
handleChangeTheme={this._handleChangeTheme}
activeTheme={settings.theme}
/>
</TabPanel>
<TabPanel className="pad scrollable">
<SettingsShortcuts />
</TabPanel>
<TabPanel className="pad scrollable">
<SettingsAbout/>
</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,
// Properties
settings: PropTypes.object.isRequired,
};
2016-05-07 17:29:24 +00:00
export default SettingsModal;