import React from 'react' import CSSModules from 'browser/lib/CSSModules' import styles from './NewNoteModal.styl' import ModalEscButton from 'browser/components/ModalEscButton' import i18n from 'browser/lib/i18n' import { openModal } from 'browser/main/lib/modal' import CreateMarkdownFromURLModal from '../modals/CreateMarkdownFromURLModal' import { createMarkdownNote, createSnippetNote } from 'browser/lib/newNote' import queryString from 'query-string' class NewNoteModal extends React.Component { constructor(props) { super(props) this.lock = false this.state = {} } componentDidMount() { this.refs.markdownButton.focus() } handleCloseButtonClick(e) { this.props.close() } handleCreateMarkdownFromUrlClick(e) { this.props.close() const { storage, folder, dispatch, location } = this.props openModal(CreateMarkdownFromURLModal, { storage: storage, folder: folder, dispatch, location }) } handleMarkdownNoteButtonClick(e) { const { storage, folder, dispatch, location, config } = this.props const params = location.search !== '' && queryString.parse(location.search) if (!this.lock) { this.lock = true createMarkdownNote( storage, folder, dispatch, location, params, config ).then(() => { setTimeout(this.props.close, 200) }) } } handleMarkdownNoteButtonKeyDown(e) { if (e.keyCode === 9) { e.preventDefault() this.refs.snippetButton.focus() } } handleSnippetNoteButtonClick(e) { const { storage, folder, dispatch, location, config } = this.props const params = location.search !== '' && queryString.parse(location.search) if (!this.lock) { this.lock = true createSnippetNote( storage, folder, dispatch, location, params, config ).then(() => { setTimeout(this.props.close, 200) }) } } handleSnippetNoteButtonKeyDown(e) { if (e.keyCode === 9) { e.preventDefault() this.refs.markdownButton.focus() } } handleKeyDown(e) { if (e.keyCode === 27) { this.props.close() } } render() { return (