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

153 lines
5.0 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';
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 SettingsSync from '../settings/SettingsSync';
2016-11-10 05:56:23 +00:00
import * as models from '../../../models';
2016-11-10 02:40:53 +00:00
import {getAppVersion, getAppLongName} from '../../../common/constants';
import * as session from '../../../sync/session';
import {showModal} from './index';
import SignupModal from './SignupModal';
import * as sync from '../../../sync';
2016-11-11 01:36:23 +00:00
import {trackEvent} from '../../../analytics/index';
2016-05-07 17:29:24 +00:00
export const TAB_INDEX_EXPORT = 1;
export const TAB_PLUS = 3;
class SettingsModal extends Component {
constructor (props) {
super(props);
this._currentTabIndex = -1;
this.state = {}
}
show (currentTabIndex = 0) {
this.setState({currentTabIndex});
this.modal.show();
}
hide () {
this.modal.hide();
}
toggle (currentTabIndex = 0) {
this.setState({currentTabIndex});
this.modal.toggle();
}
_handleTabSelect (currentTabIndex) {
this.setState({currentTabIndex});
2016-08-15 22:31:30 +00:00
}
2016-11-11 01:36:23 +00:00
async _handleSyncReset () {
this.modal.hide();
2016-11-11 01:36:23 +00:00
trackEvent('Sync', 'Reset');
await sync.resetRemoteData();
await sync.resetLocalData();
2016-11-18 00:05:00 +00:00
await sync.logout();
2016-11-11 01:36:23 +00:00
}
render () {
const {
settings,
handleExportAllToFile,
handleExportWorkspaceToFile,
handleImportFile,
} = this.props;
2016-07-21 16:33:35 +00:00
const {currentTabIndex} = this.state;
2016-05-07 17:29:24 +00:00
return (
<Modal ref={m => this.modal = m} tall={true} {...this.props}>
2016-07-19 22:28:29 +00:00
<ModalHeader>
2016-07-21 22:26:51 +00:00
{getAppLongName()}
&nbsp;&nbsp;
<span className="faint txt-sm">v{getAppVersion()}</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}>
<Tabs onSelect={i => this._handleTabSelect(i)} selectedIndex={currentTabIndex}>
<TabList>
<Tab selected={this._currentTabIndex === 0}>
<button onClick={e => trackEvent('Setting', 'Tab General')}>General</button>
</Tab>
<Tab selected={this._currentTabIndex === 1}>
<button onClick={e => trackEvent('Setting', 'Tab Import/Export')}>Import/Export</button>
</Tab>
<Tab selected={this._currentTabIndex === 3}>
<button onClick={e => trackEvent('Setting', 'Tab Shortcuts')}>Shortcuts</button>
</Tab>
<Tab selected={this._currentTabIndex === 2}>
<button onClick={e => trackEvent('Setting', 'Tab Plus')}>Insomnia Plus</button>
</Tab>
<Tab selected={this._currentTabIndex === 4}>
<button onClick={e => trackEvent('Setting', 'Tab About')}>About</button>
</Tab>
</TabList>
<TabPanel className="pad scrollable">
<SettingsGeneral
settings={settings}
updateSetting={(key, value) => {
models.settings.update(settings, {[key]: value});
trackEvent('Setting', 'Change', key)
}}
/>
</TabPanel>
<TabPanel className="pad scrollable">
<SettingsImportExport
handleExportAll={() => {
handleExportAllToFile();
this.modal.hide()
}}
handleExportWorkspace={() => {
handleExportWorkspaceToFile();
this.modal.hide()
}}
handleImport={() => {
handleImportFile();
this.modal.hide()
}}
/>
</TabPanel>
<TabPanel className="pad scrollable">
<SettingsShortcuts />
</TabPanel>
<TabPanel className="pad scrollable">
<SettingsSync
loggedIn={session.isLoggedIn()}
firstName={session.getFirstName() || ''}
handleExit={() => this.modal.hide()}
handleUpdateSetting={(key, value) => models.settings.update(settings, {[key]: value})}
handleShowSignup={() => showModal(SignupModal)}
handleCancelAccount={sync.cancelAccount}
handleReset={() => this._handleSyncReset()}
handleLogout={sync.logout}
/>
</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;