import React from 'react' import CSSModules from 'browser/lib/CSSModules' import styles from './NewNoteModal.styl' import dataApi from 'browser/main/lib/dataApi' import { hashHistory } from 'react-router' import ee from 'browser/main/lib/eventEmitter' import ModalEscButton from 'browser/components/ModalEscButton' import AwsMobileAnalyticsConfig from 'browser/main/lib/AwsMobileAnalyticsConfig' class NewNoteModal extends React.Component { constructor (props) { super(props) this.state = { } } componentDidMount () { this.refs.markdownButton.focus() } handleCloseButtonClick (e) { this.props.close() } handleMarkdownNoteButtonClick (e) { AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_MARKDOWN') AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_ALLNOTE') const { storage, folder, dispatch, location } = this.props dataApi .createNote(storage, { type: 'MARKDOWN_NOTE', folder: folder, title: '', content: '' }) .then((note) => { dispatch({ type: 'UPDATE_NOTE', note: note }) hashHistory.push({ pathname: location.pathname, query: {key: note.storage + '-' + note.key} }) ee.emit('detail:focus') this.props.close() }) } handleMarkdownNoteButtonKeyDown (e) { if (e.keyCode === 9) { e.preventDefault() this.refs.snippetButton.focus() } } handleSnippetNoteButtonClick (e) { AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_SNIPPET') AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_ALLNOTE') const { storage, folder, dispatch, location } = this.props dataApi .createNote(storage, { type: 'SNIPPET_NOTE', folder: folder, title: '', description: '', snippets: [{ name: '', mode: 'text', content: '' }] }) .then((note) => { dispatch({ type: 'UPDATE_NOTE', note: note }) hashHistory.push({ pathname: location.pathname, query: {key: note.storage + '-' + note.key} }) ee.emit('detail:focus') this.props.close() }) } handleSnippetNoteButtonKeyDown (e) { if (e.keyCode === 9) { e.preventDefault() this.refs.markdownButton.focus() } } handleKeyDown (e) { if (e.keyCode === 27) { this.props.close() } } render () { return (
this.handleKeyDown(e)} >
Make a Note
this.handleCloseButtonClick(e)} />
Tab to switch format
) } } NewNoteModal.propTypes = { } export default CSSModules(NewNoteModal, styles)