diff --git a/browser/lib/newNote.js b/browser/lib/newNote.js new file mode 100644 index 00000000..d9834dec --- /dev/null +++ b/browser/lib/newNote.js @@ -0,0 +1,62 @@ +import { hashHistory } from 'react-router' +import dataApi from 'browser/main/lib/dataApi' +import ee from 'browser/main/lib/eventEmitter' +import AwsMobileAnalyticsConfig from 'browser/main/lib/AwsMobileAnalyticsConfig' + +export function createMarkdownNote (storage, folder, dispatch, location) { + AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_MARKDOWN') + AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_ALLNOTE') + return dataApi + .createNote(storage, { + type: 'MARKDOWN_NOTE', + folder: folder, + title: '', + content: '' + }) + .then(note => { + const noteHash = note.key + dispatch({ + type: 'UPDATE_NOTE', + note: note + }) + + hashHistory.push({ + pathname: location.pathname, + query: { key: noteHash } + }) + ee.emit('list:jump', noteHash) + ee.emit('detail:focus') + }) +} + +export function createSnippetNote (storage, folder, dispatch, location, config) { + AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_SNIPPET') + AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_ALLNOTE') + return dataApi + .createNote(storage, { + type: 'SNIPPET_NOTE', + folder: folder, + title: '', + description: '', + snippets: [ + { + name: '', + mode: config.editor.snippetDefaultLanguage || 'text', + content: '' + } + ] + }) + .then(note => { + const noteHash = note.key + dispatch({ + type: 'UPDATE_NOTE', + note: note + }) + hashHistory.push({ + pathname: location.pathname, + query: { key: noteHash } + }) + ee.emit('list:jump', noteHash) + ee.emit('detail:focus') + }) +} \ No newline at end of file diff --git a/browser/main/NewNoteButton/index.js b/browser/main/NewNoteButton/index.js index 85dc7f40..85fbbfbf 100644 --- a/browser/main/NewNoteButton/index.js +++ b/browser/main/NewNoteButton/index.js @@ -7,6 +7,7 @@ import modal from 'browser/main/lib/modal' import NewNoteModal from 'browser/main/modals/NewNoteModal' import eventEmitter from 'browser/main/lib/eventEmitter' import i18n from 'browser/lib/i18n' +import { createMarkdownNote, createSnippetNote } from 'browser/lib/newNote' const { remote } = require('electron') const { dialog } = remote @@ -37,13 +38,21 @@ class NewNoteButton extends React.Component { const { location, dispatch, config } = this.props const { storage, folder } = this.resolveTargetFolder() - modal.open(NewNoteModal, { - storage: storage.key, - folder: folder.key, - dispatch, - location, - config - }) + console.log(config) + + if (config.ui.defaultNote === 'MARKDOWN_NOTE') { + createMarkdownNote(storage.key, folder.key, dispatch, location) + } else if (config.ui.defaultNote === 'SNIPPET_NOTE') { + createSnippetNote(storage.key, folder.key, dispatch, location, config) + } else { + modal.open(NewNoteModal, { + storage: storage.key, + folder: folder.key, + dispatch, + location, + config + }) + } } resolveTargetFolder () { diff --git a/browser/main/modals/NewNoteModal.js b/browser/main/modals/NewNoteModal.js index f6aa2c67..8b16f2a2 100644 --- a/browser/main/modals/NewNoteModal.js +++ b/browser/main/modals/NewNoteModal.js @@ -1,12 +1,9 @@ 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' import i18n from 'browser/lib/i18n' +import { createMarkdownNote, createSnippetNote } from 'browser/lib/newNote' class NewNoteModal extends React.Component { constructor (props) { @@ -24,31 +21,10 @@ class NewNoteModal extends React.Component { } 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 => { - const noteHash = note.key - dispatch({ - type: 'UPDATE_NOTE', - note: note - }) - - hashHistory.push({ - pathname: location.pathname, - query: { key: noteHash } - }) - ee.emit('list:jump', noteHash) - ee.emit('detail:focus') - setTimeout(this.props.close, 200) - }) + createMarkdownNote(storage, folder, dispatch, location).then(() => { + setTimeout(this.props.close, 200) + }) } handleMarkdownNoteButtonKeyDown (e) { @@ -59,38 +35,10 @@ class NewNoteModal extends React.Component { } handleSnippetNoteButtonClick (e) { - AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_SNIPPET') - AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_ALLNOTE') const { storage, folder, dispatch, location, config } = this.props - - dataApi - .createNote(storage, { - type: 'SNIPPET_NOTE', - folder: folder, - title: '', - description: '', - snippets: [ - { - name: '', - mode: config.editor.snippetDefaultLanguage || 'text', - content: '' - } - ] - }) - .then(note => { - const noteHash = note.key - dispatch({ - type: 'UPDATE_NOTE', - note: note - }) - hashHistory.push({ - pathname: location.pathname, - query: { key: noteHash } - }) - ee.emit('list:jump', noteHash) - ee.emit('detail:focus') - setTimeout(this.props.close, 200) - }) + createSnippetNote(storage, folder, dispatch, location, config).then(() => { + setTimeout(this.props.close, 200) + }) } handleSnippetNoteButtonKeyDown (e) { diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index 74047d44..6661d95d 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -67,6 +67,7 @@ class UiTab extends React.Component { ui: { theme: this.refs.uiTheme.value, language: this.refs.uiLanguage.value, + defaultNote: this.refs.defaultNote.value, showCopyNotification: this.refs.showCopyNotification.checked, confirmDeletion: this.refs.confirmDeletion.checked, showOnlyRelatedTags: this.refs.showOnlyRelatedTags.checked, @@ -202,6 +203,22 @@ class UiTab extends React.Component { +