import PropTypes from 'prop-types' import React from 'react' import { connect } from 'react-redux' import HotkeyTab from './HotkeyTab' import UiTab from './UiTab' import InfoTab from './InfoTab' import Crowdfunding from './Crowdfunding' import StoragesTab from './StoragesTab' import SnippetTab from './SnippetTab' import Blog from './Blog' import ModalEscButton from 'browser/components/ModalEscButton' import CSSModules from 'browser/lib/CSSModules' import styles from './PreferencesModal.styl' import RealtimeNotification from 'browser/components/RealtimeNotification' import _ from 'lodash' import i18n from 'browser/lib/i18n' class Preferences extends React.Component { constructor (props) { super(props) this.state = { currentTab: 'STORAGES', UIAlert: '', HotkeyAlert: '', BlogAlert: '' } } componentDidMount () { this.refs.root.focus() const boundingBox = this.getContentBoundingBox() this.setState({ boundingBox }) } switchTeam (teamId) { this.setState({currentTeamId: teamId}) } handleNavButtonClick (tab) { return (e) => { this.setState({currentTab: tab}) } } handleEscButtonClick () { this.props.close() } renderContent () { const { boundingBox } = this.state const { dispatch, config, data } = this.props switch (this.state.currentTab) { case 'INFO': return ( ) case 'HOTKEY': return ( this.setState({HotkeyAlert: alert})} /> ) case 'UI': return ( this.setState({UIAlert: alert})} /> ) case 'CROWDFUNDING': return ( ) case 'BLOG': return ( this.setState({BlogAlert: alert})} /> ) case 'SNIPPET': return ( ) case 'STORAGES': default: return ( ) } } handleKeyDown (e) { if (e.keyCode === 27) { this.props.close() } } getContentBoundingBox () { return this.refs.content.getBoundingClientRect() } haveToSaveNotif (type, message) { return (

{message}

) } render () { const content = this.renderContent() const tabs = [ {target: 'STORAGES', label: i18n.__('Storage')}, {target: 'HOTKEY', label: i18n.__('Hotkeys'), Hotkey: this.state.HotkeyAlert}, {target: 'UI', label: i18n.__('Interface'), UI: this.state.UIAlert}, {target: 'INFO', label: i18n.__('About')}, {target: 'CROWDFUNDING', label: i18n.__('Crowdfunding')}, {target: 'BLOG', label: i18n.__('Blog'), Blog: this.state.BlogAlert}, {target: 'SNIPPET', label: i18n.__('Snippets')} ] const navButtons = tabs.map((tab) => { const isActive = this.state.currentTab === tab.target const isUiHotkeyTab = _.isObject(tab[tab.label]) && tab.label === tab[tab.label].tab return ( ) }) return (
this.handleKeyDown(e)} >

{i18n.__('Your preferences for Boostnote')}

this.handleEscButtonClick(e)} />
{navButtons}
{content}
) } } Preferences.propTypes = { dispatch: PropTypes.func } export default connect((x) => x)(CSSModules(Preferences, styles))