diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index 9859716d..492ba7b3 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -9,7 +9,7 @@ import iconv from 'iconv-lite' import crypto from 'crypto' import consts from 'browser/lib/consts' import fs from 'fs' -const { ipcRenderer, remote } = require('electron') +const { ipcRenderer } = require('electron') CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js' @@ -201,11 +201,11 @@ export default class CodeEditor extends React.Component { for (let i = 0; i < snippets.length; i++) { if (snippets[i].prefix.indexOf(wordBeforeCursor.text) !== -1) { if (snippets[i].content.indexOf(templateCursorString) !== -1) { - let snippetLines = snippets[i].content.split('\n') + const snippetLines = snippets[i].content.split('\n') let cursorLineNumber = 0 let cursorLinePosition = 0 for (let j = 0; j < snippetLines.length; j++) { - let cursorIndex = snippetLines[j].indexOf(templateCursorString) + const cursorIndex = snippetLines[j].indexOf(templateCursorString) if (cursorIndex !== -1) { cursorLineNumber = j cursorLinePosition = cursorIndex diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index aa920975..55d85bea 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -393,7 +393,7 @@ export default class MarkdownPreview extends React.Component { value = value.replace(codeBlock, htmlTextHelper.encodeEntities(codeBlock)) }) } - let renderedHTML = this.markdown.render(value) + const renderedHTML = this.markdown.render(value) this.refs.root.contentWindow.document.body.innerHTML = attachmentManagement.fixLocalURLS(renderedHTML, storagePath) _.forEach(this.refs.root.contentWindow.document.querySelectorAll('a'), (el) => { diff --git a/browser/lib/consts.js b/browser/lib/consts.js index 3837ef44..e744e87a 100644 --- a/browser/lib/consts.js +++ b/browser/lib/consts.js @@ -2,7 +2,6 @@ const path = require('path') const fs = require('sander') const { remote } = require('electron') const { app } = remote -const os = require('os') const themePath = process.env.NODE_ENV === 'production' ? path.join(app.getAppPath(), './node_modules/codemirror/theme') diff --git a/browser/main/SideNav/index.js b/browser/main/SideNav/index.js index 6b53478e..0e6bb088 100644 --- a/browser/main/SideNav/index.js +++ b/browser/main/SideNav/index.js @@ -183,7 +183,7 @@ class SideNav extends React.Component { ).filter( note => activeTags.every(tag => note.tags.includes(tag)) ) - let relatedTags = new Set() + const relatedTags = new Set() relatedNotes.forEach(note => note.tags.map(tag => relatedTags.add(tag))) return relatedTags } @@ -222,7 +222,7 @@ class SideNav extends React.Component { handleClickNarrowToTag (tag) { const { router } = this.context const { location } = this.props - let listOfTags = this.getActiveTags(location.pathname) + const listOfTags = this.getActiveTags(location.pathname) const indexOfTag = listOfTags.indexOf(tag) if (indexOfTag > -1) { listOfTags.splice(indexOfTag, 1) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index 6d4d7406..ac0986e1 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -104,8 +104,8 @@ function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) { const fileType = file['type'] copyAttachment(filePath, storageKey, noteKey).then((fileName) => { - let showPreview = fileType.startsWith('image') - let imageMd = generateAttachmentMarkdown(originalFileName, path.join(STORAGE_FOLDER_PLACEHOLDER, noteKey, fileName), showPreview) + const showPreview = fileType.startsWith('image') + const imageMd = generateAttachmentMarkdown(originalFileName, path.join(STORAGE_FOLDER_PLACEHOLDER, noteKey, fileName), showPreview) codeEditor.insertAttachmentMd(imageMd) }) } @@ -139,7 +139,7 @@ function handlePastImageEvent (codeEditor, storageKey, noteKey, dataTransferItem const destinationDir = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey) createAttachmentDestinationFolder(targetStorage.path, noteKey) - let imageName = `${uniqueSlug()}.png` + const imageName = `${uniqueSlug()}.png` const imagePath = path.join(destinationDir, imageName) reader.onloadend = function () { @@ -147,7 +147,7 @@ function handlePastImageEvent (codeEditor, storageKey, noteKey, dataTransferItem base64data += base64data.replace('+', ' ') const binaryData = new Buffer(base64data, 'base64').toString('binary') fs.writeFile(imagePath, binaryData, 'binary') - let imageMd = generateAttachmentMarkdown(imageName, imagePath, true) + const imageMd = generateAttachmentMarkdown(imageName, imagePath, true) codeEditor.insertAttachmentMd(imageMd) } reader.readAsDataURL(blob) diff --git a/browser/main/lib/dataApi/fetchSnippet.js b/browser/main/lib/dataApi/fetchSnippet.js index 8d5a6efe..456a5090 100644 --- a/browser/main/lib/dataApi/fetchSnippet.js +++ b/browser/main/lib/dataApi/fetchSnippet.js @@ -1,5 +1,4 @@ import fs from 'fs' -import crypto from 'crypto' import consts from 'browser/lib/consts' function fetchSnippet (id, snippetFile) { diff --git a/browser/main/modals/PreferencesModal/SnippetEditor.js b/browser/main/modals/PreferencesModal/SnippetEditor.js index 250b0e78..010dcac8 100644 --- a/browser/main/modals/PreferencesModal/SnippetEditor.js +++ b/browser/main/modals/PreferencesModal/SnippetEditor.js @@ -1,8 +1,6 @@ import CodeMirror from 'codemirror' import React from 'react' import _ from 'lodash' -import fs from 'fs' -import consts from 'browser/lib/consts' import dataApi from 'browser/main/lib/dataApi' const defaultEditorFontFamily = ['Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'monospace'] @@ -71,10 +69,7 @@ export default class SnippetEditor extends React.Component { return (
) } diff --git a/browser/main/modals/PreferencesModal/SnippetList.js b/browser/main/modals/PreferencesModal/SnippetList.js new file mode 100644 index 00000000..3cf28cf6 --- /dev/null +++ b/browser/main/modals/PreferencesModal/SnippetList.js @@ -0,0 +1,87 @@ +import React from 'react' +import styles from './SnippetTab.styl' +import CSSModules from 'browser/lib/CSSModules' +import dataApi from 'browser/main/lib/dataApi' +import i18n from 'browser/lib/i18n' +import eventEmitter from 'browser/main/lib/eventEmitter' +const { remote } = require('electron') +const { Menu, MenuItem } = remote + +class SnippetList extends React.Component { + constructor (props) { + super(props) + this.state = { + snippets: [] + } + } + + componentDidMount () { + this.reloadSnippetList() + eventEmitter.on('snippetList:reload', this.reloadSnippetList.bind(this)) + } + + reloadSnippetList () { + dataApi.fetchSnippet().then(snippets => this.setState({snippets})) + } + + handleSnippetContextMenu (snippet) { + const menu = new Menu() + menu.append(new MenuItem({ + label: i18n.__('Delete snippet'), + click: () => { + this.deleteSnippet(snippet) + } + })) + menu.popup() + } + + deleteSnippet (snippet) { + dataApi.deleteSnippet(snippet).then(() => { + this.reloadSnippetList() + this.props.onSnippetDeleted(snippet) + }).catch(err => { throw err }) + } + + handleSnippetClick (snippet) { + this.props.onSnippetClick(snippet) + } + + createSnippet () { + dataApi.createSnippet().then(() => { + this.reloadSnippetList() + // scroll to end of list when added new snippet + const snippetList = document.getElementById('snippets') + snippetList.scrollTop = snippetList.scrollHeight + }).catch(err => { throw err }) + } + + render () { + const { snippets } = this.state + return ( +