import React, {Component, PropTypes} from 'react'; import {Tab, Tabs, TabList, TabPanel} from 'react-tabs'; import {shell} from 'electron'; import Modal from '../base/Modal'; 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'; import * as models from '../../../models/index'; import {getAppVersion, getAppName} from '../../../common/constants'; import {trackEvent} from '../../../analytics/index'; import * as session from '../../../sync/session'; export const TAB_INDEX_EXPORT = 1; class SettingsModal extends Component { constructor (props) { super(props); this._currentTabIndex = -1; this.state = {} } _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); if (persist) { trackEvent('Setting', 'Change Theme', theme); models.settings.update(this.props.settings, {theme}); } }; componentDidMount () { // Hacky way to set theme on launch // TODO: move somewhere else this._handleChangeTheme(this.props.settings.theme, false); } show (currentTabIndex = 0) { this.setState({currentTabIndex}); this.modal.show(); } hide () { this.modal.hide(); } toggle (currentTabIndex = 0) { this.setState({currentTabIndex}); this.modal.toggle(); } render () { const {settings} = this.props; const {currentTabIndex} = this.state; const email = session.isLoggedIn() ? session.getEmail() : null; return ( {getAppName()} Preferences   –  v{getAppVersion()} {email ? ` – ${email}` : null} ); } } SettingsModal.propTypes = { // Functions handleExportWorkspaceToFile: PropTypes.func.isRequired, handleExportAllToFile: PropTypes.func.isRequired, handleImportFile: PropTypes.func.isRequired, // Properties settings: PropTypes.object.isRequired, }; export default SettingsModal;