2016-07-19 04:01:31 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-09-03 05:14:48 +00:00
|
|
|
import {connect} from 'react-redux';
|
2016-07-19 04:01:31 +00:00
|
|
|
import {bindActionCreators} from 'redux';
|
2016-09-03 05:14:48 +00:00
|
|
|
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
|
2016-07-16 02:06:10 +00:00
|
|
|
import {shell} from 'electron';
|
2016-07-22 22:27:04 +00:00
|
|
|
import Modal from '../base/Modal';
|
|
|
|
import ModalBody from '../base/ModalBody';
|
|
|
|
import ModalHeader from '../base/ModalHeader';
|
|
|
|
import ModalFooter from '../base/ModalFooter';
|
2016-11-07 20:24:38 +00:00
|
|
|
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-07-22 22:27:04 +00:00
|
|
|
import * as GlobalActions from '../../redux/modules/global';
|
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';
|
2016-11-09 03:18:25 +00:00
|
|
|
import * as session from '../../../sync/session';
|
2016-11-07 20:24:38 +00:00
|
|
|
import {showModal} from './index';
|
|
|
|
import SignupModal from './SignupModal';
|
2016-11-09 03:18:25 +00:00
|
|
|
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
|
|
|
|
2016-07-19 04:01:31 +00:00
|
|
|
|
|
|
|
class SettingsTabs extends Component {
|
2016-08-17 20:58:44 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this._currentTabIndex = -1;
|
|
|
|
this._currentVersion = null;
|
2016-10-21 17:20:36 +00:00
|
|
|
this.state = {
|
|
|
|
showSyncSetting: false
|
|
|
|
}
|
2016-08-17 20:58:44 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 04:01:31 +00:00
|
|
|
_importFile () {
|
|
|
|
const workspace = this._getActiveWorkspace(this.props);
|
|
|
|
this.props.actions.global.importFile(workspace);
|
2016-07-22 17:02:42 +00:00
|
|
|
this.props.hide();
|
2016-07-19 04:01:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 20:58:44 +00:00
|
|
|
_handleTabSelect (selectedIndex) {
|
|
|
|
this._currentTabIndex = selectedIndex;
|
|
|
|
}
|
|
|
|
|
2016-08-15 22:31:30 +00:00
|
|
|
_exportAll () {
|
2016-07-19 04:01:31 +00:00
|
|
|
this.props.actions.global.exportFile();
|
2016-07-22 17:02:42 +00:00
|
|
|
this.props.hide();
|
2016-07-19 04:01:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 22:31:30 +00:00
|
|
|
_exportWorkspace () {
|
|
|
|
this.props.actions.global.exportFile(this._getActiveWorkspace());
|
|
|
|
this.props.hide();
|
|
|
|
}
|
|
|
|
|
2016-11-11 01:36:23 +00:00
|
|
|
async _handleSyncReset () {
|
|
|
|
this.props.hide();
|
|
|
|
trackEvent('Sync', 'Reset');
|
|
|
|
await sync.resetRemoteData();
|
|
|
|
await sync.resetLocalData();
|
|
|
|
await session.logout();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-19 04:01:31 +00:00
|
|
|
_getActiveWorkspace (props) {
|
|
|
|
// TODO: Factor this out into a selector
|
|
|
|
|
2016-10-21 17:20:36 +00:00
|
|
|
const {entities, global} = props || this.props;
|
|
|
|
let workspace = entities.workspaces[global.activeWorkspaceId];
|
2016-07-19 04:01:31 +00:00
|
|
|
if (!workspace) {
|
|
|
|
workspace = entities.workspaces[Object.keys(entities.workspaces)[0]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return workspace;
|
|
|
|
}
|
|
|
|
|
2016-08-17 20:58:44 +00:00
|
|
|
componentWillReceiveProps ({selectedIndex, version}) {
|
|
|
|
if (this._currentVersion !== version) {
|
|
|
|
this._currentTabIndex = selectedIndex;
|
|
|
|
this._currentVersion = version;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 04:01:31 +00:00
|
|
|
render () {
|
2016-11-07 20:24:38 +00:00
|
|
|
const {entities, hide} = this.props;
|
2016-07-19 19:13:51 +00:00
|
|
|
const settings = entities.settings[Object.keys(entities.settings)[0]];
|
|
|
|
|
2016-07-19 04:01:31 +00:00
|
|
|
return (
|
2016-09-03 05:14:48 +00:00
|
|
|
<Tabs onSelect={i => this._handleTabSelect(i)}
|
|
|
|
selectedIndex={this._currentTabIndex}>
|
2016-07-19 04:01:31 +00:00
|
|
|
<TabList>
|
2016-08-17 20:58:44 +00:00
|
|
|
<Tab selected={this._currentTabIndex === 0}>
|
2016-07-19 04:01:31 +00:00
|
|
|
<button>General</button>
|
|
|
|
</Tab>
|
2016-08-17 20:58:44 +00:00
|
|
|
<Tab selected={this._currentTabIndex === 1}>
|
2016-11-07 20:24:38 +00:00
|
|
|
<button>Import/Export</button>
|
2016-08-15 17:04:36 +00:00
|
|
|
</Tab>
|
2016-08-17 20:58:44 +00:00
|
|
|
<Tab selected={this._currentTabIndex === 2}>
|
2016-11-07 20:24:38 +00:00
|
|
|
<button>Cloud Sync</button>
|
2016-07-19 04:01:31 +00:00
|
|
|
</Tab>
|
2016-08-17 20:58:44 +00:00
|
|
|
<Tab selected={this._currentTabIndex === 3}>
|
2016-07-21 22:13:57 +00:00
|
|
|
<button>Shortcuts</button>
|
2016-07-19 04:01:31 +00:00
|
|
|
</Tab>
|
2016-08-17 20:58:44 +00:00
|
|
|
<Tab selected={this._currentTabIndex === 4}>
|
2016-07-19 22:28:29 +00:00
|
|
|
<button>About</button>
|
2016-07-19 04:01:31 +00:00
|
|
|
</Tab>
|
|
|
|
</TabList>
|
2016-10-21 17:20:36 +00:00
|
|
|
<TabPanel className="pad scrollable">
|
2016-11-07 20:24:38 +00:00
|
|
|
<SettingsGeneral
|
|
|
|
settings={settings}
|
2016-11-10 01:15:27 +00:00
|
|
|
updateSetting={(key, value) => models.settings.update(settings, {[key]: value})}
|
2016-11-07 20:24:38 +00:00
|
|
|
/>
|
2016-08-15 17:04:36 +00:00
|
|
|
</TabPanel>
|
2016-10-21 17:20:36 +00:00
|
|
|
<TabPanel className="pad scrollable">
|
2016-11-07 20:24:38 +00:00
|
|
|
<SettingsImportExport
|
|
|
|
exportAll={this._exportAll.bind(this)}
|
|
|
|
exportWorkspace={this._exportWorkspace.bind(this)}
|
|
|
|
importFile={this._importFile.bind(this)}
|
|
|
|
/>
|
2016-07-19 04:01:31 +00:00
|
|
|
</TabPanel>
|
2016-10-21 17:20:36 +00:00
|
|
|
<TabPanel className="pad scrollable">
|
2016-11-07 20:24:38 +00:00
|
|
|
<SettingsSync
|
|
|
|
loggedIn={session.isLoggedIn()}
|
|
|
|
firstName={session.getFirstName() || ''}
|
|
|
|
handleExit={hide}
|
2016-11-10 01:15:27 +00:00
|
|
|
handleUpdateSetting={(key, value) => models.settings.update(settings, {[key]: value})}
|
2016-11-07 20:24:38 +00:00
|
|
|
handleShowSignup={() => showModal(SignupModal)}
|
|
|
|
handleCancelAccount={sync.cancelAccount}
|
2016-11-11 01:36:23 +00:00
|
|
|
handleReset={() => this._handleSyncReset()}
|
2016-11-07 20:24:38 +00:00
|
|
|
handleLogout={sync.logout}
|
|
|
|
/>
|
2016-07-19 04:01:31 +00:00
|
|
|
</TabPanel>
|
2016-10-21 17:20:36 +00:00
|
|
|
<TabPanel className="pad scrollable">
|
2016-11-07 20:24:38 +00:00
|
|
|
<SettingsShortcuts />
|
2016-07-19 04:01:31 +00:00
|
|
|
</TabPanel>
|
2016-10-21 17:20:36 +00:00
|
|
|
<TabPanel className="pad scrollable">
|
2016-11-07 20:24:38 +00:00
|
|
|
<SettingsAbout/>
|
2016-07-19 04:01:31 +00:00
|
|
|
</TabPanel>
|
|
|
|
</Tabs>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SettingsTabs.propTypes = {
|
2016-10-21 17:20:36 +00:00
|
|
|
global: PropTypes.shape({
|
|
|
|
activeWorkspaceId: PropTypes.string
|
2016-07-19 04:01:31 +00:00
|
|
|
}),
|
|
|
|
entities: PropTypes.shape({
|
2016-07-19 19:13:51 +00:00
|
|
|
workspaces: PropTypes.object.isRequired,
|
|
|
|
settings: PropTypes.object.isRequired
|
2016-07-19 04:01:31 +00:00
|
|
|
}).isRequired,
|
|
|
|
actions: PropTypes.shape({
|
|
|
|
global: PropTypes.shape({
|
|
|
|
importFile: PropTypes.func.isRequired,
|
|
|
|
exportFile: PropTypes.func.isRequired,
|
|
|
|
})
|
2016-07-21 16:33:35 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
// Optional
|
2016-08-17 20:58:44 +00:00
|
|
|
selectedIndex: PropTypes.number,
|
|
|
|
version: PropTypes.number
|
2016-07-19 04:01:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
2016-10-21 17:20:36 +00:00
|
|
|
global: state.global,
|
2016-07-19 04:01:31 +00:00
|
|
|
entities: state.entities,
|
2016-11-07 20:24:38 +00:00
|
|
|
actions: state.actions
|
2016-07-19 04:01:31 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
|
|
|
actions: {
|
|
|
|
global: bindActionCreators(GlobalActions, dispatch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: We can't _connect_ the SettingsModal because it hides the public methods
|
|
|
|
const ConnectedSettingsTabs = connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(SettingsTabs);
|
|
|
|
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
class SettingsModal extends Component {
|
2016-07-21 16:33:35 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2016-08-17 20:58:44 +00:00
|
|
|
version: 0,
|
|
|
|
selectedIndex: -1
|
2016-07-21 16:33:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 22:31:30 +00:00
|
|
|
_setIndex (selectedIndex) {
|
2016-08-17 20:58:44 +00:00
|
|
|
const version = this.state.version + 1;
|
|
|
|
this.setState({selectedIndex, version});
|
2016-07-21 16:33:35 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
show (selectedIndex = 0) {
|
|
|
|
this.modal.show();
|
|
|
|
this._setIndex(selectedIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggle (selectedIndex = 0) {
|
|
|
|
this.modal.toggle();
|
|
|
|
this._setIndex(selectedIndex);
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
render () {
|
2016-08-17 20:58:44 +00:00
|
|
|
const {selectedIndex, version} = this.state;
|
2016-07-19 04:01:31 +00:00
|
|
|
|
2016-05-07 17:29:24 +00:00
|
|
|
return (
|
2016-08-15 17:04:36 +00:00
|
|
|
<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()}
|
|
|
|
|
|
|
|
<span className="faint txt-sm">v{getAppVersion()}</span>
|
2016-07-19 22:28:29 +00:00
|
|
|
</ModalHeader>
|
2016-10-21 17:20:36 +00:00
|
|
|
<ModalBody noScroll={true}>
|
2016-08-17 20:58:44 +00:00
|
|
|
<ConnectedSettingsTabs
|
|
|
|
version={version}
|
|
|
|
hide={() => this.modal.hide()}
|
|
|
|
selectedIndex={selectedIndex}
|
|
|
|
/>
|
2016-05-07 17:29:24 +00:00
|
|
|
</ModalBody>
|
2016-08-15 17:04:36 +00:00
|
|
|
<ModalFooter>
|
2016-10-21 17:20:36 +00:00
|
|
|
<button className="btn" onClick={() => this.modal.hide()}>
|
2016-09-03 05:14:48 +00:00
|
|
|
Done
|
|
|
|
</button>
|
2016-07-07 20:10:55 +00:00
|
|
|
</ModalFooter>
|
2016-05-07 17:29:24 +00:00
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export default SettingsModal;
|